Show More
@@ -37,13 +37,17 b' class PostForm(forms.Form):' | |||
|
37 | 37 | |
|
38 | 38 | |
|
39 | 39 | class ThreadForm(PostForm): |
|
40 | INVALID_TAG_CHARACTERS = ['+', '/', '&', '=', '?'] | |
|
41 | ||
|
40 | 42 | tags = forms.CharField(max_length=100) |
|
41 | 43 | |
|
42 | 44 | def clean_tags(self): |
|
43 | 45 | tags = self.cleaned_data['tags'] |
|
44 | 46 | if tags: |
|
45 | if ('+' in tags) or ('/' in tags): | |
|
46 | raise forms.ValidationError('Inappropriate characters in tags') | |
|
47 | for character in tags: | |
|
48 | if character in self.INVALID_TAG_CHARACTERS: | |
|
49 | raise forms.ValidationError( | |
|
50 | 'Inappropriate characters in tags') | |
|
47 | 51 | |
|
48 | 52 | return tags |
|
49 | 53 |
@@ -68,6 +68,8 b' class PostManager(models.Manager):' | |||
|
68 | 68 | |
|
69 | 69 | def get_thread(self, opening_post_id): |
|
70 | 70 | opening_post = self.get(id=opening_post_id) |
|
71 | ||
|
72 | if opening_post.parent == NO_PARENT: | |
|
71 | 73 | replies = self.filter(parent=opening_post_id) |
|
72 | 74 | |
|
73 | 75 | thread = [opening_post] |
@@ -103,12 +105,25 b' class PostManager(models.Manager):' | |||
|
103 | 105 | self.delete_post(thread) |
|
104 | 106 | |
|
105 | 107 | |
|
108 | class TagManager(models.Manager): | |
|
109 | def get_not_empty_tags(self): | |
|
110 | all_tags = self.all() | |
|
111 | tags = [] | |
|
112 | for tag in all_tags: | |
|
113 | if not tag.is_empty(): | |
|
114 | tags.append(tag) | |
|
115 | ||
|
116 | return tags | |
|
117 | ||
|
118 | ||
|
106 | 119 | class Tag(models.Model): |
|
107 | 120 | """ |
|
108 | 121 | A tag is a text node assigned to the post. The tag serves as a board |
|
109 | 122 | section. There can be multiple tags for each message |
|
110 | 123 | """ |
|
111 | 124 | |
|
125 | objects = TagManager() | |
|
126 | ||
|
112 | 127 | name = models.CharField(max_length=100) |
|
113 | 128 | # TODO Connect the tag to its posts to check the number of threads for |
|
114 | 129 | # the tag. |
@@ -117,8 +132,11 b' class Tag(models.Model):' | |||
|
117 | 132 | return self.name |
|
118 | 133 | |
|
119 | 134 | def is_empty(self): |
|
135 | return self.get_post_count() == 0 | |
|
136 | ||
|
137 | def get_post_count(self): | |
|
120 | 138 | posts_with_tag = Post.objects.get_threads(tag=self) |
|
121 |
return len(posts_with_tag) |
|
|
139 | return len(posts_with_tag) | |
|
122 | 140 | |
|
123 | 141 | |
|
124 | 142 | class Post(models.Model): |
@@ -76,4 +76,11 b' html {' | |||
|
76 | 76 | border: solid 1px #666; |
|
77 | 77 | font-size: 0.9em; |
|
78 | 78 | color: #ddd |
|
79 | } | |
|
80 | ||
|
81 | #navigation_panel { | |
|
82 | background: #444; | |
|
83 | margin: 5px; | |
|
84 | padding: 10px; | |
|
85 | border-radius: 5px; | |
|
79 | 86 | } No newline at end of file |
@@ -17,6 +17,7 b' def index(request):' | |||
|
17 | 17 | |
|
18 | 18 | context['threads'] = None if len(threads) == 0 else threads |
|
19 | 19 | context['form'] = forms.ThreadForm() |
|
20 | context['tags'] = Tag.objects.get_not_empty_tags() | |
|
20 | 21 | |
|
21 | 22 | return render(request, 'posting_general.html', |
|
22 | 23 | context) |
@@ -50,7 +51,7 b' def new_post(request, thread_id=boards.m' | |||
|
50 | 51 | tag_strings = data['tags'] |
|
51 | 52 | |
|
52 | 53 | if tag_strings: |
|
53 |
tag_strings = tag_strings.split(' |
|
|
54 | tag_strings = tag_strings.split(',') | |
|
54 | 55 | for tag_name in tag_strings: |
|
55 | 56 | tag_name = tag_name.strip() |
|
56 | 57 | if len(tag_name) > 0: |
@@ -81,6 +82,7 b' def tag(request, tag_name):' | |||
|
81 | 82 | context = RequestContext(request) |
|
82 | 83 | context['threads'] = None if len(threads) == 0 else threads |
|
83 | 84 | context['tag'] = tag_name |
|
85 | context['tags'] = Tag.objects.get_not_empty_tags() | |
|
84 | 86 | |
|
85 | 87 | context['form'] = forms.ThreadForm(initial={'tags': tag_name}) |
|
86 | 88 | |
@@ -98,9 +100,10 b' def thread(request, post_id):' | |||
|
98 | 100 | posts = Post.objects.get_thread(post_id) |
|
99 | 101 | |
|
100 | 102 | context = RequestContext(request) |
|
103 | ||
|
101 | 104 | context['posts'] = posts |
|
102 | ||
|
103 | 105 | context['form'] = forms.PostForm() |
|
106 | context['tags'] = Tag.objects.get_not_empty_tags() | |
|
104 | 107 | |
|
105 | 108 | return render(request, 'thread.html', context) |
|
106 | 109 |
@@ -7,7 +7,7 b' msgid ""' | |||
|
7 | 7 | msgstr "" |
|
8 | 8 | "Project-Id-Version: PACKAGE VERSION\n" |
|
9 | 9 | "Report-Msgid-Bugs-To: \n" |
|
10 |
"POT-Creation-Date: 2013-04-1 |
|
|
10 | "POT-Creation-Date: 2013-04-13 22:07+0300\n" | |
|
11 | 11 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
|
12 | 12 | "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
|
13 | 13 | "Language-Team: LANGUAGE <LL@li.org>\n" |
@@ -18,43 +18,55 b' msgstr ""' | |||
|
18 | 18 | "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" |
|
19 | 19 | "%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" |
|
20 | 20 | |
|
21 |
#: templates/ |
|
|
21 | #: templates/base.html:22 | |
|
22 | msgid "All threads" | |
|
23 | msgstr "Все ники" | |
|
24 | ||
|
25 | #: templates/posting_general.html:26 | |
|
22 | 26 | msgid "View" |
|
23 | 27 | msgstr "Просмотр" |
|
24 | 28 | |
|
25 |
#: templates/posting_general.html: |
|
|
29 | #: templates/posting_general.html:31 | |
|
26 | 30 | msgid "replies" |
|
27 | 31 | msgstr "ответов" |
|
28 | 32 | |
|
29 |
#: templates/posting_general.html:2 |
|
|
33 | #: templates/posting_general.html:32 | |
|
30 | 34 | msgid "images" |
|
31 | 35 | msgstr "изображений" |
|
32 | 36 | |
|
33 |
#: templates/posting_general.html: |
|
|
34 | #: templates/thread.html:23 | |
|
37 | #: templates/posting_general.html:33 | |
|
38 | msgid "gets" | |
|
39 | msgstr "геты" | |
|
40 | ||
|
41 | #: templates/posting_general.html:35 templates/posting_general.html.py:67 | |
|
42 | #: templates/thread.html:31 | |
|
35 | 43 | msgid "Tags" |
|
36 | 44 | msgstr "Теги" |
|
37 | 45 | |
|
38 |
#: templates/posting_general.html: |
|
|
46 | #: templates/posting_general.html:52 | |
|
39 | 47 | msgid "Create new thread" |
|
40 |
msgstr "Создать нов |
|
|
48 | msgstr "Создать новую нить" | |
|
41 | 49 | |
|
42 |
#: templates/posting_general.html: |
|
|
50 | #: templates/posting_general.html:55 templates/thread.html:50 | |
|
43 | 51 | msgid "Title" |
|
44 | 52 | msgstr "Заголовок" |
|
45 | 53 | |
|
46 |
#: templates/posting_general.html:5 |
|
|
54 | #: templates/posting_general.html:59 templates/thread.html:54 | |
|
47 | 55 | msgid "Text" |
|
48 | 56 | msgstr "Текст" |
|
49 | 57 | |
|
50 |
#: templates/posting_general.html: |
|
|
58 | #: templates/posting_general.html:63 templates/thread.html:58 | |
|
51 | 59 | msgid "Image" |
|
52 | 60 | msgstr "Картинка" |
|
53 | 61 | |
|
54 |
#: templates/posting_general.html: |
|
|
62 | #: templates/posting_general.html:70 templates/thread.html:61 | |
|
55 | 63 | msgid "Post" |
|
56 | 64 | msgstr "Отправить" |
|
57 | 65 | |
|
58 |
#: templates/ |
|
|
66 | #: templates/posting_general.html:72 | |
|
67 | msgid "Tags must be delimited by spaces. Text or image is required." | |
|
68 | msgstr "Теги должны быть разделены пробелами. Текст или изображение обязательны." | |
|
69 | ||
|
70 | #: templates/thread.html:47 | |
|
59 | 71 | msgid "Reply to the thread" |
|
60 |
msgstr "Ответить в |
|
|
72 | msgstr "Ответить в нить" |
@@ -1,4 +1,5 b'' | |||
|
1 | 1 | {% load staticfiles %} |
|
2 | {% load i18n %} | |
|
2 | 3 | |
|
3 | 4 | <!DOCTYPE html> |
|
4 | 5 | <html> |
@@ -17,6 +18,14 b'' | |||
|
17 | 18 | |
|
18 | 19 | </div> |
|
19 | 20 | |
|
21 | <div id="navigation_panel"> | |
|
22 | <a class="link" href="{% url 'index' %}">{% trans "All threads" %}</a> | |
|
23 | {% for tag in tags %} | |
|
24 | <a class="tag" href=" {% url 'tag' tag_name=tag.name %}"> | |
|
25 | {{ tag.name }}</a>({{ tag.get_post_count }}) | |
|
26 | {% endfor %} | |
|
27 | </div> | |
|
28 | ||
|
20 | 29 | {% block content %}{% endblock %} |
|
21 | 30 | |
|
22 | 31 | </body> |
General Comments 0
You need to be logged in to leave comments.
Login now