##// END OF EJS Templates
Added a page to view the thread.
neko259 -
r20:c63898fe default
parent child Browse files
Show More
@@ -1,30 +1,34 b''
1 1 html {
2 background: #555555;
2 background: #333;
3 3 }
4 4
5 5 #admin_panel {
6 6 background: #FF0000;
7 7 color: #00FF00
8 8 }
9 9
10 10 .title {
11 11 font-weight: bold;
12 12 color: #ffcc00;
13 13 }
14 14
15 15 .text {
16 16 color: #ffffff;
17 17 }
18 18
19 19 .post-form {
20 20 text-align: left;
21 21 color: #ffffff;
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,85 +1,93 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
12 return new_post(request)
13 else:
14 14 threads = Post.objects.get_threads()
15 15
16 16 context['threads'] = None if len(threads) == 0 else threads
17 17 context['form'] = forms.NewThreadForm()
18 18
19 19 return render(request, 'posting_general.html',
20 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)."""
38 42
39 43 tag_name = request.GET['tag']
40 44
41 45 threads = get_list_or_404(Post, tag = tag_name)
42 46
43 47 context = RequestContext(request)
44 48 context['threads'] = None if len(threads) == 0 else threads
45 49 context['tag'] = tag_name
46 50
47 51 return render(request, 'posting_general.html',
48 52 context)
49 53
50 54 def thread(request, id):
51 55 """Get all thread posts"""
52 56
57 if request.method == 'POST':
58 return new_post(request, id)
59 else:
53 60 # TODO Show 404 if there is no such thread
54
55 61 posts = Post.objects.get_thread(id)
56 62
57 63 context = RequestContext(request)
58 64 context['posts'] = posts
59 65
66 context['form'] = forms.NewThreadForm()
67
60 68 return render(request, 'thread.html', context)
61 69
62 70 def login(request):
63 71 """Log in as admin"""
64 72
65 73 if 'name' in request.POST and 'password' in request.POST:
66 74 request.session['admin'] = False
67 75
68 76 isAdmin = len(Admin.objects.filter(name = request.POST['name'],
69 77 password = request.POST['password'])) > 0
70 78
71 79 if isAdmin :
72 80 request.session['admin'] = True
73 81
74 82 response = HttpResponseRedirect('/boards')
75 83
76 84 else:
77 85 response = render(request, 'login.html', {'error' : 'Login error'})
78 86 else:
79 87 response = render(request, 'login.html', {})
80 88
81 89 return response
82 90
83 91 def logout(request):
84 92 request.session['admin'] = False
85 93 return HttpResponseRedirect('/boards')
@@ -1,28 +1,28 b''
1 1 {% extends "base.html" %}
2 2
3 3 {% block content %}
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 %}
14 14 No threads found.
15 15 <hr />
16 16 {% endif %}
17 17
18 18 <div class="post-form">
19 19 <form action="/boards/" method="post">{% csrf_token %}
20 20 {{ form.as_p }}
21 21 <input type="submit" value="Post!" />
22 22 </form>
23 23 </div>
24 24
25 25 <HR />
26 26
27 27 {% endblock %}
28 28
@@ -1,28 +1,27 b''
1 1 {% extends "base.html" %}
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 %}
14 13 No threads found.
15 14 <hr />
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>
23 22 </div>
24 23
25 24 <HR />
26 25
27 26 {% endblock %}
28 27
General Comments 0
You need to be logged in to leave comments. Login now