##// END OF EJS Templates
Tripcode should be delimited by 2 hashes
Tripcode should be delimited by 2 hashes

File last commit:

r1919:df3ebb11 default
r1923:916b2d74 default
Show More
thread.py
165 lines | 5.4 KiB | text/x-python | PythonLexer
neko259
Added ability to hide a post
r1366 from django.contrib.auth.decorators import permission_required
neko259
Added missing import to the last commit
r1014 from django.core.exceptions import ObjectDoesNotExist
neko259
New RSS url model with proper links (no page attribute)
r1399 from django.core.urlresolvers import reverse
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
neko259
Use CSRF protection
r1422 from django.template.context_processors import csrf
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_protect
neko259
Split thread view into separate views for each mode
r951 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
neko259
Favorite threads with new posts counter
r1323 from boards.abstracts.settingsmanager import get_settings_manager
neko259
Split thread view into separate views for each mode
r951 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
neko259
Added ability to hide a post
r1366 from boards.views.mixins import DispatcherMixin, PARAMETER_METHOD
neko259
Split thread view into separate views for each mode
r951 from boards.views.posting_mixin import PostMixin
import neboard
neko259
Added ability to hide a post
r1366 REQ_POST_ID = 'post_id'
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'
neko259
Added tree mode for the thread
r1180 CONTEXT_MODE = 'mode'
neko259
Refactored thread views
r1185 CONTEXT_OP = 'opening_post'
neko259
Favorite threads with new posts counter
r1323 CONTEXT_FAVORITE = 'is_favorite'
neko259
New RSS url model with proper links (no page attribute)
r1399 CONTEXT_RSS_URL = 'rss_url'
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
neko259
Favorite threads with new posts counter
r1323 class ThreadView(BaseBoardView, PostMixin, FormMixin, DispatcherMixin):
neko259
Split thread view into separate views for each mode
r951
neko259
Use CSRF protection
r1422 @method_decorator(csrf_protect)
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
neko259
Favorite threads with new posts counter
r1323 # If the tag is favorite, update the counter
settings_manager = get_settings_manager(request)
favorite = settings_manager.thread_is_fav(opening_post)
if favorite:
settings_manager.add_or_read_fav_thread(opening_post)
neko259
Split thread view into separate views for each mode
r951 # 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
Redirect to post inside thread, if the post was opened as a thread
r1803 return redirect('{}#{}'.format(opening_post.get_thread().get_opening_post()
.get_absolute_url(), opening_post.id))
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
Favorite threads with new posts counter
r1323 params[CONTEXT_FAVORITE] = favorite
neko259
New RSS url model with proper links (no page attribute)
r1399 params[CONTEXT_RSS_URL] = self.get_rss_url(post_id)
neko259
Split thread view into separate views for each mode
r951
params.update(self.get_data(thread_to_show))
return render(request, self.get_template(), params)
neko259
Use CSRF protection
r1422 @method_decorator(csrf_protect)
neko259
Split thread view into separate views for each mode
r951 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
neko259
Added ability to hide a post
r1366 if PARAMETER_METHOD in request.POST:
neko259
Dispatch thread method on post, not get
r1324 self.dispatch_method(request, opening_post)
return redirect('thread', post_id) # FIXME Different for different modes
neko259
Thread status field instead of bumpable and archived fields (per BB-73)
r1414 if not opening_post.get_thread().is_archived():
neko259
Split thread view into separate views for each mode
r951 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
neko259
Use password-hash tripcodes
r1299 title = form.get_title()
neko259
Split thread view into separate views for each mode
r951 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
Split thread view into separate views for each mode
r951
text = self._remove_invalid_links(text)
post_thread = opening_post.get_thread()
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
Refactored post and thread models
r1091 thread=post_thread, ip=ip,
neko259
Added image aliases to upload the same images (like "fake" or "gtfo")
r1500 tripcode=form.get_tripcode(),
neko259
Fixed the fix for image download
r1919 images=images, file_urls=file_urls)
neko259
Split thread view into separate views for each mode
r951
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_thread.get_opening_post())
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
neko259
Favorite threads with new posts counter
r1323
def subscribe(self, request, opening_post):
settings_manager = get_settings_manager(request)
settings_manager.add_or_read_fav_thread(opening_post)
def unsubscribe(self, request, opening_post):
settings_manager = get_settings_manager(request)
settings_manager.del_fav_thread(opening_post)
neko259
Added ability to hide a post
r1366
neko259
New RSS url model with proper links (no page attribute)
r1399 def get_rss_url(self, opening_id):
neko259
Fixed thread RSS. Limit items count in RSS
r1400 return reverse('thread', kwargs={'post_id': opening_id}) + 'rss/'