# HG changeset patch # User neko259 # Date 2013-04-05 18:41:12 # Node ID bb515fee6f1cb289da689d2c5bf49f7cff58cd00 # Parent 8653b542879c9c6965dd89405bc2a6c5c1ec71a4 Added localization (not fully working). Added tags posting. Changed the design a bit. diff --git a/boards/forms.py b/boards/forms.py --- a/boards/forms.py +++ b/boards/forms.py @@ -2,7 +2,7 @@ from django import forms class NewThreadForm(forms.Form): - title = forms.CharField(max_length = 100) - text = forms.CharField(widget = forms.Textarea) + title = forms.CharField(max_length=100) + text = forms.CharField(widget=forms.Textarea) image = forms.ImageField() tags = forms.CharField(max_length=100) diff --git a/boards/models.py b/boards/models.py --- a/boards/models.py +++ b/boards/models.py @@ -12,7 +12,7 @@ UNKNOWN_UA = '' class PostManager(models.Manager): def create_post(self, title, text, image=None, parent_id=NO_PARENT, - ip=NO_IP): + ip=NO_IP, tags=None): post = self.create(title=title, text=text, pub_time=timezone.now(), @@ -21,6 +21,10 @@ class PostManager(models.Manager): poster_ip=ip, poster_user_agent=UNKNOWN_UA) + if tags: + for tag in tags: + post.tags.add(tag) + return post def delete_post(self, post): 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 @@ -1,5 +1,6 @@ html { background: #333; + color: #ffffff; } #admin_panel { @@ -12,13 +13,18 @@ html { color: #ffcc00; } -.text { - color: #ffffff; -} - .post-form { text-align: left; color: #ffffff; + display: table; +} + +.form-row { + display: table-row; +} + +.form-input { + display: table-cell; } .link { @@ -36,4 +42,12 @@ html { .block { display: inline-block; vertical-align: top; +} + +.tag { + color: #bb7766; +} + +.tag:hover { + color: #dd8888; } \ No newline at end of file diff --git a/boards/tests.py b/boards/tests.py --- a/boards/tests.py +++ b/boards/tests.py @@ -3,7 +3,7 @@ from django.test.client import Client import boards -from boards.models import Post, Admin +from boards.models import Post, Admin, Tag class BoardTests(TestCase): @@ -95,3 +95,8 @@ class BoardTests(TestCase): thread = Post.objects.get_thread(op_id) self.assertEqual(3, len(thread)) + + def test_create_post_with_tag(self): + tag = Tag.objects.create(name='test_tag') + post = Post.objects.create_post(title='title', text='text', tags=[tag]) + self.assertIsNotNone(post) \ No newline at end of file diff --git a/boards/urls.py b/boards/urls.py --- a/boards/urls.py +++ b/boards/urls.py @@ -12,9 +12,9 @@ urlpatterns = patterns('', url(r'^logout$', views.logout, name='logout'), # /boards/tag/ - url(r'^tag/(?P\w+)/$', views.tag, name = 'tag'), + url(r'^tag/(?P\w+)/$', views.tag, name = 'tag'), # /boards/post_id/ - url(r'^thread/(?P\w+)/$', views.thread, name = 'thread'), + url(r'^thread/(?P\w+)/$', views.thread, name = 'thread'), # /boards/tag/post/ url(r'^post.html$', views.new_post, name='post'), diff --git a/boards/views.py b/boards/views.py --- a/boards/views.py +++ b/boards/views.py @@ -2,7 +2,7 @@ from django.template import RequestConte from boards import forms import boards from boards.forms import NewThreadForm -from boards.models import Post, Admin +from boards.models import Post, Admin, Tag from django.shortcuts import render, get_list_or_404, redirect from django.http import HttpResponseRedirect, Http404 @@ -37,39 +37,57 @@ def new_post(request, thread_id=boards.m ip = request.META['REMOTE_ADDR'] - # TODO Get tags list, download image (if link is given) + tags = [] + if thread_id == boards.models.NO_PARENT: + tag_strings = request.POST['tags'] + + if tag_strings: + tag_strings = tag_strings.split(',') + for tag_name in tag_strings: + tag_name = tag_name.strip() + if len(tag_name) > 0: + tag, created = Tag.objects.get_or_create(name=tag_name) + tags.append(tag) + + # TODO Add a possibility to define a link image instead of an image file. + # If a link is given, download the image automatically. post = Post.objects.create_post(title=title, text=text, ip=ip, - parent_id=thread_id, image=image) + parent_id=thread_id, image=image, + tags=tags) thread_to_show = (post.id if thread_id == boards.models.NO_PARENT else thread_id) - return redirect(thread, id=thread_to_show) + return redirect(thread, post_id=thread_to_show) -def tag(request): +def tag(request, tag_name): """Get all tag threads (posts without a parent).""" - tag_name = request.GET['tag'] - - threads = get_list_or_404(Post, tag=tag_name) + tag = Tag.objects.get(name=tag_name) + threads = get_list_or_404(Post, tags=tag) - context = RequestContext(request) - context['threads'] = None if len(threads) == 0 else threads - context['tag'] = tag_name + if request.method == 'POST': + return new_post(request) + else: + context = RequestContext(request) + context['threads'] = None if len(threads) == 0 else threads + context['tag'] = tag_name - return render(request, 'posting_general.html', - context) + context['form'] = forms.NewThreadForm(initial={'tags': tag_name}) + + return render(request, 'posting_general.html', + context) -def thread(request, id): +def thread(request, post_id): """Get all thread posts""" if request.method == 'POST': - return new_post(request, id) + return new_post(request, post_id) else: # TODO Show 404 if there is no such thread - posts = Post.objects.get_thread(id) + posts = Post.objects.get_thread(post_id) context = RequestContext(request) context['posts'] = posts diff --git a/locale/ru/LC_MESSAGES/django.po b/locale/ru/LC_MESSAGES/django.po new file mode 100644 --- /dev/null +++ b/locale/ru/LC_MESSAGES/django.po @@ -0,0 +1,38 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-04-05 20:55+0300\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"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" + +msgid "Title" +msgstr "Заголовок" + +msgid "Text" +msgstr "Текст" + +msgid "Image" +msgstr "Картинка" + +msgid "Post" +msgstr "Отправить" + +msgid "Tags" +msgstr "Теги" + +msgid "View" +msgstr "Просмотр" \ No newline at end of file diff --git a/templates/posting_general.html b/templates/posting_general.html --- a/templates/posting_general.html +++ b/templates/posting_general.html @@ -1,5 +1,7 @@ {% extends "base.html" %} +{% load i18n %} + {% block content %} {% if threads %} @@ -14,21 +16,46 @@
{{ thread.title }} - [View]
- {{ thread.text }}
+ [{% trans "View" %}]
+ {{ thread.text }}
+ {% if thread.tags %} + {% trans 'Tags' %}: + {% for tag in thread.tags.all %} + + {{ tag.name }} + {% endfor %} + + {% endif %}

{% endfor %} {% else %} - No threads found. + No threads found.
{% endif %}
-
{% csrf_token %} - {{ form.as_p }} - -
+
+
{% csrf_token %} +
+
{% trans 'Title' %}
+
{{ form.title }}
+
+
+
{% trans 'Text' %}
+
{{ form.text }}
+
+
+
{% trans 'Image' %}
+
{{ form.image }}
+
+
+
{% trans 'Tags' %}
+
{{ form.tags }}
+
+ +
+
{% endblock %} \ No newline at end of file diff --git a/templates/thread.html b/templates/thread.html --- a/templates/thread.html +++ b/templates/thread.html @@ -1,5 +1,7 @@ {% extends "base.html" %} +{% load i18n %} + {% block content %} {% if posts %} @@ -14,7 +16,15 @@
{{ post.title }} (#{{ post.id }})
- {{ post.text }}
+ {{ post.text }}
+ {% if post.tags %} + {% trans 'Tags' %}: + {% for tag in post.tags.all %} + + {{ tag.name }} + {% endfor %} + + {% endif %}

{% endfor %} @@ -25,8 +35,19 @@
{% csrf_token %} - {{ form.as_p }} - +
+
{% trans 'Title' %}
+
{{ form.title }}
+
+
+
{% trans 'Text' %}
+
{{ form.text }}
+
+
+
{% trans 'Image' %}
+
{{ form.image }}
+
+