##// END OF EJS Templates
Added a page to view the thread.
Added a page to view the thread.

File last commit:

r20:c63898fe default
r20:c63898fe default
Show More
views.py
93 lines | 2.6 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
Renamed model "admins" to "admin".
r11 from boards.models import Post, Admin
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
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
context['form'] = forms.NewThreadForm()
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',
context)
neko259
Initial commit. One test doesn't work, missing posting form.
r0
neko259
Added a page to view the thread.
r20 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
Initial commit. One test doesn't work, missing posting form.
r0 title = request.POST['title']
text = request.POST['text']
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
Changed the url to the post page. Added one more TODO.
r6 # TODO Get tags list, download image (if link is given)
neko259
Added a page to view the thread.
r20 post = Post.objects.create_post(title = title, text = text, ip = ip,
parent_id = thread_id)
neko259
Removed images directory. Removed old urls. Added a bit code for the views.
r4
neko259
Added a page to view the thread.
r20 if thread_id != boards.models.NO_PARENT:
request.method = 'GET'
return thread(request, thread_id)
else:
return redirect(thread, id = post.id)
neko259
Added methods for getting opening posts and threads.
r5
neko259
Removed images directory. Removed old urls. Added a bit code for the views.
r4 def tag(request):
"""Get all tag threads (posts without a parent)."""
tag_name = request.GET['tag']
Ilyas
Added creating new thread form...
r14 threads = get_list_or_404(Post, tag = tag_name)
neko259
Added methods for getting opening posts and threads.
r5
neko259
Changed some links to the html pages.
r12 context = RequestContext(request)
context['threads'] = None if len(threads) == 0 else threads
context['tag'] = tag_name
return render(request, 'posting_general.html',
context)
neko259
Removed images directory. Removed old urls. Added a bit code for the views.
r4
neko259
Fixed getting posts for a thread. Implemented thread getting test.
r17 def thread(request, 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':
return new_post(request, id)
else:
# TODO Show 404 if there is no such thread
posts = Post.objects.get_thread(id)
neko259
Added methods for getting opening posts and threads.
r5
neko259
Added a page to view the thread.
r20 context = RequestContext(request)
context['posts'] = posts
neko259
Changed some links to the html pages.
r12
neko259
Added a page to view the thread.
r20 context['form'] = forms.NewThreadForm()
return render(request, '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
Ilyas
Completed login and logout functionality and covered by tests.
r13 isAdmin = len(Admin.objects.filter(name = request.POST['name'],
password = request.POST['password'])) > 0
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
response = HttpResponseRedirect('/boards')
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:
response = render(request, 'login.html', {'error' : 'Login error'})
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
def logout(request):
request.session['admin'] = False
return HttpResponseRedirect('/boards')