##// END OF EJS Templates
Added fixed image length. This fixes #52
Added fixed image length. This fixes #52

File last commit:

r84:842448d8 default
r88:f32104ea default
Show More
views.py
212 lines | 6.4 KiB | text/x-python | PythonLexer
neko259
Updated the Snow White theme. Scroll to the new post after posting to thread.
r41 from django.core.urlresolvers import reverse
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 form validation, added style for the tag panel. This fixes #13
r76 from django.http import HttpResponseRedirect
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, \
ThreadCaptchaForm, PostCaptchaForm
neko259
Added localization (not fully working). Added tags posting. Changed the design a bit.
r24 from boards.models import Post, Admin, Tag
neko259
Added themes support. Added 'snow white' theme by Mystra_x64.
r35 import neboard
neko259
Initial commit. One test doesn't work, missing posting form.
r0
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):
Ilyas
Added creating new thread form...
r14 context = RequestContext(request)
Ilyas
Added django-simple-capthca support...
r78 threadFormClass = (ThreadForm
if utils.check_if_human(request)
else ThreadCaptchaForm)
Ilyas
Added creating new thread form...
r14 if request.method == 'POST':
Ilyas
Added django-simple-capthca support...
r78 form = threadFormClass(request.POST, request.FILES,
neko259
Fixed captcha design. Added setting to enable or disable captcha. This refs #39
r81 error_class=PlainErrorList)
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 a page to view the thread.
r20 else:
Ilyas
Added django-simple-capthca support...
r78 form = threadFormClass(error_class=PlainErrorList)
neko259
Added form validation, added style for the tag panel. This fixes #13
r76
threads = Post.objects.get_threads(page=int(page))
Ilyas
Added checkinf form fields when creating a new thread.
r18
neko259
Added form validation, added style for the tag panel. This fixes #13
r76 # TODO Get rid of the duplicate code in index and tag views
context['threads'] = None if len(threads) == 0 else threads
context['form'] = form
context['tags'] = Tag.objects.get_popular_tags()
context['theme'] = _get_theme(request)
context['pages'] = range(Post.objects.get_thread_page_count())
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
Added form validation, added style for the tag panel. This fixes #13
r76 def _new_post(request, form, thread_id=boards.models.NO_PARENT):
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 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
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
More properly saving the ip address. This fixes #9
r70 ip = _get_client_ip(request)
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 tags = []
neko259
Updated the Snow White theme. Scroll to the new post after posting to thread.
r41
new_thread = thread_id == boards.models.NO_PARENT
if new_thread:
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:
tag_name = tag_name.strip()
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 localization (not fully working). Added tags posting. Changed the design a bit.
r24 # TODO Add a possibility to define a link image instead of an image file.
# If a link is given, download the image automatically.
neko259
Removed images directory. Removed old urls. Added a bit code for the views.
r4
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
Added localization (not fully working). Added tags posting. Changed the design a bit.
r24 parent_id=thread_id, image=image,
tags=tags)
neko259
Removed images directory. Removed old urls. Added a bit code for the views.
r4
neko259
Updated the Snow White theme. Scroll to the new post after posting to thread.
r41 thread_to_show = (post.id if new_thread else thread_id)
neko259
Added methods for getting opening posts and threads.
r5
neko259
Updated the Snow White theme. Scroll to the new post after posting to thread.
r41 if new_thread:
return redirect(thread, post_id=thread_to_show)
else:
return redirect(reverse(thread,
kwargs={'post_id': thread_to_show}) + '#'
+ str(post.id))
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
Removed images directory. Removed old urls. Added a bit code for the views.
r4 """Get all tag threads (posts without a parent)."""
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
Compiling regexes for gets. #17 Added pagination. #28 Visually differing the dead (not bumpable) threads.
r46 threads = Post.objects.get_threads(tag=tag, page=int(page))
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)
if form.is_valid():
return _new_post(request, form)
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
Added form validation, added style for the tag panel. This fixes #13
r76 context = RequestContext(request)
context['threads'] = None if len(threads) == 0 else threads
context['tag'] = tag_name
context['tags'] = Tag.objects.get_popular_tags()
context['theme'] = _get_theme(request)
context['pages'] = range(Post.objects.get_thread_page_count(tag=tag))
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"""
neko259
Fixed captcha design. Added setting to enable or disable captcha. This refs #39
r81 postFormClass = (PostForm if utils.check_if_human(request) else
PostCaptchaForm)
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,
neko259
Fixed captcha design. Added setting to enable or disable captcha. This refs #39
r81 error_class=PlainErrorList)
neko259
Added form validation, added style for the tag panel. This fixes #13
r76 if form.is_valid():
return _new_post(request, form, post_id)
neko259
Added a page to view the thread.
r20 else:
Ilyas
Added django-simple-capthca support...
r78 form = postFormClass(error_class=PlainErrorList)
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
Added form validation, added style for the tag panel. This fixes #13
r76 context = RequestContext(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
context['tags'] = Tag.objects.get_popular_tags()
context['theme'] = _get_theme(request)
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
Renamed model "admins" to "admin".
r11 """Log in as admin"""
Ilyas
Completed login and logout functionality and covered by tests.
r13 if 'name' in request.POST and 'password' in request.POST:
request.session['admin'] = False
Ilyas
Added admin loing possibility. Now it is abailable under {BASE_URL}/boards/login...
r9
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 isAdmin = len(Admin.objects.filter(name=request.POST['name'],
password=request.POST[
'password'])) > 0
Ilyas
Completed login and logout functionality and covered by tests.
r13
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 if isAdmin:
Ilyas
Added admin loing possibility. Now it is abailable under {BASE_URL}/boards/login...
r9 request.session['admin'] = True
Ilyas
Completed login and logout functionality and covered by tests.
r13
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 response = HttpResponseRedirect('/')
Ilyas
Added admin loing possibility. Now it is abailable under {BASE_URL}/boards/login...
r9
Ilyas
Completed login and logout functionality and covered by tests.
r13 else:
Ilyas
Templates moved to fit django documentation structure....
r84 response = render(request, 'boards/login.html', {'error': 'Login error'})
Ilyas
Completed login and logout functionality and covered by tests.
r13 else:
Ilyas
Templates moved to fit django documentation structure....
r84 response = render(request, 'boards/login.html', {})
Ilyas
Added admin loing possibility. Now it is abailable under {BASE_URL}/boards/login...
r9
Ilyas
Completed login and logout functionality and covered by tests.
r13 return response
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
Ilyas
Completed login and logout functionality and covered by tests.
r13 def logout(request):
request.session['admin'] = False
neko259
Added themes support. Added 'snow white' theme by Mystra_x64.
r35 return HttpResponseRedirect('/')
def settings(request):
context = RequestContext(request)
if request.method == 'POST':
form = SettingsForm(request.POST)
if form.is_valid():
selected_theme = form.cleaned_data['theme']
request.session['theme'] = selected_theme
return redirect(settings)
else:
selected_theme = _get_theme(request)
form = SettingsForm(initial={'theme': selected_theme})
context['form'] = form
neko259
Limit number of tags shown in the navigation bar to only the most popular ones.
r57 context['tags'] = Tag.objects.get_popular_tags()
neko259
Added themes support. Added 'snow white' theme by Mystra_x64.
r35 context['theme'] = _get_theme(request)
Ilyas
Templates moved to fit django documentation structure....
r84 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):
context = RequestContext(request)
context['tags'] = Tag.objects.get_popular_tags()
context['theme'] = _get_theme(request)
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 themes support. Added 'snow white' theme by Mystra_x64.
r35 def _get_theme(request):
neko259
More properly saving the ip address. This fixes #9
r70 return request.session.get('theme', neboard.settings.DEFAULT_THEME)
def _get_client_ip(request):
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
ip = x_forwarded_for.split(',')[-1].strip()
else:
ip = request.META.get('REMOTE_ADDR')
emerge-ng
Improved page showing threads for certain tag. Also some fixes of dependency...
r74 return ip