Show More
|
1 | NO CONTENT: modified file, binary diff hidden |
|
1 | NO CONTENT: modified file, binary diff hidden |
@@ -1,8 +1,8 b'' | |||
|
1 | 1 | from django import forms |
|
2 | 2 | |
|
3 | 3 | |
|
4 | 4 | class NewThreadForm(forms.Form): |
|
5 | 5 | title = forms.CharField(max_length = 100) |
|
6 | 6 | text = forms.CharField(widget = forms.Textarea) |
|
7 | image = forms.ImageField() | |
|
7 | image = forms.ImageField(required=False) | |
|
8 | 8 | tags = forms.CharField(max_length=100) |
|
1 | NO CONTENT: modified file, binary diff hidden |
@@ -1,30 +1,43 b'' | |||
|
1 | 1 | html { |
|
2 | 2 | background: #555555; |
|
3 | 3 | } |
|
4 | 4 | |
|
5 |
|
|
|
5 | .admin_panel { | |
|
6 | 6 | background: #FF0000; |
|
7 | 7 | color: #00FF00 |
|
8 | 8 | } |
|
9 | 9 | |
|
10 | .input_field { | |
|
11 | ||
|
12 | } | |
|
13 | ||
|
14 | .input_field_name { | |
|
15 | ||
|
16 | } | |
|
17 | ||
|
18 | .input_field_error { | |
|
19 | color: #FF0000; | |
|
20 | } | |
|
21 | ||
|
22 | ||
|
10 | 23 | .title { |
|
11 | 24 | font-weight: bold; |
|
12 | 25 | color: #ffcc00; |
|
13 | 26 | } |
|
14 | 27 | |
|
15 | 28 | .text { |
|
16 | 29 | color: #ffffff; |
|
17 | 30 | } |
|
18 | 31 | |
|
19 | 32 | .post-form { |
|
20 | 33 | text-align: left; |
|
21 | 34 | color: #ffffff; |
|
22 | 35 | } |
|
23 | 36 | |
|
24 | 37 | .link { |
|
25 | 38 | color: #33bb33 |
|
26 | 39 | } |
|
27 | 40 | |
|
28 | 41 | .link:hover { |
|
29 | 42 | color: #00ff00; |
|
30 | 43 | } No newline at end of file |
|
1 | NO CONTENT: modified file, binary diff hidden |
@@ -1,85 +1,95 b'' | |||
|
1 | 1 | from django.template import RequestContext |
|
2 | 2 | from boards import forms |
|
3 | from boards.forms import NewThreadForm | |
|
3 | 4 | from boards.models import Post, Admin |
|
4 | 5 | from django.shortcuts import render, get_list_or_404 |
|
5 |
from django.http import HttpResponseRedirect |
|
|
6 | from django.http import HttpResponseRedirect | |
|
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']) | |
|
12 | ||
|
13 | form = NewThreadForm(request.POST) | |
|
14 | if form.is_valid(): | |
|
15 | ||
|
16 | Post.objects.create_post(form.cleaned_data['title'], | |
|
17 | form.cleaned_data['text'], ip = request.META['REMOTE_ADDR']) | |
|
18 | else: | |
|
19 | context['form'] = form | |
|
20 | ||
|
13 | 21 | |
|
14 | 22 | threads = Post.objects.get_threads() |
|
15 | 23 | |
|
16 | 24 | context['threads'] = None if len(threads) == 0 else threads |
|
25 | ||
|
26 | if 'form' not in context: | |
|
17 | 27 | context['form'] = forms.NewThreadForm() |
|
18 | 28 | |
|
19 | 29 | return render(request, 'posting_general.html', |
|
20 | 30 | context) |
|
21 | 31 | |
|
22 | 32 | def new_post(request): |
|
23 | 33 | """Add a new post (in thread or as a reply).""" |
|
24 | 34 | |
|
25 | 35 | title = request.POST['title'] |
|
26 | 36 | text = request.POST['text'] |
|
27 | 37 | |
|
28 | 38 | image = request.POST['image'] |
|
29 | 39 | |
|
30 | 40 | # TODO Get tags list, download image (if link is given) |
|
31 | 41 | |
|
32 | 42 | post = Post.objects.create_post(title = title, text = text, image = image) |
|
33 | 43 | |
|
34 | 44 | # TODO Show the thread with a newly created post |
|
35 | 45 | |
|
36 | 46 | def tag(request): |
|
37 | 47 | """Get all tag threads (posts without a parent).""" |
|
38 | 48 | |
|
39 | 49 | tag_name = request.GET['tag'] |
|
40 | 50 | |
|
41 | 51 | threads = get_list_or_404(Post, tag = tag_name) |
|
42 | 52 | |
|
43 | 53 | context = RequestContext(request) |
|
44 | 54 | context['threads'] = None if len(threads) == 0 else threads |
|
45 | 55 | context['tag'] = tag_name |
|
46 | 56 | |
|
47 | 57 | return render(request, 'posting_general.html', |
|
48 | 58 | context) |
|
49 | 59 | |
|
50 | 60 | def thread(request, id): |
|
51 | 61 | """Get all thread posts""" |
|
52 | 62 | |
|
53 | 63 | # TODO Show 404 if there is no such thread |
|
54 | 64 | |
|
55 | 65 | posts = Post.objects.get_thread(id) |
|
56 | 66 | |
|
57 | 67 | context = RequestContext(request) |
|
58 | 68 | context['posts'] = posts |
|
59 | 69 | |
|
60 | 70 | return render(request, 'thread.html', context) |
|
61 | 71 | |
|
62 | 72 | def login(request): |
|
63 | 73 | """Log in as admin""" |
|
64 | 74 | |
|
65 | 75 | if 'name' in request.POST and 'password' in request.POST: |
|
66 | 76 | request.session['admin'] = False |
|
67 | 77 | |
|
68 | 78 | isAdmin = len(Admin.objects.filter(name = request.POST['name'], |
|
69 | 79 | password = request.POST['password'])) > 0 |
|
70 | 80 | |
|
71 | 81 | if isAdmin : |
|
72 | 82 | request.session['admin'] = True |
|
73 | 83 | |
|
74 | 84 | response = HttpResponseRedirect('/boards') |
|
75 | 85 | |
|
76 | 86 | else: |
|
77 | 87 | response = render(request, 'login.html', {'error' : 'Login error'}) |
|
78 | 88 | else: |
|
79 | 89 | response = render(request, 'login.html', {}) |
|
80 | 90 | |
|
81 | 91 | return response |
|
82 | 92 | |
|
83 | 93 | def logout(request): |
|
84 | 94 | request.session['admin'] = False |
|
85 | 95 | return HttpResponseRedirect('/boards') |
|
1 | NO CONTENT: modified file, binary diff hidden |
@@ -1,20 +1,20 b'' | |||
|
1 | 1 | <!DOCTYPE html> |
|
2 | 2 | <html> |
|
3 | 3 | <head> |
|
4 | 4 | <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/base_page.css" media="all"/> |
|
5 | 5 | {% block head %}{% endblock %} |
|
6 | 6 | </head> |
|
7 | 7 | <body> |
|
8 |
<div |
|
|
8 | <div class="admin_panel"> | |
|
9 | 9 | |
|
10 | 10 | {% if request.session.admin == True %} |
|
11 | 11 | Admin panel TODO: Need to implement <BR /> |
|
12 | 12 | {% endif %} |
|
13 | 13 | |
|
14 | 14 | |
|
15 | 15 | </div> |
|
16 | 16 | |
|
17 | 17 | {% block content %}{% endblock %} |
|
18 | 18 | |
|
19 | 19 | </body> |
|
20 | 20 | </html> No newline at end of file |
@@ -1,28 +1,52 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 | 7 | <span class="title">{{ thread.title }}</span><br /> |
|
8 | 8 | <span class="text">{{ thread.text }}</span><br /> |
|
9 | 9 | <a class="link" href="/boards/post/{{ thread.id }}/">View |
|
10 | 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 | {{ form.as_p }} | |
|
21 | <input type="submit" value="Post!" /> | |
|
20 | <div class="input_field_name"> | |
|
21 | <span class=input_field_error>{{ form.title.errors }}</span> | |
|
22 | ||
|
23 | <label class=input_field_name for="title">Title</label> | |
|
24 | {{ form.title }} | |
|
25 | </div> | |
|
26 | ||
|
27 | <div class="input_field_name"> | |
|
28 | <span class=input_field_error>{{ form.text.errors }}</span> | |
|
29 | ||
|
30 | <label class=input_field_name for="text">Text</label> | |
|
31 | {{ form.text }} | |
|
32 | </div> | |
|
33 | ||
|
34 | <div class="input_field_name"> | |
|
35 | <label class=input_field_name for="image">Avatar</label> | |
|
36 | {{ form.image }} | |
|
37 | </div> | |
|
38 | ||
|
39 | <div class="input_field_name"> | |
|
40 | <span class=input_field_error>{{ form.tags.errors}}</span> | |
|
41 | <label class=input_field_name for="tags">Name</label> | |
|
42 | {{ form.tags }} | |
|
43 | </div> | |
|
44 | ||
|
45 | <input type="submit" value="Create" /> | |
|
22 | 46 | </form> |
|
23 | 47 | </div> |
|
24 | 48 | |
|
25 | 49 | <HR /> |
|
26 | 50 | |
|
27 | 51 | {% endblock %} |
|
28 | 52 |
General Comments 0
You need to be logged in to leave comments.
Login now