|
|
from django.template import RequestContext
|
|
|
from boards.models import Post, Admins
|
|
|
from django.shortcuts import render
|
|
|
from django.http import HttpResponseRedirect
|
|
|
|
|
|
def index(request):
|
|
|
# TODO Show a real index page with all threads list
|
|
|
threads = Post.objects.get_threads()
|
|
|
|
|
|
context = RequestContext(request)
|
|
|
context['threads'] = None if len(threads) == 0 else threads
|
|
|
|
|
|
return render(request, 'posting_general.html',
|
|
|
context)
|
|
|
|
|
|
def new_post(request):
|
|
|
"""Add a new post (in thread or as a reply)."""
|
|
|
|
|
|
title = request.POST['title']
|
|
|
text = request.POST['text']
|
|
|
|
|
|
image = request.POST['image']
|
|
|
|
|
|
# TODO Get tags list, download image (if link is given)
|
|
|
|
|
|
post = Post.objects.create_post(title = title, text = text, image = image)
|
|
|
|
|
|
# TODO Show the thread with a newly created post
|
|
|
|
|
|
def tag(request):
|
|
|
"""Get all tag threads (posts without a parent)."""
|
|
|
|
|
|
tag_name = request.GET['tag']
|
|
|
|
|
|
posts = Post.objects.get_threads(tag = tag)
|
|
|
|
|
|
# TODO Send a response with the post list
|
|
|
|
|
|
def thread(request):
|
|
|
"""Get all thread posts"""
|
|
|
|
|
|
opening_post_id = request.GET['id']
|
|
|
posts = Post.objects.get_thread(opening_post_id)
|
|
|
|
|
|
# TODO Show all posts for the current thread
|
|
|
|
|
|
def login(request):
|
|
|
if 'name' in request.POST and 'password' in request.POST\
|
|
|
and Admins.objects.is_admin(request.POST['name'],
|
|
|
request.POST['password']):
|
|
|
|
|
|
if request.POST['name'] == 'ilyas':
|
|
|
request.session['admin'] = True
|
|
|
return HttpResponseRedirect('/boards')
|
|
|
else:
|
|
|
|
|
|
return render(request, 'login.html', {'error' : 'Login error'})
|
|
|
|
|
|
else :
|
|
|
return render(request, 'login.html', {})
|
|
|
|