# HG changeset patch # User neko259 # Date 2013-04-13 19:12:57 # Node ID 45bad15a759576c9c024456e03d23b2b1ffae679 # Parent e74f9cc7b12a56094da7cc8bfcd98443552d3978 Fixed medadata design when an image is present. Added a method to determine if the tag is empty (has no attached threads). diff --git a/boards/forms.py b/boards/forms.py --- a/boards/forms.py +++ b/boards/forms.py @@ -37,13 +37,17 @@ class PostForm(forms.Form): class ThreadForm(PostForm): + INVALID_TAG_CHARACTERS = ['+', '/', '&', '=', '?'] + tags = forms.CharField(max_length=100) def clean_tags(self): tags = self.cleaned_data['tags'] if tags: - if ('+' in tags) or ('/' in tags): - raise forms.ValidationError('Inappropriate characters in tags') + for character in tags: + if character in self.INVALID_TAG_CHARACTERS: + raise forms.ValidationError( + 'Inappropriate characters in tags') return tags diff --git a/boards/models.py b/boards/models.py --- a/boards/models.py +++ b/boards/models.py @@ -68,12 +68,14 @@ class PostManager(models.Manager): def get_thread(self, opening_post_id): opening_post = self.get(id=opening_post_id) - replies = self.filter(parent=opening_post_id) + + if opening_post.parent == NO_PARENT: + replies = self.filter(parent=opening_post_id) - thread = [opening_post] - thread.extend(replies) + thread = [opening_post] + thread.extend(replies) - return thread + return thread def exists(self, post_id): posts = self.filter(id=post_id) @@ -103,12 +105,25 @@ class PostManager(models.Manager): self.delete_post(thread) +class TagManager(models.Manager): + def get_not_empty_tags(self): + all_tags = self.all() + tags = [] + for tag in all_tags: + if not tag.is_empty(): + tags.append(tag) + + return tags + + class Tag(models.Model): """ A tag is a text node assigned to the post. The tag serves as a board section. There can be multiple tags for each message """ + objects = TagManager() + name = models.CharField(max_length=100) # TODO Connect the tag to its posts to check the number of threads for # the tag. @@ -117,8 +132,11 @@ class Tag(models.Model): return self.name def is_empty(self): + return self.get_post_count() == 0 + + def get_post_count(self): posts_with_tag = Post.objects.get_threads(tag=self) - return len(posts_with_tag) == 0 + return len(posts_with_tag) class Post(models.Model): diff --git a/boards/static/css/base_page.css b/boards/static/css/base_page.css --- a/boards/static/css/base_page.css +++ b/boards/static/css/base_page.css @@ -76,4 +76,11 @@ html { border: solid 1px #666; font-size: 0.9em; color: #ddd +} + +#navigation_panel { + background: #444; + margin: 5px; + padding: 10px; + border-radius: 5px; } \ No newline at end of file diff --git a/boards/views.py b/boards/views.py --- a/boards/views.py +++ b/boards/views.py @@ -17,6 +17,7 @@ def index(request): context['threads'] = None if len(threads) == 0 else threads context['form'] = forms.ThreadForm() + context['tags'] = Tag.objects.get_not_empty_tags() return render(request, 'posting_general.html', context) @@ -50,7 +51,7 @@ def new_post(request, thread_id=boards.m tag_strings = data['tags'] if tag_strings: - tag_strings = tag_strings.split(' ') + tag_strings = tag_strings.split(',') for tag_name in tag_strings: tag_name = tag_name.strip() if len(tag_name) > 0: @@ -81,6 +82,7 @@ def tag(request, tag_name): context = RequestContext(request) context['threads'] = None if len(threads) == 0 else threads context['tag'] = tag_name + context['tags'] = Tag.objects.get_not_empty_tags() context['form'] = forms.ThreadForm(initial={'tags': tag_name}) @@ -98,9 +100,10 @@ def thread(request, post_id): posts = Post.objects.get_thread(post_id) context = RequestContext(request) + context['posts'] = posts - context['form'] = forms.PostForm() + context['tags'] = Tag.objects.get_not_empty_tags() return render(request, 'thread.html', context) diff --git a/locale/ru/LC_MESSAGES/django.po b/locale/ru/LC_MESSAGES/django.po --- a/locale/ru/LC_MESSAGES/django.po +++ b/locale/ru/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2013-04-11 21:26+0300\n" +"POT-Creation-Date: 2013-04-13 22:07+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -18,43 +18,55 @@ msgstr "" "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" "%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" -#: templates/posting_general.html:22 +#: templates/base.html:22 +msgid "All threads" +msgstr "Все ники" + +#: templates/posting_general.html:26 msgid "View" msgstr "Просмотр" -#: templates/posting_general.html:25 +#: templates/posting_general.html:31 msgid "replies" msgstr "ответов" -#: templates/posting_general.html:26 +#: templates/posting_general.html:32 msgid "images" msgstr "изображений" -#: templates/posting_general.html:29 templates/posting_general.html.py:61 -#: templates/thread.html:23 +#: templates/posting_general.html:33 +msgid "gets" +msgstr "геты" + +#: templates/posting_general.html:35 templates/posting_general.html.py:67 +#: templates/thread.html:31 msgid "Tags" msgstr "Теги" -#: templates/posting_general.html:46 +#: templates/posting_general.html:52 msgid "Create new thread" -msgstr "Создать новый тред" +msgstr "Создать новую нить" -#: templates/posting_general.html:49 templates/thread.html:42 +#: templates/posting_general.html:55 templates/thread.html:50 msgid "Title" msgstr "Заголовок" -#: templates/posting_general.html:53 templates/thread.html:46 +#: templates/posting_general.html:59 templates/thread.html:54 msgid "Text" msgstr "Текст" -#: templates/posting_general.html:57 templates/thread.html:50 +#: templates/posting_general.html:63 templates/thread.html:58 msgid "Image" msgstr "Картинка" -#: templates/posting_general.html:64 templates/thread.html:53 +#: templates/posting_general.html:70 templates/thread.html:61 msgid "Post" msgstr "Отправить" -#: templates/thread.html:39 +#: templates/posting_general.html:72 +msgid "Tags must be delimited by spaces. Text or image is required." +msgstr "Теги должны быть разделены пробелами. Текст или изображение обязательны." + +#: templates/thread.html:47 msgid "Reply to the thread" -msgstr "Ответить в тред" +msgstr "Ответить в нить" diff --git a/templates/base.html b/templates/base.html --- a/templates/base.html +++ b/templates/base.html @@ -1,4 +1,5 @@ {% load staticfiles %} +{% load i18n %} @@ -17,6 +18,14 @@ + + {% block content %}{% endblock %} diff --git a/templates/posting_general.html b/templates/posting_general.html --- a/templates/posting_general.html +++ b/templates/posting_general.html @@ -2,6 +2,10 @@ {% load i18n %} +{% block head %} + Neboard +{% endblock %} + {% block content %} {% if threads %} diff --git a/templates/thread.html b/templates/thread.html --- a/templates/thread.html +++ b/templates/thread.html @@ -2,6 +2,10 @@ {% load i18n %} +{% block head %} + Neboard +{% endblock %} + {% block content %} {% if posts %}