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