##// END OF EJS Templates
Removed strange 'exists' method in post manager, fixed tests in which it was...
Removed strange 'exists' method in post manager, fixed tests in which it was used

File last commit:

r393:64170e36 default
r396:0d260248 default
Show More
views.py
561 lines | 15.9 KiB | text/x-python | PythonLexer
neko259
Added users with unique (sort of) IDs. Moved theme setting to user instead of session. This refs #61
r110 import hashlib
neko259
Added thread autoupdate. Currently has some bugs, not ready for merge with the main branch
r361 import json
neko259
Making tags lower case.
r199 import string
neko259
Update thread by time, not post id. This will help with getting updated posts
r363 import time
from datetime import datetime
neko259
Moved models to a separate module folder. Starting to split up models file
r384 import re
neko259
Update thread by time, not post id. This will help with getting updated posts
r363
neko259
Added an API method for retrieving post's JSON.
r221 from django.core import serializers
neko259
Updated the Snow White theme. Scroll to the new post after posting to thread.
r41 from django.core.urlresolvers import reverse
neko259
Added a 'next' attribute to the delete page to return to the current page after deletion.
r155 from django.http import HttpResponseRedirect
neko259
Added an API method for retrieving post's JSON.
r221 from django.http.response import HttpResponse
Ilyas
Added admin loing possibility. Now it is abailable under {BASE_URL}/boards/login...
r9 from django.template import RequestContext
neko259
Added error 404 for opening not existing thread or tag. This fixes #8
r79 from django.shortcuts import render, redirect, get_object_or_404
neko259
Added last access time and registration time for user. This refs #61
r121 from django.utils import timezone
neko259
Use transactions only in views that need them
r335 from django.db import transaction
neko259
Added form validation, added style for the tag panel. This fixes #13
r76
Ilyas
Added creating new thread form...
r14 from boards import forms
neko259
Added a page to view the thread.
r20 import boards
Ilyas
Added django-simple-capthca support...
r78 from boards import utils
from boards.forms import ThreadForm, PostForm, SettingsForm, PlainErrorList, \
neko259
Added ability to disable moderator panel. Refactored forms code. Translating forms.
r205 ThreadCaptchaForm, PostCaptchaForm, LoginForm, ModeratorSettingsForm
neko259
Split up tag module from post module
r385 from boards.models import Post, Tag, Ban, User
neko259
Split up user models
r386 from boards.models.post import SETTING_MODERATE, REGEX_REPLY
from boards.models.user import RANK_USER
neko259
Added authors page. This fixes #22
r103 from boards import authors
neko259
Added ban middleware. Now banned user's won't cause load to the server.
r210 from boards.utils import get_client_ip
neko259
Added themes support. Added 'snow white' theme by Mystra_x64.
r35 import neboard
neko259
Moved models to a separate module folder. Starting to split up models file
r384
neko259
Initial commit. One test doesn't work, missing posting form.
r0
neko259
Added ban reasons. Added write-only bans.
r340 BAN_REASON_SPAM = 'Autoban: spam bot'
neko259
Added images upload. Changed the design a bit. Reformatted some code by PEP 8. Changed the urls: not the main site is located at /, not /boards/.
r22
neko259
Compiling regexes for gets. #17 Added pagination. #28 Visually differing the dead (not bumpable) threads.
r46 def index(request, page=0):
neko259
Refactored views code. This refs #16
r101 context = _init_default_context(request)
Ilyas
Added creating new thread form...
r14
wnc_21
Added captcha support
r95 if utils.need_include_captcha(request):
threadFormClass = ThreadCaptchaForm
kwargs = {'request': request}
else:
threadFormClass = ThreadForm
kwargs = {}
Ilyas
Added django-simple-capthca support...
r78
Ilyas
Added creating new thread form...
r14 if request.method == 'POST':
Ilyas
Added django-simple-capthca support...
r78 form = threadFormClass(request.POST, request.FILES,
wnc_21
Added captcha support
r95 error_class=PlainErrorList, **kwargs)
neko259
Implemented posting delay. User must wait some time before posting (a measure against flood).
r153 form.session = request.session
Ilyas
Added django-simple-capthca support...
r78
neko259
Added form validation, added style for the tag panel. This fixes #13
r76 if form.is_valid():
return _new_post(request, form)
neko259
Added autoban by the hidden field (to ban spammers and prevent them from trying to post anything).
r271 if form.need_to_ban:
# Ban user because he is suspected to be a bot
_ban_current_user(request)
neko259
Added a page to view the thread.
r20 else:
wnc_21
Added captcha support
r95 form = threadFormClass(error_class=PlainErrorList, **kwargs)
neko259
Added form validation, added style for the tag panel. This fixes #13
r76
neko259
Optimized threads list.
r163 threads = []
for thread in Post.objects.get_threads(page=int(page)):
neko259
Use cache for thread list.
r318 threads.append({
'thread': thread,
'bumpable': thread.can_bump(),
'last_replies': thread.get_last_replies(),
})
Ilyas
Added checkinf form fields when creating a new thread.
r18
neko259
Added next and previous page links
r343 # TODO Make this generic for tag and threads list pages
neko259
Added form validation, added style for the tag panel. This fixes #13
r76 context['threads'] = None if len(threads) == 0 else threads
context['form'] = form
neko259
Added next and previous page links
r343
page_count = Post.objects.get_thread_page_count()
context['pages'] = range(page_count)
page = int(page)
if page < page_count - 1:
context['next_page'] = str(page + 1)
if page > 0:
context['prev_page'] = str(page - 1)
Ilyas
Added admin loing possibility. Now it is abailable under {BASE_URL}/boards/login...
r9
Ilyas
Templates moved to fit django documentation structure....
r84 return render(request, 'boards/posting_general.html',
neko259
Added form validation, added style for the tag panel. This fixes #13
r76 context)
Ilyas
Added checkinf form fields when creating a new thread.
r18
Ilyas
Added creating new thread form...
r14
neko259
Removed deprecated transaction annotations and changed them to atomic
r393 @transaction.atomic
neko259
Moved models to a separate module folder. Starting to split up models file
r384 def _new_post(request, form, opening_post=None):
neko259
Removed images directory. Removed old urls. Added a bit code for the views.
r4 """Add a new post (in thread or as a reply)."""
neko259
Added ban middleware. Now banned user's won't cause load to the server.
r210 ip = get_client_ip(request)
is_banned = Ban.objects.filter(ip=ip).exists()
neko259
Added IP ban lists. Added migration for bans. Use generic ip address for posting instead of ipv4 only.
r116
if is_banned:
return redirect(you_are_banned)
neko259
Added form validation, added style for the tag panel. This fixes #13
r76 data = form.cleaned_data
neko259
Added images upload. Changed the design a bit. Reformatted some code by PEP 8. Changed the urls: not the main site is located at /, not /boards/.
r22
neko259
Implemented form validation. When the form fails validation, showing the index page.
r29 title = data['title']
text = data['text']
neko259
Initial commit. One test doesn't work, missing posting form.
r0
neko259
Do not parse links to posts that do not exists in the time of posting.
r312 text = _remove_invalid_links(text)
neko259
Implemented form validation. When the form fails validation, showing the index page.
r29 if 'image' in data.keys():
image = data['image']
neko259
Added images upload. Changed the design a bit. Reformatted some code by PEP 8. Changed the urls: not the main site is located at /, not /boards/.
r22 else:
image = None
neko259
Added localization (not fully working). Added tags posting. Changed the design a bit.
r24 tags = []
neko259
Updated the Snow White theme. Scroll to the new post after posting to thread.
r41
neko259
Moved models to a separate module folder. Starting to split up models file
r384 if not opening_post:
neko259
Implemented form validation. When the form fails validation, showing the index page.
r29 tag_strings = data['tags']
neko259
Initial commit. One test doesn't work, missing posting form.
r0
neko259
Added localization (not fully working). Added tags posting. Changed the design a bit.
r24 if tag_strings:
neko259
Added themes support. Added 'snow white' theme by Mystra_x64.
r35 tag_strings = tag_strings.split(' ')
neko259
Added localization (not fully working). Added tags posting. Changed the design a bit.
r24 for tag_name in tag_strings:
neko259
Making tags lower case.
r199 tag_name = string.lower(tag_name.strip())
neko259
Added localization (not fully working). Added tags posting. Changed the design a bit.
r24 if len(tag_name) > 0:
tag, created = Tag.objects.get_or_create(name=tag_name)
tags.append(tag)
neko259
Changed the url to the post page. Added one more TODO.
r6
neko259
Added images upload. Changed the design a bit. Reformatted some code by PEP 8. Changed the urls: not the main site is located at /, not /boards/.
r22 post = Post.objects.create_post(title=title, text=text, ip=ip,
neko259
Moved models to a separate module folder. Starting to split up models file
r384 thread=opening_post, image=image,
neko259
Added posts count to the profile page.
r185 tags=tags, user=_get_user(request))
neko259
Removed images directory. Removed old urls. Added a bit code for the views.
r4
neko259
Moved models to a separate module folder. Starting to split up models file
r384 thread_to_show = (opening_post.id if opening_post else post.id)
neko259
Added methods for getting opening posts and threads.
r5
neko259
Moved models to a separate module folder. Starting to split up models file
r384 if opening_post:
neko259
Added thread field to the post. 'parent' field is deprecated now.
r174 return redirect(reverse(thread, kwargs={'post_id': thread_to_show}) +
'#' + str(post.id))
neko259
Moved models to a separate module folder. Starting to split up models file
r384 else:
return redirect(thread, post_id=thread_to_show)
neko259
Added images upload. Changed the design a bit. Reformatted some code by PEP 8. Changed the urls: not the main site is located at /, not /boards/.
r22
neko259
Added methods for getting opening posts and threads.
r5
neko259
Compiling regexes for gets. #17 Added pagination. #28 Visually differing the dead (not bumpable) threads.
r46 def tag(request, tag_name, page=0):
neko259
Added autoban by the hidden field (to ban spammers and prevent them from trying to post anything).
r271 """
Get all tag threads. Threads are split in pages, so some page is
requested. Default page is 0.
"""
neko259
Removed images directory. Removed old urls. Added a bit code for the views.
r4
neko259
Added error 404 for opening not existing thread or tag. This fixes #8
r79 tag = get_object_or_404(Tag, name=tag_name)
neko259
Fixed tag view.
r164 threads = []
for thread in Post.objects.get_threads(tag=tag, page=int(page)):
neko259
Use cache for thread list.
r318 threads.append({
'thread': thread,
'bumpable': thread.can_bump(),
'last_replies': thread.get_last_replies(),
})
neko259
Added methods for getting opening posts and threads.
r5
neko259
Added localization (not fully working). Added tags posting. Changed the design a bit.
r24 if request.method == 'POST':
neko259
Added form validation, added style for the tag panel. This fixes #13
r76 form = ThreadForm(request.POST, request.FILES,
error_class=PlainErrorList)
Pavel Ryapolov
Fixed bug with creating thread from tag view
r278 form.session = request.session
neko259
Added form validation, added style for the tag panel. This fixes #13
r76 if form.is_valid():
return _new_post(request, form)
neko259
Added autoban by the hidden field (to ban spammers and prevent them from trying to post anything).
r271 if form.need_to_ban:
# Ban user because he is suspected to be a bot
_ban_current_user(request)
neko259
Added localization (not fully working). Added tags posting. Changed the design a bit.
r24 else:
neko259
Added form validation, added style for the tag panel. This fixes #13
r76 form = forms.ThreadForm(initial={'tags': tag_name},
error_class=PlainErrorList)
neko259
Changed some links to the html pages.
r12
neko259
Refactored views code. This refs #16
r101 context = _init_default_context(request)
neko259
Added form validation, added style for the tag panel. This fixes #13
r76 context['threads'] = None if len(threads) == 0 else threads
neko259
Added star for tag subscribe link. Show the link on the tag view.
r179 context['tag'] = tag
neko259
Added next and previous page links
r343
page_count = Post.objects.get_thread_page_count(tag=tag)
context['pages'] = range(page_count)
page = int(page)
if page < page_count - 1:
context['next_page'] = str(page + 1)
if page > 0:
context['prev_page'] = str(page - 1)
neko259
Removed images directory. Removed old urls. Added a bit code for the views.
r4
neko259
Added form validation, added style for the tag panel. This fixes #13
r76 context['form'] = form
Ilyas
Templates moved to fit django documentation structure....
r84 return render(request, 'boards/posting_general.html',
neko259
Added form validation, added style for the tag panel. This fixes #13
r76 context)
neko259
Added images upload. Changed the design a bit. Reformatted some code by PEP 8. Changed the urls: not the main site is located at /, not /boards/.
r22
neko259
Removed images directory. Removed old urls. Added a bit code for the views.
r4
neko259
Added localization (not fully working). Added tags posting. Changed the design a bit.
r24 def thread(request, post_id):
neko259
Added methods for getting opening posts and threads.
r5 """Get all thread posts"""
wnc_21
Added captcha support
r95 if utils.need_include_captcha(request):
postFormClass = PostCaptchaForm
kwargs = {'request': request}
else:
postFormClass = PostForm
kwargs = {}
Ilyas
Added django-simple-capthca support...
r78
neko259
Added a page to view the thread.
r20 if request.method == 'POST':
Ilyas
Added django-simple-capthca support...
r78 form = postFormClass(request.POST, request.FILES,
wnc_21
Added captcha support
r95 error_class=PlainErrorList, **kwargs)
neko259
Implemented posting delay. User must wait some time before posting (a measure against flood).
r153 form.session = request.session
neko259
Moved models to a separate module folder. Starting to split up models file
r384 opening_post = get_object_or_404(Post, id=post_id)
neko259
Added form validation, added style for the tag panel. This fixes #13
r76 if form.is_valid():
neko259
Moved models to a separate module folder. Starting to split up models file
r384 return _new_post(request, form, opening_post)
neko259
Added autoban by the hidden field (to ban spammers and prevent them from trying to post anything).
r271 if form.need_to_ban:
# Ban user because he is suspected to be a bot
_ban_current_user(request)
neko259
Added a page to view the thread.
r20 else:
wnc_21
Added captcha support
r95 form = postFormClass(error_class=PlainErrorList, **kwargs)
neko259
Changed some links to the html pages.
r12
neko259
Added form validation, added style for the tag panel. This fixes #13
r76 posts = Post.objects.get_thread(post_id)
neko259
Added methods for getting opening posts and threads.
r5
neko259
Refactored views code. This refs #16
r101 context = _init_default_context(request)
neko259
Changed some links to the html pages.
r12
neko259
Added form validation, added style for the tag panel. This fixes #13
r76 context['posts'] = posts
context['form'] = form
neko259
Optimized thread view a lot.
r161 context['bumpable'] = posts[0].can_bump()
neko259
Show bumplimit bar for threads. Added board logo to the authors page.
r281 if context['bumpable']:
context['posts_left'] = neboard.settings.MAX_POSTS_PER_THREAD - len(
posts)
neko259
Fixed some indent issues in Python code
r319 context['bumplimit_progress'] = str(
float(context['posts_left']) /
neboard.settings.MAX_POSTS_PER_THREAD * 100)
neko259
Use proper last update timestamps in thread autoupdate
r370 context["last_update"] = _datetime_to_epoch(posts[0].last_edit_time)
neko259
Added form validation, added style for the tag panel. This fixes #13
r76
Ilyas
Templates moved to fit django documentation structure....
r84 return render(request, 'boards/thread.html', context)
Ilyas
Added admin loing possibility. Now it is abailable under {BASE_URL}/boards/login...
r9
def login(request):
neko259
Added login functionality.
r144 """Log in with user id"""
Ilyas
Added admin loing possibility. Now it is abailable under {BASE_URL}/boards/login...
r9
neko259
Added login functionality.
r144 context = _init_default_context(request)
Ilyas
Completed login and logout functionality and covered by tests.
r13
neko259
Added login functionality.
r144 if request.method == 'POST':
neko259
Refactored code. Added thread title if the opening post has no title.
r147 form = LoginForm(request.POST, request.FILES,
error_class=PlainErrorList)
neko259
Added localizations to forms. Do not allow users without session to post.
r211 form.session = request.session
neko259
Added login functionality.
r144 if form.is_valid():
user = User.objects.get(user_id=form.cleaned_data['user_id'])
request.session['user_id'] = user.id
return redirect(index)
Ilyas
Added admin loing possibility. Now it is abailable under {BASE_URL}/boards/login...
r9
neko259
Added login functionality.
r144 else:
form = LoginForm()
neko259
Added images upload. Changed the design a bit. Reformatted some code by PEP 8. Changed the urls: not the main site is located at /, not /boards/.
r22
neko259
Added login functionality.
r144 context['form'] = form
return render(request, 'boards/login.html', context)
neko259
Added themes support. Added 'snow white' theme by Mystra_x64.
r35
def settings(request):
neko259
Refactored views code. This refs #16
r101 """User's settings"""
neko259
Added users with unique (sort of) IDs. Moved theme setting to user instead of session. This refs #61
r110 context = _init_default_context(request)
neko259
Added ability to disable moderator panel. Refactored forms code. Translating forms.
r205 user = _get_user(request)
is_moderator = user.is_moderator()
neko259
Added themes support. Added 'snow white' theme by Mystra_x64.
r35
if request.method == 'POST':
neko259
Use proper last update timestamps in thread autoupdate
r370 with transaction.commit_on_success():
if is_moderator:
form = ModeratorSettingsForm(request.POST,
error_class=PlainErrorList)
else:
form = SettingsForm(request.POST, error_class=PlainErrorList)
neko259
Added ability to disable moderator panel. Refactored forms code. Translating forms.
r205
neko259
Use proper last update timestamps in thread autoupdate
r370 if form.is_valid():
selected_theme = form.cleaned_data['theme']
neko259
Added users with unique (sort of) IDs. Moved theme setting to user instead of session. This refs #61
r110
neko259
Use proper last update timestamps in thread autoupdate
r370 user.save_setting('theme', selected_theme)
neko259
Added themes support. Added 'snow white' theme by Mystra_x64.
r35
neko259
Use proper last update timestamps in thread autoupdate
r370 if is_moderator:
moderate = form.cleaned_data['moderate']
user.save_setting(SETTING_MODERATE, moderate)
neko259
Added ability to disable moderator panel. Refactored forms code. Translating forms.
r205
neko259
Use proper last update timestamps in thread autoupdate
r370 return redirect(settings)
neko259
Added themes support. Added 'snow white' theme by Mystra_x64.
r35 else:
selected_theme = _get_theme(request)
neko259
Added ability to disable moderator panel. Refactored forms code. Translating forms.
r205 if is_moderator:
form = ModeratorSettingsForm(initial={'theme': selected_theme,
'moderate': context['moderator']},
neko259
Fixed some indent issues in Python code
r319 error_class=PlainErrorList)
neko259
Added ability to disable moderator panel. Refactored forms code. Translating forms.
r205 else:
form = SettingsForm(initial={'theme': selected_theme},
error_class=PlainErrorList)
context['form'] = form
return render(request, 'boards/settings.html', context)
neko259
Added themes support. Added 'snow white' theme by Mystra_x64.
r35
neko259
Limit number of tags shown in the navigation bar to only the most popular ones.
r57 def all_tags(request):
neko259
Refactored views code. This refs #16
r101 """All tags list"""
context = _init_default_context(request)
neko259
Limit number of tags shown in the navigation bar to only the most popular ones.
r57 context['all_tags'] = Tag.objects.get_not_empty_tags()
Ilyas
Templates moved to fit django documentation structure....
r84 return render(request, 'boards/tags.html', context)
neko259
Limit number of tags shown in the navigation bar to only the most popular ones.
r57
neko259
Added jump view to open message of any thread by id. This fixes #49
r98 def jump_to_post(request, post_id):
neko259
Refactored views code. This refs #16
r101 """Determine thread in which the requested post is and open it's page"""
neko259
Added jump view to open message of any thread by id. This fixes #49
r98 post = get_object_or_404(Post, id=post_id)
neko259
Added thread field to the post. 'parent' field is deprecated now.
r174 if not post.thread:
neko259
Fixed some indent issues in Python code
r319 return redirect(thread, post_id=post.id)
neko259
Added jump view to open message of any thread by id. This fixes #49
r98 else:
neko259
Added thread field to the post. 'parent' field is deprecated now.
r174 return redirect(reverse(thread, kwargs={'post_id': post.thread.id})
neko259
Added jump view to open message of any thread by id. This fixes #49
r98 + '#' + str(post.id))
neko259
Added authors page. This fixes #22
r103 def authors(request):
neko259
Added an API method for retrieving post's JSON.
r221 """Show authors list"""
neko259
Added authors page. This fixes #22
r103 context = _init_default_context(request)
context['authors'] = boards.authors.authors
return render(request, 'boards/authors.html', context)
neko259
Removed deprecated transaction annotations and changed them to atomic
r393 @transaction.atomic
neko259
Added admin actions (showing IP, post removal). Added user ranks. This refs #61, #12
r112 def delete(request, post_id):
neko259
Added an API method for retrieving post's JSON.
r221 """Delete post"""
neko259
Added admin actions (showing IP, post removal). Added user ranks. This refs #61, #12
r112 user = _get_user(request)
post = get_object_or_404(Post, id=post_id)
if user.is_moderator():
neko259
Refactored code. Added thread title if the opening post has no title.
r147 # TODO Show confirmation page before deletion
neko259
Added admin actions (showing IP, post removal). Added user ranks. This refs #61, #12
r112 Post.objects.delete_post(post)
neko259
Use proper last update timestamps in thread autoupdate
r370
neko259
Added thread field to the post. 'parent' field is deprecated now.
r174 if not post.thread:
neko259
Added a 'next' attribute to the delete page to return to the current page after deletion.
r155 return _redirect_to_next(request)
neko259
Added admin actions (showing IP, post removal). Added user ranks. This refs #61, #12
r112 else:
neko259
Added thread field to the post. 'parent' field is deprecated now.
r174 return redirect(thread, post_id=post.thread.id)
neko259
Added admin actions (showing IP, post removal). Added user ranks. This refs #61, #12
r112
neko259
Added subscription to tags.
r145
neko259
Removed deprecated transaction annotations and changed them to atomic
r393 @transaction.atomic
neko259
Added 'ban' button to the moderator panel.
r156 def ban(request, post_id):
neko259
Added an API method for retrieving post's JSON.
r221 """Ban user"""
neko259
Added 'ban' button to the moderator panel.
r156 user = _get_user(request)
post = get_object_or_404(Post, id=post_id)
if user.is_moderator():
# TODO Show confirmation page before ban
neko259
Added ban reasons. Added write-only bans.
r340 ban, created = Ban.objects.get_or_create(ip=post.poster_ip)
if created:
ban.reason = 'Banned for post ' + str(post_id)
ban.save()
neko259
Added 'ban' button to the moderator panel.
r156
return _redirect_to_next(request)
neko259
Added IP ban lists. Added migration for bans. Use generic ip address for posting instead of ipv4 only.
r116 def you_are_banned(request):
neko259
Added an API method for retrieving post's JSON.
r221 """Show the page that notifies that user is banned"""
neko259
Added IP ban lists. Added migration for bans. Use generic ip address for posting instead of ipv4 only.
r116 context = _init_default_context(request)
neko259
Added ban reasons. Added write-only bans.
r340
ban = get_object_or_404(Ban, ip=utils.get_client_ip(request))
context['ban_reason'] = ban.reason
neko259
Added a help page.
r152 return render(request, 'boards/staticpages/banned.html', context)
neko259
Added IP ban lists. Added migration for bans. Use generic ip address for posting instead of ipv4 only.
r116
neko259
Added error 404 page
r130 def page_404(request):
neko259
Added an API method for retrieving post's JSON.
r221 """Show page 404 (not found error)"""
neko259
Added error 404 page
r130 context = _init_default_context(request)
return render(request, 'boards/404.html', context)
neko259
Removed deprecated transaction annotations and changed them to atomic
r393 @transaction.atomic
neko259
Added subscription to tags.
r145 def tag_subscribe(request, tag_name):
neko259
Added an API method for retrieving post's JSON.
r221 """Add tag to favorites"""
neko259
Added subscription to tags.
r145 user = _get_user(request)
tag = get_object_or_404(Tag, name=tag_name)
if not tag in user.fav_tags.all():
neko259
Cache user's tags
r323 user.add_tag(tag)
neko259
Added subscription to tags.
r145
neko259
Added star for tag subscribe link. Show the link on the tag view.
r179 return _redirect_to_next(request)
neko259
Added subscription to tags.
r145
neko259
Removed deprecated transaction annotations and changed them to atomic
r393 @transaction.atomic
neko259
Added subscription to tags.
r145 def tag_unsubscribe(request, tag_name):
neko259
Added an API method for retrieving post's JSON.
r221 """Remove tag from favorites"""
neko259
Added subscription to tags.
r145 user = _get_user(request)
tag = get_object_or_404(Tag, name=tag_name)
if tag in user.fav_tags.all():
neko259
Cache user's tags
r323 user.remove_tag(tag)
neko259
Added subscription to tags.
r145
neko259
Added star for tag subscribe link. Show the link on the tag view.
r179 return _redirect_to_next(request)
neko259
Added subscription to tags.
r145
neko259
Added a help page.
r152 def static_page(request, name):
neko259
Added an API method for retrieving post's JSON.
r221 """Show a static page that needs only tags list and a CSS"""
neko259
Added a help page.
r152 context = _init_default_context(request)
return render(request, 'boards/staticpages/' + name + '.html', context)
neko259
Added hover popups for the reflinks.
r222 def api_get_post(request, post_id):
neko259
Added an API method for retrieving post's JSON.
r221 """
neko259
Added hover popups for the reflinks.
r222 Get the JSON of a post. This can be
neko259
Added an API method for retrieving post's JSON.
r221 used as and API for external clients.
"""
post = get_object_or_404(Post, id=post_id)
json = serializers.serialize("json", [post], fields=(
"pub_time", "_text_rendered", "title", "text", "image",
"image_width", "image_height", "replies", "tags"
))
return HttpResponse(content=json)
neko259
Removed deprecated transaction annotations and changed them to atomic
r393 @transaction.atomic
neko259
Update thread by time, not post id. This will help with getting updated posts
r363 def api_get_threaddiff(request, thread_id, last_update_time):
neko259
Use proper last update timestamps in thread autoupdate
r370 """Get posts that were changed or added since time"""
neko259
Added thread autoupdate. Currently has some bugs, not ready for merge with the main branch
r361 thread = get_object_or_404(Post, id=thread_id)
neko259
Update thread by time, not post id. This will help with getting updated posts
r363
neko259
Fixed getting precise and synced last update time. Added autoscroll to bottom after updating if user is at the page bottom
r373 filter_time = datetime.fromtimestamp(float(last_update_time) / 1000000,
neko259
Use proper last update timestamps in thread autoupdate
r370 timezone.get_current_timezone())
neko259
Added thread autoupdate. Currently has some bugs, not ready for merge with the main branch
r361
json_data = {
neko259
Update thread by time, not post id. This will help with getting updated posts
r363 'added': [],
neko259
Loading updated posts in thread autoupdate
r364 'updated': [],
neko259
Use proper last update timestamps in thread autoupdate
r370 'last_update': None,
neko259
Added thread autoupdate. Currently has some bugs, not ready for merge with the main branch
r361 }
neko259
Added order statement to getting added posts
r379 added_posts = Post.objects.filter(thread=thread,
pub_time__gt=filter_time)\
.order_by('pub_time')
neko259
Loading updated posts in thread autoupdate
r364 updated_posts = Post.objects.filter(thread=thread,
neko259
Include posts that were created during one diff and changed in another when...
r382 pub_time__lte=filter_time,
neko259
Use proper last update timestamps in thread autoupdate
r370 last_edit_time__gt=filter_time)
neko259
Update thread by time, not post id. This will help with getting updated posts
r363 for post in added_posts:
neko259
Added thread autoupdate. Currently has some bugs, not ready for merge with the main branch
r361 json_data['added'].append(get_post(request, post.id).content.strip())
neko259
Loading updated posts in thread autoupdate
r364 for post in updated_posts:
json_data['updated'].append(get_post(request, post.id).content.strip())
neko259
Use proper last update timestamps in thread autoupdate
r370 json_data['last_update'] = _datetime_to_epoch(thread.last_edit_time)
neko259
Added thread autoupdate. Currently has some bugs, not ready for merge with the main branch
r361
return HttpResponse(content=json.dumps(json_data))
neko259
Added hover popups for the reflinks.
r222 def get_post(request, post_id):
neko259
Added autoban by the hidden field (to ban spammers and prevent them from trying to post anything).
r271 """Get the html of a post. Used for popups."""
neko259
Added hover popups for the reflinks.
r222
post = get_object_or_404(Post, id=post_id)
neko259
Added thread autoupdate. Currently has some bugs, not ready for merge with the main branch
r361 thread = post.thread
neko259
Fixed loading previews of OPs in bumplimit
r378 if not thread:
thread = post
neko259
Added hover popups for the reflinks.
r222
context = RequestContext(request)
context["post"] = post
neko259
Added thread autoupdate. Currently has some bugs, not ready for merge with the main branch
r361 context["can_bump"] = thread.can_bump()
neko259
Truncate posts in reflink popups
r368 if "truncated" in request.GET:
context["truncated"] = True
neko259
Added hover popups for the reflinks.
r222
return render(request, 'boards/post.html', context)
neko259
Refactored code. Added thread title if the opening post has no title.
r147 def _get_theme(request, user=None):
neko259
Refactored views code. This refs #16
r101 """Get user's CSS theme"""
neko259
Refactored code. Added thread title if the opening post has no title.
r147 if not user:
user = _get_user(request)
neko259
Added users with unique (sort of) IDs. Moved theme setting to user instead of session. This refs #61
r110 theme = user.get_setting('theme')
if not theme:
theme = neboard.settings.DEFAULT_THEME
return theme
neko259
More properly saving the ip address. This fixes #9
r70
neko259
Refactored views code. This refs #16
r101 def _init_default_context(request):
"""Create context with default values that are used in most views"""
context = RequestContext(request)
neko259
Refactored code. Added thread title if the opening post has no title.
r147
user = _get_user(request)
context['user'] = user
neko259
Speed up tags ordering in the navigation panel.
r149 context['tags'] = user.get_sorted_fav_tags()
neko259
Using static template tag for resources.
r260
theme = _get_theme(request, user)
context['theme'] = theme
context['theme_css'] = 'css/' + theme + '/base_page.css'
neko259
Added ability to disable moderator panel. Refactored forms code. Translating forms.
r205
neko259
Added autoban by the hidden field (to ban spammers and prevent them from trying to post anything).
r271 # This shows the moderator panel
neko259
Added ability to disable moderator panel. Refactored forms code. Translating forms.
r205 moderate = user.get_setting(SETTING_MODERATE)
if moderate == 'True':
context['moderator'] = user.is_moderator()
else:
context['moderator'] = False
neko259
Refactored views code. This refs #16
r101
return context
neko259
Added users with unique (sort of) IDs. Moved theme setting to user instead of session. This refs #61
r110
def _get_user(request):
neko259
Added autoban by the hidden field (to ban spammers and prevent them from trying to post anything).
r271 """
Get current user from the session. If the user does not exist, create
a new one.
"""
neko259
Added users with unique (sort of) IDs. Moved theme setting to user instead of session. This refs #61
r110
session = request.session
neko259
Added admin actions (showing IP, post removal). Added user ranks. This refs #61, #12
r112 if not 'user_id' in session:
neko259
Added users with unique (sort of) IDs. Moved theme setting to user instead of session. This refs #61
r110 request.session.save()
md5 = hashlib.md5()
md5.update(session.session_key)
new_id = md5.hexdigest()
neko259
Fixed some tests and views. Added migration for admin model removal.
r141 time_now = timezone.now()
neko259
Added last access time and registration time for user. This refs #61
r121 user = User.objects.create(user_id=new_id, rank=RANK_USER,
neko259
Fixed new user creation. Fixed some posting tests.
r202 registration_time=time_now)
neko259
Added users with unique (sort of) IDs. Moved theme setting to user instead of session. This refs #61
r110
neko259
Added admin actions (showing IP, post removal). Added user ranks. This refs #61, #12
r112 session['user_id'] = user.id
neko259
Added users with unique (sort of) IDs. Moved theme setting to user instead of session. This refs #61
r110 else:
neko259
Added admin actions (showing IP, post removal). Added user ranks. This refs #61, #12
r112 user = User.objects.get(id=session['user_id'])
neko259
Removed user last access time update to speed up page load.
r196
neko259
Merged with default branch
r137 return user
neko259
Added a 'next' attribute to the delete page to return to the current page after deletion.
r155
def _redirect_to_next(request):
neko259
Added autoban by the hidden field (to ban spammers and prevent them from trying to post anything).
r271 """
If a 'next' parameter was specified, redirect to the next page. This is
used when the user is required to return to some page after the current
view has finished its work.
"""
neko259
Added 'ban' button to the moderator panel.
r156 if 'next' in request.GET:
next_page = request.GET['next']
return HttpResponseRedirect(next_page)
else:
return redirect(index)
neko259
Added autoban by the hidden field (to ban spammers and prevent them from trying to post anything).
r271
neko259
Removed deprecated transaction annotations and changed them to atomic
r393 @transaction.atomic
neko259
Added autoban by the hidden field (to ban spammers and prevent them from trying to post anything).
r271 def _ban_current_user(request):
"""Add current user to the IP ban list"""
ip = utils.get_client_ip(request)
neko259
Added ban reasons. Added write-only bans.
r340 ban, created = Ban.objects.get_or_create(ip=ip)
if created:
ban.can_read = False
ban.reason = BAN_REASON_SPAM
ban.save()
neko259
Do not parse links to posts that do not exists in the time of posting.
r312
def _remove_invalid_links(text):
"""
Replace invalid links in posts so that they won't be parsed.
Invalid links are links to non-existent posts
"""
for reply_number in re.finditer(REGEX_REPLY, text):
neko259
Fixed some indent issues in Python code
r319 post_id = reply_number.group(1)
post = Post.objects.filter(id=post_id)
if not post.exists():
neko259
Fixed links to not existing messages
r388 text = string.replace(text, '>>' + post_id, post_id)
neko259
Do not parse links to posts that do not exists in the time of posting.
r312
return text
neko259
Use proper last update timestamps in thread autoupdate
r370
def _datetime_to_epoch(datetime):
return int(time.mktime(timezone.localtime(
datetime,timezone.get_current_timezone()).timetuple())
neko259
Include posts that were created during one diff and changed in another when...
r382 * 1000000 + datetime.microsecond)