##// END OF EJS Templates
Post message by ctrl-enter on the text field
Post message by ctrl-enter on the text field

File last commit:

r977:6b112efe default
r1005:1df42bd8 default
Show More
all_threads.py
145 lines | 4.2 KiB | text/x-python | PythonLexer
neko259
Load image from URL (BB-56)
r954 from django.core.files import File
from django.core.files.temp import NamedTemporaryFile
neko259
Throw error 404 when trying to open invalid page in threads list
r977 from django.core.paginator import EmptyPage
neko259
Rewriting views to class-based
r542 from django.db import transaction
neko259
Throw error 404 when trying to open invalid page in threads list
r977 from django.http import Http404
neko259
Rewriting views to class-based
r542 from django.shortcuts import render, redirect
neko259
Load image from URL (BB-56)
r954 import requests
neko259
Rewriting views to class-based
r542
neko259
Moved imageboard settings to the boards settings module. Added setting to disable archive
r716 from boards import utils, settings
neko259
Updated paginator for long page lists. Removed old get_threads method in the post manager
r596 from boards.abstracts.paginator import get_paginator
neko259
Divided settings manager into base settings manager class and session-based settings manager. This allowes to add other backends to the settings manager
r730 from boards.abstracts.settingsmanager import get_settings_manager
neko259
Rewriting views to class-based
r542 from boards.forms import ThreadForm, PlainErrorList
neko259
Load image from URL (BB-56)
r954 from boards.models import Post, Thread, Ban, Tag, PostImage
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
Views refactoring
r900
neko259
Code cleanup part 2
r722 FORM_TAGS = 'tags'
FORM_TEXT = 'text'
FORM_TITLE = 'title'
FORM_IMAGE = 'image'
neko259
Refactoring in all threads view
r634 TAG_DELIMITER = ' '
neko259
Rewriting views to class-based
r542 PARAMETER_CURRENT_PAGE = 'current_page'
PARAMETER_PAGINATOR = 'paginator'
PARAMETER_THREADS = 'threads'
TEMPLATE = 'boards/posting_general.html'
DEFAULT_PAGE = 1
class AllThreadsView(PostMixin, BaseBoardView):
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 def __init__(self):
self.settings_manager = None
super(AllThreadsView, self).__init__()
neko259
Added hidden tags functionality
r635
neko259
Load image from URL (BB-56)
r954 def get(self, request, page=DEFAULT_PAGE, form: ThreadForm=None):
neko259
Fixed tag threads view
r919 params = self.get_context_data(request=request)
neko259
Rewriting views to class-based
r542
neko259
Moved login view to a separate class. Refactored thread and all threads views
r544 if not form:
form = ThreadForm(error_class=PlainErrorList)
neko259
Rewriting views to class-based
r542
neko259
Divided settings manager into base settings manager class and session-based settings manager. This allowes to add other backends to the settings manager
r730 self.settings_manager = get_settings_manager(request)
neko259
Updated paginator for long page lists. Removed old get_threads method in the post manager
r596 paginator = get_paginator(self.get_threads(),
neko259
Moved imageboard settings to the boards settings module. Added setting to disable archive
r716 settings.THREADS_PER_PAGE)
neko259
Updated paginator for long page lists. Removed old get_threads method in the post manager
r596 paginator.current_page = int(page)
neko259
Rewriting views to class-based
r542
neko259
Throw error 404 when trying to open invalid page in threads list
r977 try:
threads = paginator.page(page).object_list
except EmptyPage:
raise Http404()
neko259
Rewriting views to class-based
r542
neko259
Fixed calls to render shortcut to use dict instead of context instance
r918 params[PARAMETER_THREADS] = threads
params[CONTEXT_FORM] = form
neko259
Rewriting views to class-based
r542
neko259
Fixed calls to render shortcut to use dict instead of context instance
r918 self._get_page_context(paginator, params, page)
neko259
Rewriting views to class-based
r542
neko259
Fixed calls to render shortcut to use dict instead of context instance
r918 return render(request, TEMPLATE, params)
neko259
Rewriting views to class-based
r542
def post(self, request, page=DEFAULT_PAGE):
form = ThreadForm(request.POST, request.FILES,
error_class=PlainErrorList)
form.session = request.session
if form.is_valid():
neko259
Refactoring in all threads view
r634 return self.create_thread(request, form)
neko259
Rewriting views to class-based
r542 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, page, form)
neko259
Rewriting views to class-based
r542
neko259
Fixed calls to render shortcut to use dict instead of context instance
r918 def _get_page_context(self, paginator, params, page):
neko259
Rewriting views to class-based
r542 """
Get pagination context variables
"""
neko259
Fixed calls to render shortcut to use dict instead of context instance
r918 params[PARAMETER_PAGINATOR] = paginator
params[PARAMETER_CURRENT_PAGE] = paginator.page(int(page))
neko259
Rewriting views to class-based
r542
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 @staticmethod
def parse_tags_string(tag_strings):
neko259
Refactoring in all threads view
r634 """
Parses tag list string and returns tag object list.
"""
tags = []
if tag_strings:
tag_strings = tag_strings.split(TAG_DELIMITER)
for tag_name in tag_strings:
neko259
Fixed tag problems with python3 (related to the 'map' function that was...
r766 tag_name = tag_name.strip().lower()
neko259
Refactoring in all threads view
r634 if len(tag_name) > 0:
tag, created = Tag.objects.get_or_create(name=tag_name)
tags.append(tag)
return tags
neko259
Rewriting views to class-based
r542 @transaction.atomic
neko259
Load image from URL (BB-56)
r954 def create_thread(self, request, form: ThreadForm, html_response=True):
neko259
Rewriting views to class-based
r542 """
neko259
Refactoring in all threads view
r634 Creates a new thread with an opening post.
neko259
Rewriting views to class-based
r542 """
ip = utils.get_client_ip(request)
is_banned = Ban.objects.filter(ip=ip).exists()
if is_banned:
if html_response:
return redirect(BannedView().as_view())
else:
return
data = form.cleaned_data
neko259
Code cleanup part 2
r722 title = data[FORM_TITLE]
text = data[FORM_TEXT]
neko259
Load image from URL (BB-56)
r954 image = form.get_image()
neko259
Rewriting views to class-based
r542
text = self._remove_invalid_links(text)
neko259
Code cleanup part 2
r722 tag_strings = data[FORM_TAGS]
neko259
Rewriting views to class-based
r542
neko259
Refactoring in all threads view
r634 tags = self.parse_tags_string(tag_strings)
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,
ip=ip, tags=tags)
neko259
Views refactoring
r900
# This is required to update the threads to which posts we have replied
# when creating this one
neko259
Added centrifuge (websocket) support for thread autoupdate. Only websocket version is supported for now
r853 post.send_to_websocket(request)
neko259
Rewriting views to class-based
r542
if html_response:
neko259
Refactoring in all threads view
r634 return redirect(post.get_url())
neko259
Rewriting views to class-based
r542
def get_threads(self):
neko259
Refactoring in all threads view
r634 """
Gets list of threads that will be shown on a page.
"""
neko259
Added line break height to SW theme. Don't get all threads when getting thread list for a page
r942 return Thread.objects.order_by('-bump_time')\
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 .exclude(tags__in=self.settings_manager.get_hidden_tags())