##// END OF EJS Templates
Updated file image
Updated file image

File last commit:

r1273:2c3f55c9 default
r1290:8be27cbf default
Show More
thread.py
138 lines | 4.1 KiB | text/x-python | PythonLexer
neko259
Added missing import to the last commit
r1014 from django.core.exceptions import ObjectDoesNotExist
neko259
Split thread view into separate views for each mode
r951 from django.http import Http404
from django.shortcuts import get_object_or_404, render, redirect
from django.views.generic.edit import FormMixin
neko259
Updated API to use a new timestamp format for getting updated posts and get...
r1086 from django.utils import timezone
from django.utils.dateformat import format
neko259
Split thread view into separate views for each mode
r951
from boards import utils, settings
from boards.forms import PostForm, PlainErrorList
neko259
Added noindex to the pages without unique content or user-specific ones
r1040 from boards.models import Post
neko259
Split thread view into separate views for each mode
r951 from boards.views.base import BaseBoardView, CONTEXT_FORM
from boards.views.posting_mixin import PostMixin
neko259
Updated API to use a new timestamp format for getting updated posts and get...
r1086
neko259
Split thread view into separate views for each mode
r951 import neboard
neko259
Added noindex to the pages without unique content or user-specific ones
r1040
neko259
Split thread view into separate views for each mode
r951 CONTEXT_LASTUPDATE = "last_update"
CONTEXT_THREAD = 'thread'
CONTEXT_WS_TOKEN = 'ws_token'
CONTEXT_WS_PROJECT = 'ws_project'
CONTEXT_WS_HOST = 'ws_host'
CONTEXT_WS_PORT = 'ws_port'
neko259
Updated API to use a new timestamp format for getting updated posts and get...
r1086 CONTEXT_WS_TIME = 'ws_token_time'
neko259
Added tree mode for the thread
r1180 CONTEXT_MODE = 'mode'
neko259
Refactored thread views
r1185 CONTEXT_OP = 'opening_post'
neko259
Split thread view into separate views for each mode
r951
FORM_TITLE = 'title'
FORM_TEXT = 'text'
FORM_IMAGE = 'image'
neko259
Added a form field for additional threads list in multi-thread posts
r1077 FORM_THREADS = 'threads'
neko259
Split thread view into separate views for each mode
r951
class ThreadView(BaseBoardView, PostMixin, FormMixin):
neko259
Load image from URL (BB-56)
r954 def get(self, request, post_id, form: PostForm=None):
neko259
Split thread view into separate views for each mode
r951 try:
neko259
When trying to opening thread by passing non-opening post ID, find its proper...
r1013 opening_post = Post.objects.get(id=post_id)
neko259
Added missing import to the last commit
r1014 except ObjectDoesNotExist:
neko259
Split thread view into separate views for each mode
r951 raise Http404
# If this is not OP, don't show it as it is
neko259
When trying to opening thread by passing non-opening post ID, find its proper...
r1013 if not opening_post.is_opening():
neko259
Use get_absolute_url instead of get_url for post, tag and thread
r1160 return redirect(opening_post.get_thread().get_opening_post()
.get_absolute_url())
neko259
Split thread view into separate views for each mode
r951
if not form:
form = PostForm(error_class=PlainErrorList)
thread_to_show = opening_post.get_thread()
params = dict()
params[CONTEXT_FORM] = form
neko259
Updated API to use a new timestamp format for getting updated posts and get...
r1086 params[CONTEXT_LASTUPDATE] = str(thread_to_show.last_edit_time)
neko259
Split thread view into separate views for each mode
r951 params[CONTEXT_THREAD] = thread_to_show
neko259
Added tree mode for the thread
r1180 params[CONTEXT_MODE] = self.get_mode()
neko259
Refactored thread views
r1185 params[CONTEXT_OP] = opening_post
neko259
Split thread view into separate views for each mode
r951
neko259
Implemented ini settings parser
r1153 if settings.get_bool('External', 'WebsocketsEnabled'):
neko259
Updated API to use a new timestamp format for getting updated posts and get...
r1086 token_time = format(timezone.now(), u'U')
params[CONTEXT_WS_TIME] = token_time
neko259
Split thread view into separate views for each mode
r951 params[CONTEXT_WS_TOKEN] = utils.get_websocket_token(
neko259
Updated API to use a new timestamp format for getting updated posts and get...
r1086 timestamp=token_time)
neko259
Split thread view into separate views for each mode
r951 params[CONTEXT_WS_PROJECT] = neboard.settings.CENTRIFUGE_PROJECT_ID
params[CONTEXT_WS_HOST] = request.get_host().split(':')[0]
params[CONTEXT_WS_PORT] = neboard.settings.CENTRIFUGE_PORT
params.update(self.get_data(thread_to_show))
return render(request, self.get_template(), params)
def post(self, request, post_id):
opening_post = get_object_or_404(Post, id=post_id)
# If this is not OP, don't show it as it is
if not opening_post.is_opening():
raise Http404
if not opening_post.get_thread().archived:
form = PostForm(request.POST, request.FILES,
error_class=PlainErrorList)
form.session = request.session
if form.is_valid():
return self.new_post(request, form, opening_post)
if form.need_to_ban:
# Ban user because he is suspected to be a bot
self._ban_current_user(request)
return self.get(request, post_id, form)
neko259
Load image from URL (BB-56)
r954 def new_post(self, request, form: PostForm, opening_post: Post=None,
html_response=True):
neko259
Split thread view into separate views for each mode
r951 """
Adds a new post (in thread or as a reply).
"""
ip = utils.get_client_ip(request)
data = form.cleaned_data
title = data[FORM_TITLE]
text = data[FORM_TEXT]
neko259
Added support for different attachment types
r1273 file = form.get_file()
neko259
Added a form field for additional threads list in multi-thread posts
r1077 threads = data[FORM_THREADS]
neko259
Split thread view into separate views for each mode
r951
text = self._remove_invalid_links(text)
post_thread = opening_post.get_thread()
neko259
Added support for different attachment types
r1273 post = Post.objects.create_post(title=title, text=text, file=file,
neko259
Refactored post and thread models
r1091 thread=post_thread, ip=ip,
neko259
Fixed thread bumping
r1221 opening_posts=threads)
neko259
Refactored post and thread models
r1091 post.notify_clients()
neko259
Split thread view into separate views for each mode
r951
if html_response:
if opening_post:
neko259
Use get_absolute_url instead of get_url for post, tag and thread
r1160 return redirect(post.get_absolute_url())
neko259
Split thread view into separate views for each mode
r951 else:
return post
neko259
Refactored thread views
r1185 def get_data(self, thread) -> dict:
neko259
Split thread view into separate views for each mode
r951 """
Returns context params for the view.
"""
neko259
Refactored thread views
r1185 return dict()
neko259
Split thread view into separate views for each mode
r951
neko259
Refactored thread views
r1185 def get_template(self) -> str:
neko259
Split thread view into separate views for each mode
r951 """
Gets template to show the thread mode on.
"""
pass
neko259
Added tree mode for the thread
r1180
neko259
Refactored thread views
r1185 def get_mode(self) -> str:
neko259
Added tree mode for the thread
r1180 pass