##// END OF EJS Templates
Added checkinf form fields when creating a new thread.
Added checkinf form fields when creating a new thread.

File last commit:

r18:174f8766 default
r18:174f8766 default
Show More
views.py
95 lines | 2.5 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
Ilyas
Added checkinf form fields when creating a new thread.
r18 from boards.forms import NewThreadForm
neko259
Renamed model "admins" to "admin".
r11 from boards.models import Post, Admin
Ilyas
Added creating new thread form...
r14 from django.shortcuts import render, get_list_or_404
Ilyas
Added checkinf form fields when creating a new thread.
r18 from django.http import HttpResponseRedirect
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':
Ilyas
Added checkinf form fields when creating a new thread.
r18
form = NewThreadForm(request.POST)
if form.is_valid():
Post.objects.create_post(form.cleaned_data['title'],
form.cleaned_data['text'], ip = request.META['REMOTE_ADDR'])
else:
context['form'] = form
Ilyas
Added creating new thread form...
r14
neko259
Added methods for getting opening posts and threads.
r5 threads = Post.objects.get_threads()
Ilyas
Added admin loing possibility. Now it is abailable under {BASE_URL}/boards/login...
r9 context['threads'] = None if len(threads) == 0 else threads
Ilyas
Added checkinf form fields when creating a new thread.
r18
if 'form' not in context:
context['form'] = forms.NewThreadForm()
Ilyas
Added admin loing possibility. Now it is abailable under {BASE_URL}/boards/login...
r9
return render(request, 'posting_general.html',
context)
neko259
Initial commit. One test doesn't work, missing posting form.
r0
neko259
Removed images directory. Removed old urls. Added a bit code for the views.
r4 def new_post(request):
"""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']
image = request.POST['image']
neko259
Changed the url to the post page. Added one more TODO.
r6 # TODO Get tags list, download image (if link is given)
neko259
Removed old views. Added a proper deletion of post with children.
r3 post = Post.objects.create_post(title = title, text = text, image = image)
neko259
Removed images directory. Removed old urls. Added a bit code for the views.
r4
neko259
Added methods for getting opening posts and threads.
r5 # TODO Show the thread with a newly created post
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
Changed some links to the html pages.
r12 # TODO Show 404 if there is no such thread
neko259
Fixed getting posts for a thread. Implemented thread getting test.
r17 posts = Post.objects.get_thread(id)
neko259
Added methods for getting opening posts and threads.
r5
neko259
Changed some links to the html pages.
r12 context = RequestContext(request)
context['posts'] = posts
neko259
Fixed getting posts for a thread. Implemented thread getting test.
r17 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')