##// END OF EJS Templates
Run js highlight on the new posts only, not on all page each time. Add...
Run js highlight on the new posts only, not on all page each time. Add highlight to the reflink popups

File last commit:

r690:a8dffe47 1.8-dev
r709:e6788412 default
Show More
all_threads.py
134 lines | 3.7 KiB | text/x-python | PythonLexer
neko259
Rewriting views to class-based
r542 import string
from django.db import transaction
from django.shortcuts import render, redirect
from boards import utils
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
Rewriting views to class-based
r542 from boards.forms import ThreadForm, PlainErrorList
from boards.models import Post, Thread, Ban, Tag
from boards.views.banned import BannedView
from boards.views.base import BaseBoardView, PARAMETER_FORM
from boards.views.posting_mixin import PostMixin
import neboard
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
Added hidden tags functionality
r635 user = None
neko259
Moved login view to a separate class. Refactored thread and all threads views
r544 def get(self, request, page=DEFAULT_PAGE, form=None):
neko259
Rewriting views to class-based
r542 context = self.get_context_data(request=request)
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 self.user = utils.get_user(request)
neko259
Added hidden tags functionality
r635
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
Updated paginator for long page lists. Removed old get_threads method in the post manager
r596 paginator = get_paginator(self.get_threads(),
neboard.settings.THREADS_PER_PAGE)
paginator.current_page = int(page)
neko259
Rewriting views to class-based
r542
threads = paginator.page(page).object_list
context[PARAMETER_THREADS] = threads
context[PARAMETER_FORM] = form
self._get_page_context(paginator, context, page)
return render(request, TEMPLATE, context)
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
@staticmethod
def _get_page_context(paginator, context, page):
"""
Get pagination context variables
"""
context[PARAMETER_PAGINATOR] = paginator
context[PARAMETER_CURRENT_PAGE] = paginator.page(int(page))
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:
tag_name = string.lower(tag_name.strip())
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
Refactoring in all threads view
r634 def create_thread(self, request, form, 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
title = data['title']
text = data['text']
text = self._remove_invalid_links(text)
if 'image' in data.keys():
image = data['image']
else:
image = None
tag_strings = data['tags']
neko259
Refactoring in all threads view
r634 tags = self.parse_tags_string(tag_strings)
neko259
Rewriting views to class-based
r542
post = Post.objects.create_post(title=title, text=text, ip=ip,
image=image, tags=tags,
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 user=utils.get_user(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
Removed archive as a separate entity. Archived threads are saved in the same...
r652 return Thread.objects.all().order_by('-bump_time')\
.exclude(tags__in=self.user.hidden_tags.all())