##// END OF EJS Templates
Implemented bumplimit.
Implemented bumplimit.

File last commit:

r35:4962ee48 default
r38:3006249c default
Show More
views.py
163 lines | 4.8 KiB | text/x-python | PythonLexer
Ilyas
Added admin loing possibility. Now it is abailable under {BASE_URL}/boards/login...
r9 from django.template import RequestContext
Ilyas
Added creating new thread form...
r14 from boards import forms
neko259
Added a page to view the thread.
r20 import boards
neko259
Added themes support. Added 'snow white' theme by Mystra_x64.
r35 from boards.forms import ThreadForm, PostForm, SettingsForm
neko259
Added localization (not fully working). Added tags posting. Changed the design a bit.
r24 from boards.models import Post, Admin, Tag
neko259
Added a page to view the thread.
r20 from django.shortcuts import render, get_list_or_404, redirect
Ilyas
Added creating new thread form...
r14 from django.http import HttpResponseRedirect, Http404
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
Initial commit. One test doesn't work, missing posting form.
r0 def index(request):
Ilyas
Added creating new thread form...
r14 context = RequestContext(request)
if request.method == 'POST':
neko259
Added a page to view the thread.
r20 return new_post(request)
else:
threads = Post.objects.get_threads()
neko259
Added methods for getting opening posts and threads.
r5
neko259
Added a page to view the thread.
r20 context['threads'] = None if len(threads) == 0 else threads
neko259
Implemented form validation. When the form fails validation, showing the index page.
r29 context['form'] = forms.ThreadForm()
neko259
Fixed medadata design when an image is present. Added a method to determine if the tag is empty (has no attached threads).
r33 context['tags'] = Tag.objects.get_not_empty_tags()
neko259
Added themes support. Added 'snow white' theme by Mystra_x64.
r35 context['theme'] = _get_theme(request)
Ilyas
Added admin loing possibility. Now it is abailable under {BASE_URL}/boards/login...
r9
neko259
Added a page to view the thread.
r20 return render(request, 'posting_general.html',
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 context)
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 def new_post(request, 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
Implemented form validation. When the form fails validation, showing the index page.
r29 if thread_id == boards.models.NO_PARENT:
form = ThreadForm(request.POST, request.FILES)
else:
form = PostForm(request.POST, request.FILES)
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 if form.is_valid():
data = form.cleaned_data
else:
return redirect(index)
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']
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 a page to view the thread.
r20 ip = request.META['REMOTE_ADDR']
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 = []
if thread_id == boards.models.NO_PARENT:
neko259
Implemented form validation. When the form fails validation, showing the index page.
r29 tag_strings = data['tags']
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)
# TODO Add a possibility to define a link image instead of an image file.
# If a link is given, download the image automatically.
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
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
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 thread_to_show = (post.id if thread_id == boards.models.NO_PARENT else
thread_id)
neko259
Added localization (not fully working). Added tags posting. Changed the design a bit.
r24 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
Added localization (not fully working). Added tags posting. Changed the design a bit.
r24 def tag(request, tag_name):
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 localization (not fully working). Added tags posting. Changed the design a bit.
r24 tag = Tag.objects.get(name=tag_name)
neko259
Truncating thread text in threads list. Fixed tag threads order.
r27 threads = Post.objects.get_threads(tag=tag)
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':
return new_post(request)
else:
context = RequestContext(request)
context['threads'] = None if len(threads) == 0 else threads
context['tag'] = tag_name
neko259
Fixed medadata design when an image is present. Added a method to determine if the tag is empty (has no attached threads).
r33 context['tags'] = Tag.objects.get_not_empty_tags()
neko259
Added themes support. Added 'snow white' theme by Mystra_x64.
r35 context['theme'] = _get_theme(request)
neko259
Changed some links to the html pages.
r12
neko259
Implemented form validation. When the form fails validation, showing the index page.
r29 context['form'] = forms.ThreadForm(initial={'tags': tag_name})
neko259
Added localization (not fully working). Added tags posting. Changed the design a bit.
r24
return render(request, 'posting_general.html',
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
Added a page to view the thread.
r20 if request.method == 'POST':
neko259
Added localization (not fully working). Added tags posting. Changed the design a bit.
r24 return new_post(request, post_id)
neko259
Added a page to view the thread.
r20 else:
# TODO Show 404 if there is no such thread
neko259
Added localization (not fully working). Added tags posting. Changed the design a bit.
r24 posts = Post.objects.get_thread(post_id)
neko259
Added methods for getting opening posts and threads.
r5
neko259
Added a page to view the thread.
r20 context = RequestContext(request)
neko259
Fixed medadata design when an image is present. Added a method to determine if the tag is empty (has no attached threads).
r33
neko259
Added a page to view the thread.
r20 context['posts'] = posts
neko259
Implemented form validation. When the form fails validation, showing the index page.
r29 context['form'] = forms.PostForm()
neko259
Fixed medadata design when an image is present. Added a method to determine if the tag is empty (has no attached threads).
r33 context['tags'] = Tag.objects.get_not_empty_tags()
neko259
Added themes support. Added 'snow white' theme by Mystra_x64.
r35 context['theme'] = _get_theme(request)
neko259
Added a page to view the thread.
r20
return render(request, 'thread.html', context)
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
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:
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 = render(request, 'login.html', {'error': 'Login error'})
Ilyas
Completed login and logout functionality and covered by tests.
r13 else:
response = render(request, '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
context['tags'] = Tag.objects.get_not_empty_tags()
context['theme'] = _get_theme(request)
return render(request, 'settings.html', context)
def _get_theme(request):
return request.session.get('theme', neboard.settings.DEFAULT_THEME)