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