##// END OF EJS Templates
Added a page to view the thread.
neko259 -
r20:c63898fe default
parent child Browse files
Show More
@@ -1,5 +1,5 b''
1 1 html {
2 background: #555555;
2 background: #333;
3 3 }
4 4
5 5 #admin_panel {
@@ -22,9 +22,13 b' html {'
22 22 }
23 23
24 24 .link {
25 color: #33bb33
25 color: #33bb33;
26 26 }
27 27
28 28 .link:hover {
29 29 color: #00ff00;
30 }
31
32 .post_id {
33 color: #ffffff;
30 34 } No newline at end of file
@@ -1,37 +1,41 b''
1 1 from django.template import RequestContext
2 2 from boards import forms
3 import boards
3 4 from boards.models import Post, Admin
4 from django.shortcuts import render, get_list_or_404
5 from django.shortcuts import render, get_list_or_404, redirect
5 6 from django.http import HttpResponseRedirect, Http404
6 7
7 8 def index(request):
8 9 context = RequestContext(request)
9 10
10 11 if request.method == 'POST':
11 Post.objects.create_post(request.POST['title'],
12 request.POST['text'], ip = request.META['REMOTE_ADDR'])
13
14 threads = Post.objects.get_threads()
12 return new_post(request)
13 else:
14 threads = Post.objects.get_threads()
15 15
16 context['threads'] = None if len(threads) == 0 else threads
17 context['form'] = forms.NewThreadForm()
16 context['threads'] = None if len(threads) == 0 else threads
17 context['form'] = forms.NewThreadForm()
18 18
19 return render(request, 'posting_general.html',
20 context)
19 return render(request, 'posting_general.html',
20 context)
21 21
22 def new_post(request):
22 def new_post(request, thread_id = boards.models.NO_PARENT):
23 23 """Add a new post (in thread or as a reply)."""
24 24
25 25 title = request.POST['title']
26 26 text = request.POST['text']
27
28 image = request.POST['image']
27 ip = request.META['REMOTE_ADDR']
29 28
30 29 # TODO Get tags list, download image (if link is given)
31 30
32 post = Post.objects.create_post(title = title, text = text, image = image)
31 post = Post.objects.create_post(title = title, text = text, ip = ip,
32 parent_id = thread_id)
33 33
34 # TODO Show the thread with a newly created post
34 if thread_id != boards.models.NO_PARENT:
35 request.method = 'GET'
36 return thread(request, thread_id)
37 else:
38 return redirect(thread, id = post.id)
35 39
36 40 def tag(request):
37 41 """Get all tag threads (posts without a parent)."""
@@ -50,14 +54,18 b' def tag(request):'
50 54 def thread(request, id):
51 55 """Get all thread posts"""
52 56
53 # TODO Show 404 if there is no such thread
54
55 posts = Post.objects.get_thread(id)
57 if request.method == 'POST':
58 return new_post(request, id)
59 else:
60 # TODO Show 404 if there is no such thread
61 posts = Post.objects.get_thread(id)
56 62
57 context = RequestContext(request)
58 context['posts'] = posts
63 context = RequestContext(request)
64 context['posts'] = posts
59 65
60 return render(request, 'thread.html', context)
66 context['form'] = forms.NewThreadForm()
67
68 return render(request, 'thread.html', context)
61 69
62 70 def login(request):
63 71 """Log in as admin"""
@@ -4,10 +4,10 b''
4 4
5 5 {% if threads %}
6 6 {% for thread in threads %}
7 <span class="title">{{ thread.title }}</span><br />
7 <span class="title">{{ thread.title }}</span>
8 <a class="link" href="/boards/post/{{ thread.id }}/">
9 [View]</a><br />
8 10 <span class="text">{{ thread.text }}</span><br />
9 <a class="link" href="/boards/post/{{ thread.id }}/">View
10 thread</a>
11 11 <hr />
12 12 {% endfor %}
13 13 {% else %}
@@ -2,12 +2,11 b''
2 2
3 3 {% block content %}
4 4
5 {% if threads %}
6 {% for thread in threads %}
7 <span class="title">{{ thread.title }}</span><br />
8 <span class="text">{{ thread.text }}</span><br />
9 <a class="link" href="/boards/post/{{ thread.id }}/">View
10 thread</a>
5 {% if posts %}
6 {% for post in posts %}
7 <span class="title">{{ post.title }}</span>
8 <span class="post_id">(#{{ post.id }})</span><br />
9 <span class="text">{{ post.text }}</span><br />
11 10 <hr />
12 11 {% endfor %}
13 12 {% else %}
@@ -16,7 +15,7 b''
16 15 {% endif %}
17 16
18 17 <div class="post-form">
19 <form action="/boards/" method="post">{% csrf_token %}
18 <form method="post">{% csrf_token %}
20 19 {{ form.as_p }}
21 20 <input type="submit" value="Post!" />
22 21 </form>
General Comments 0
You need to be logged in to leave comments. Login now