##// END OF EJS Templates
Added sticker pack functionality
Added sticker pack functionality

File last commit:

r1951:1024ce38 default
r1951:1024ce38 default
Show More
all_threads.py
180 lines | 5.9 KiB | text/x-python | PythonLexer
neko259
Set previous and next page links in the thread list view instead of template
r1129 from django.core.urlresolvers import reverse
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
Use CSRF protection
r1422 from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_protect
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
Switch to show only favorite tags (BB-94)
r1691 from boards.abstracts.settingsmanager import get_settings_manager,\
SETTING_ONLY_FAVORITES
neko259
Rewriting views to class-based
r542 from boards.forms import ThreadForm, PlainErrorList
neko259
Load banners in all pages
r1646 from boards.models import Post, Thread, 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
Switch to show only favorite tags (BB-94)
r1691 from boards.views.mixins import FileUploadMixin, PaginatedMixin,\
DispatcherMixin, PARAMETER_METHOD
neko259
Views refactoring
r900
neko259
Code cleanup part 2
r722 FORM_TAGS = 'tags'
FORM_TEXT = 'text'
FORM_TITLE = 'title'
FORM_IMAGE = 'image'
neko259
Added a form field for additional threads list in multi-thread posts
r1077 FORM_THREADS = 'threads'
neko259
Code cleanup part 2
r722
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'
neko259
Added ability to get page urls of paginators
r1377 PARAMETER_ADDITIONAL = 'additional_params'
neko259
Show max file size in the posting templates
r1396 PARAMETER_MAX_FILE_SIZE = 'max_file_size'
neko259
New RSS url model with proper links (no page attribute)
r1399 PARAMETER_RSS_URL = 'rss_url'
neko259
Show max file number in the forms
r1771 PARAMETER_MAX_FILES = 'max_files'
neko259
Rewriting views to class-based
r542
neko259
Renamed posting_general.html to all_threads.html to clarify its purpose
r1164 TEMPLATE = 'boards/all_threads.html'
neko259
Rewriting views to class-based
r542 DEFAULT_PAGE = 1
neko259
Re-added the functionality of 'add the tag we are standing on to the form'
r1738 FORM_TAGS = 'tags'
neko259
Rewriting views to class-based
r542
neko259
Switch to show only favorite tags (BB-94)
r1691 class AllThreadsView(PostMixin, FileUploadMixin, BaseBoardView, PaginatedMixin, DispatcherMixin):
neko259
Rewriting views to class-based
r542
neko259
Re-added the functionality of 'add the tag we are standing on to the form'
r1738 tag_name = ''
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
Use CSRF protection
r1422 @method_decorator(csrf_protect)
neko259
Use GET parameter to specify a page instead of different url reversers
r1204 def get(self, request, form: ThreadForm=None):
page = request.GET.get('page', DEFAULT_PAGE)
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:
neko259
Re-added the functionality of 'add the tag we are standing on to the form'
r1738 form = ThreadForm(error_class=PlainErrorList,
initial={FORM_TAGS: self.tag_name})
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
Added link to the pub-time sorted thread list
r1376
threads = self.get_threads()
order = request.GET.get('order', 'bump')
if order == 'bump':
threads = threads.order_by('-bump_time')
else:
neko259
Removed multitread posts 'feature'
r1704 threads = threads.filter(replies__opening=True)\
.order_by('-replies__pub_time')
neko259
Added 'interesting' url for viewing threads from favorite tags only
r1472 filter = request.GET.get('filter')
threads = threads.distinct()
neko259
Added link to the pub-time sorted thread list
r1376
paginator = get_paginator(threads,
neko259
Implemented ini settings parser
r1153 settings.get_int('View', 'ThreadsPerPage'))
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
Show max file size in the posting templates
r1396 params[PARAMETER_MAX_FILE_SIZE] = self.get_max_upload_size()
neko259
New RSS url model with proper links (no page attribute)
r1399 params[PARAMETER_RSS_URL] = self.get_rss_url()
neko259
Show max file number in the forms
r1771 params[PARAMETER_MAX_FILES] = settings.get_int('Forms', 'MaxFileCount')
neko259
Rewriting views to class-based
r542
neko259
Added ability to get page urls of paginators
r1377 paginator.set_url(self.get_reverse_url(), request.GET.dict())
neko259
Moved pagination related stuff to the mixin
r1854 params.update(self.get_page_context(paginator, 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
neko259
Use CSRF protection
r1422 @method_decorator(csrf_protect)
neko259
Use GET parameter to specify a page instead of different url reversers
r1204 def post(self, request):
neko259
Switch to show only favorite tags (BB-94)
r1691 if PARAMETER_METHOD in request.POST:
self.dispatch_method(request)
return redirect('index') # FIXME Different for different modes
neko259
Rewriting views to class-based
r542 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
Use GET parameter to specify a page instead of different url reversers
r1204 return self.get(request, form)
neko259
Rewriting views to class-based
r542
neko259
Added ability to get page urls of paginators
r1377 def get_reverse_url(self):
return reverse('index')
neko259
Small refactoring of threads view
r1374
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
Use password-hash tripcodes
r1299 title = form.get_title()
neko259
Code cleanup part 2
r722 text = data[FORM_TEXT]
neko259
Add any number of files and URLs to post, not just one
r1753 files = form.get_files()
file_urls = form.get_file_urls()
neko259
Added image aliases to upload the same images (like "fake" or "gtfo")
r1500 images = form.get_images()
neko259
Rewriting views to class-based
r542
text = self._remove_invalid_links(text)
neko259
Added categories -- a redesign of old-style linked tags, a tree-based...
r1348 tags = data[FORM_TAGS]
neko259
Added ability to create monochrome threads
r1434 monochrome = form.is_monochrome()
neko259
Added sticker pack functionality
r1951 stickerpack = form.is_stickerpack()
neko259
Rewriting views to class-based
r542
neko259
Add any number of files and URLs to post, not just one
r1753 post = Post.objects.create_post(title=title, text=text, files=files,
neko259
Removed multitread posts 'feature'
r1704 ip=ip, tags=tags,
neko259
Added ability to create monochrome threads
r1434 tripcode=form.get_tripcode(),
neko259
Load URL if the file could not be loaded
r1660 monochrome=monochrome, images=images,
neko259
Added sticker pack functionality
r1951 file_urls=file_urls, stickerpack=stickerpack)
neko259
Rewriting views to class-based
r542
neko259
Checkbox to subscribe replied or created thread
r1625 if form.is_subscribe():
settings_manager = get_settings_manager(request)
settings_manager.add_or_read_fav_thread(post)
neko259
Rewriting views to class-based
r542 if html_response:
neko259
Use get_absolute_url instead of get_url for post, tag and thread
r1160 return redirect(post.get_absolute_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
Show only favorite tags' threads in index view, not tag view
r1692 threads = Thread.objects\
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())
neko259
Show only favorite tags' threads in index view, not tag view
r1692 if self.settings_manager.get_setting(SETTING_ONLY_FAVORITES):
fav_tags = self.settings_manager.get_fav_tags()
if len(fav_tags) > 0:
threads = threads.filter(tags__in=fav_tags)
return threads
neko259
New RSS url model with proper links (no page attribute)
r1399
def get_rss_url(self):
return self.get_reverse_url() + 'rss/'
neko259
Switch to show only favorite tags (BB-94)
r1691
def toggle_fav(self, request):
settings_manager = get_settings_manager(request)
settings_manager.set_setting(SETTING_ONLY_FAVORITES,
not settings_manager.get_setting(SETTING_ONLY_FAVORITES, False))