Show More
@@ -1,30 +1,34 b'' | |||||
1 | html { |
|
1 | html { | |
2 |
background: # |
|
2 | background: #333; | |
3 | } |
|
3 | } | |
4 |
|
4 | |||
5 | #admin_panel { |
|
5 | #admin_panel { | |
6 | background: #FF0000; |
|
6 | background: #FF0000; | |
7 | color: #00FF00 |
|
7 | color: #00FF00 | |
8 | } |
|
8 | } | |
9 |
|
9 | |||
10 | .title { |
|
10 | .title { | |
11 | font-weight: bold; |
|
11 | font-weight: bold; | |
12 | color: #ffcc00; |
|
12 | color: #ffcc00; | |
13 | } |
|
13 | } | |
14 |
|
14 | |||
15 | .text { |
|
15 | .text { | |
16 | color: #ffffff; |
|
16 | color: #ffffff; | |
17 | } |
|
17 | } | |
18 |
|
18 | |||
19 | .post-form { |
|
19 | .post-form { | |
20 | text-align: left; |
|
20 | text-align: left; | |
21 | color: #ffffff; |
|
21 | color: #ffffff; | |
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,85 +1,93 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, i |
|
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).""" | |
38 |
|
42 | |||
39 | tag_name = request.GET['tag'] |
|
43 | tag_name = request.GET['tag'] | |
40 |
|
44 | |||
41 | threads = get_list_or_404(Post, tag = tag_name) |
|
45 | threads = get_list_or_404(Post, tag = tag_name) | |
42 |
|
46 | |||
43 | context = RequestContext(request) |
|
47 | context = RequestContext(request) | |
44 | context['threads'] = None if len(threads) == 0 else threads |
|
48 | context['threads'] = None if len(threads) == 0 else threads | |
45 | context['tag'] = tag_name |
|
49 | context['tag'] = tag_name | |
46 |
|
50 | |||
47 | return render(request, 'posting_general.html', |
|
51 | return render(request, 'posting_general.html', | |
48 | context) |
|
52 | context) | |
49 |
|
53 | |||
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""" | |
64 |
|
72 | |||
65 | if 'name' in request.POST and 'password' in request.POST: |
|
73 | if 'name' in request.POST and 'password' in request.POST: | |
66 | request.session['admin'] = False |
|
74 | request.session['admin'] = False | |
67 |
|
75 | |||
68 | isAdmin = len(Admin.objects.filter(name = request.POST['name'], |
|
76 | isAdmin = len(Admin.objects.filter(name = request.POST['name'], | |
69 | password = request.POST['password'])) > 0 |
|
77 | password = request.POST['password'])) > 0 | |
70 |
|
78 | |||
71 | if isAdmin : |
|
79 | if isAdmin : | |
72 | request.session['admin'] = True |
|
80 | request.session['admin'] = True | |
73 |
|
81 | |||
74 | response = HttpResponseRedirect('/boards') |
|
82 | response = HttpResponseRedirect('/boards') | |
75 |
|
83 | |||
76 | else: |
|
84 | else: | |
77 | response = render(request, 'login.html', {'error' : 'Login error'}) |
|
85 | response = render(request, 'login.html', {'error' : 'Login error'}) | |
78 | else: |
|
86 | else: | |
79 | response = render(request, 'login.html', {}) |
|
87 | response = render(request, 'login.html', {}) | |
80 |
|
88 | |||
81 | return response |
|
89 | return response | |
82 |
|
90 | |||
83 | def logout(request): |
|
91 | def logout(request): | |
84 | request.session['admin'] = False |
|
92 | request.session['admin'] = False | |
85 | return HttpResponseRedirect('/boards') |
|
93 | return HttpResponseRedirect('/boards') |
@@ -1,28 +1,28 b'' | |||||
1 | {% extends "base.html" %} |
|
1 | {% extends "base.html" %} | |
2 |
|
2 | |||
3 | {% block content %} |
|
3 | {% block content %} | |
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> |
|
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 %} | |
14 | No threads found. |
|
14 | No threads found. | |
15 | <hr /> |
|
15 | <hr /> | |
16 | {% endif %} |
|
16 | {% endif %} | |
17 |
|
17 | |||
18 | <div class="post-form"> |
|
18 | <div class="post-form"> | |
19 | <form action="/boards/" method="post">{% csrf_token %} |
|
19 | <form action="/boards/" method="post">{% csrf_token %} | |
20 | {{ form.as_p }} |
|
20 | {{ form.as_p }} | |
21 | <input type="submit" value="Post!" /> |
|
21 | <input type="submit" value="Post!" /> | |
22 | </form> |
|
22 | </form> | |
23 | </div> |
|
23 | </div> | |
24 |
|
24 | |||
25 | <HR /> |
|
25 | <HR /> | |
26 |
|
26 | |||
27 | {% endblock %} |
|
27 | {% endblock %} | |
28 |
|
28 |
@@ -1,28 +1,27 b'' | |||||
1 | {% extends "base.html" %} |
|
1 | {% extends "base.html" %} | |
2 |
|
2 | |||
3 | {% block content %} |
|
3 | {% block content %} | |
4 |
|
4 | |||
5 |
{% if t |
|
5 | {% if posts %} | |
6 |
{% for t |
|
6 | {% for post in posts %} | |
7 |
<span class="title">{{ t |
|
7 | <span class="title">{{ post.title }}</span> | |
8 |
<span class=" |
|
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 %} | |
14 | No threads found. |
|
13 | No threads found. | |
15 | <hr /> |
|
14 | <hr /> | |
16 | {% endif %} |
|
15 | {% endif %} | |
17 |
|
16 | |||
18 | <div class="post-form"> |
|
17 | <div class="post-form"> | |
19 |
<form |
|
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> | |
23 | </div> |
|
22 | </div> | |
24 |
|
23 | |||
25 | <HR /> |
|
24 | <HR /> | |
26 |
|
25 | |||
27 | {% endblock %} |
|
26 | {% endblock %} | |
28 |
|
27 |
General Comments 0
You need to be logged in to leave comments.
Login now