##// END OF EJS Templates
Merged with default branch
Merged with default branch

File last commit:

r918:06775760 default
r933:ce97c754 merge decentral
Show More
thread.py
142 lines | 4.8 KiB | text/x-python | PythonLexer
neko259
Rewriting views to class-based
r542 from django.core.urlresolvers import reverse
from django.db import transaction
from django.http import Http404
from django.shortcuts import get_object_or_404, render, redirect
neko259
Added post bumplimit size to the end of form template. Some code cleanup
r633 from django.views.generic.edit import FormMixin
neko259
Implemented search over posts. Moved get_user and get_theme to utils module. Use context processors instead of creating context in the base view. Removed unused imports in some modules
r690
neko259
Moved imageboard settings to the boards settings module. Added setting to disable archive
r716 from boards import utils, settings
neko259
Rewriting views to class-based
r542 from boards.forms import PostForm, PlainErrorList
neko259
Implemented search over posts. Moved get_user and get_theme to utils module. Use context processors instead of creating context in the base view. Removed unused imports in some modules
r690 from boards.models import Post, Ban
neko259
Rewriting views to class-based
r542 from boards.views.banned import BannedView
neko259
Code cleanup part 2
r722 from boards.views.base import BaseBoardView, CONTEXT_FORM
neko259
Rewriting views to class-based
r542 from boards.views.posting_mixin import PostMixin
neko259
Added centrifuge (websocket) support for thread autoupdate. Only websocket version is supported for now
r853 import neboard
neko259
Rewriting views to class-based
r542
neko259
Code cleanup part 2
r722 TEMPLATE_GALLERY = 'boards/thread_gallery.html'
TEMPLATE_NORMAL = 'boards/thread.html'
CONTEXT_POSTS = 'posts'
CONTEXT_OP = 'opening_post'
CONTEXT_BUMPLIMIT_PRG = 'bumplimit_progress'
CONTEXT_POSTS_LEFT = 'posts_left'
CONTEXT_LASTUPDATE = "last_update"
CONTEXT_MAX_REPLIES = 'max_replies'
CONTEXT_THREAD = 'thread'
CONTEXT_BUMPABLE = 'bumpable'
neko259
Added centrifuge (websocket) support for thread autoupdate. Only websocket version is supported for now
r853 CONTEXT_WS_TOKEN = 'ws_token'
CONTEXT_WS_PROJECT = 'ws_project'
CONTEXT_WS_HOST = 'ws_host'
CONTEXT_WS_PORT = 'ws_port'
neko259
Code cleanup part 2
r722
FORM_TITLE = 'title'
FORM_TEXT = 'text'
FORM_IMAGE = 'image'
neko259
Implemented search over posts. Moved get_user and get_theme to utils module. Use context processors instead of creating context in the base view. Removed unused imports in some modules
r690
neko259
Rewriting views to class-based
r542 MODE_GALLERY = 'gallery'
MODE_NORMAL = 'normal'
neko259
Added post bumplimit size to the end of form template. Some code cleanup
r633
class ThreadView(BaseBoardView, PostMixin, FormMixin):
neko259
Rewriting views to class-based
r542
neko259
Moved login view to a separate class. Refactored thread and all threads views
r544 def get(self, request, post_id, mode=MODE_NORMAL, form=None):
neko259
Added django management command to clean old users. Cleaned up failing tests. Fixed error when trying to get a non-existent post
r689 try:
opening_post = Post.objects.filter(id=post_id).only('thread_new')[0]
except IndexError:
raise Http404
neko259
Rewriting views to class-based
r542
# If this is not OP, don't show it as it is
neko259
Slight optimizations to thread opening
r659 if not opening_post or not opening_post.is_opening():
neko259
Rewriting views to class-based
r542 raise Http404
neko259
Moved login view to a separate class. Refactored thread and all threads views
r544 if not form:
form = PostForm(error_class=PlainErrorList)
neko259
Rewriting views to class-based
r542
neko259
Made getting post thread more generic and scalable
r617 thread_to_show = opening_post.get_thread()
neko259
Rewriting views to class-based
r542
neko259
Fixed calls to render shortcut to use dict instead of context instance
r918 params = dict()
neko259
Rewriting views to class-based
r542
neko259
Fixed calls to render shortcut to use dict instead of context instance
r918 params[CONTEXT_FORM] = form
params[CONTEXT_LASTUPDATE] = str(utils.datetime_to_epoch(
neko259
Added centrifuge (websocket) support for thread autoupdate. Only websocket version is supported for now
r853 thread_to_show.last_edit_time))
neko259
Fixed calls to render shortcut to use dict instead of context instance
r918 params[CONTEXT_THREAD] = thread_to_show
params[CONTEXT_MAX_REPLIES] = settings.MAX_POSTS_PER_THREAD
neko259
Rewriting views to class-based
r542
neko259
Added centrifuge (websocket) support for thread autoupdate. Only websocket version is supported for now
r853 if settings.WEBSOCKETS_ENABLED:
neko259
Fixed calls to render shortcut to use dict instead of context instance
r918 params[CONTEXT_WS_TOKEN] = utils.get_websocket_token(
timestamp=params[CONTEXT_LASTUPDATE])
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
neko259
Added centrifuge (websocket) support for thread autoupdate. Only websocket version is supported for now
r853
neko259
Added a todo in the thread view
r859 # TODO Move this to subclasses: NormalThreadView, GalleryThreadView etc
neko259
Rewriting views to class-based
r542 if MODE_NORMAL == mode:
neko259
Code cleanup part 2
r722 bumpable = thread_to_show.can_bump()
neko259
Fixed calls to render shortcut to use dict instead of context instance
r918 params[CONTEXT_BUMPABLE] = bumpable
neko259
Code cleanup part 2
r722 if bumpable:
left_posts = settings.MAX_POSTS_PER_THREAD \
- thread_to_show.get_reply_count()
neko259
Fixed calls to render shortcut to use dict instead of context instance
r918 params[CONTEXT_POSTS_LEFT] = left_posts
params[CONTEXT_BUMPLIMIT_PRG] = str(
neko259
Code cleanup part 2
r722 float(left_posts) / settings.MAX_POSTS_PER_THREAD * 100)
neko259
Rewriting views to class-based
r542
neko259
Fixed calls to render shortcut to use dict instead of context instance
r918 params[CONTEXT_OP] = opening_post
neko259
Rewriting views to class-based
r542
neko259
Code cleanup part 2
r722 document = TEMPLATE_NORMAL
neko259
Rewriting views to class-based
r542 elif MODE_GALLERY == mode:
neko259
Fixed calls to render shortcut to use dict instead of context instance
r918 params[CONTEXT_POSTS] = thread_to_show.get_replies_with_images(
neko259
Moved post image to a separate model. Each post (as of model) can contain multiple images now. The image shown to the user is got with get_first_image method
r693 view_fields_only=True)
neko259
Rewriting views to class-based
r542
neko259
Code cleanup part 2
r722 document = TEMPLATE_GALLERY
neko259
Rewriting views to class-based
r542 else:
raise Http404
neko259
Fixed calls to render shortcut to use dict instead of context instance
r918 return render(request, document, params)
neko259
Rewriting views to class-based
r542
def post(self, request, post_id, mode=MODE_NORMAL):
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
neko259
Made getting post thread more generic and scalable
r617 if not opening_post.get_thread().archived:
neko259
Rewriting views to class-based
r542 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)
neko259
Moved login view to a separate class. Refactored thread and all threads views
r544 return self.get(request, post_id, mode, form)
neko259
Rewriting views to class-based
r542
def new_post(self, request, form, opening_post=None, html_response=True):
"""Add a new post (in thread or as a reply)."""
ip = utils.get_client_ip(request)
data = form.cleaned_data
neko259
Code cleanup part 2
r722 title = data[FORM_TITLE]
text = data[FORM_TEXT]
neko259
Fixed sending posts to websockets. Cleaned up new post view code
r916 image = data.get(FORM_IMAGE)
neko259
Rewriting views to class-based
r542
text = self._remove_invalid_links(text)
neko259
Made getting post thread more generic and scalable
r617 post_thread = opening_post.get_thread()
neko259
Rewriting views to class-based
r542
neko259
Removed user and settings mode. Added settings manager to manage settings and keep them in the session (or any other backend like cookie in the future
r728 post = Post.objects.create_post(title=title, text=text, image=image,
neko259
Fixed sending posts to websockets. Cleaned up new post view code
r916 thread=post_thread, ip=ip)
neko259
Small fixes to the websocket notifications. Make post creation atomic, not the entire view
r915 post.send_to_websocket(request)
neko259
Rewriting views to class-based
r542
thread_to_show = (opening_post.id if opening_post else post.id)
if html_response:
if opening_post:
neko259
Code cleanup part 2
r722 return redirect(
reverse('thread', kwargs={'post_id': thread_to_show})
+ '#' + str(post.id))
neko259
Make status an error if the user is banned in api_add_post
r638 else:
neko259
Tweaked API logging
r640 return post