Show More
@@ -0,0 +1,130 b'' | |||
|
1 | # -*- coding: utf-8 -*- | |
|
2 | import datetime | |
|
3 | from south.db import db | |
|
4 | from south.v2 import SchemaMigration | |
|
5 | from django.db import models | |
|
6 | ||
|
7 | ||
|
8 | class Migration(SchemaMigration): | |
|
9 | ||
|
10 | def forwards(self, orm): | |
|
11 | # Deleting model 'Admin' | |
|
12 | db.delete_table(u'boards_admin') | |
|
13 | ||
|
14 | # Adding model 'User' | |
|
15 | db.create_table(u'boards_user', ( | |
|
16 | (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), | |
|
17 | ('user_id', self.gf('django.db.models.fields.CharField')(max_length=50)), | |
|
18 | ('rank', self.gf('django.db.models.fields.IntegerField')()), | |
|
19 | ('registration_time', self.gf('django.db.models.fields.DateTimeField')()), | |
|
20 | ('last_access_time', self.gf('django.db.models.fields.DateTimeField')()), | |
|
21 | )) | |
|
22 | db.send_create_signal(u'boards', ['User']) | |
|
23 | ||
|
24 | # Adding M2M table for field fav_tags on 'User' | |
|
25 | m2m_table_name = db.shorten_name(u'boards_user_fav_tags') | |
|
26 | db.create_table(m2m_table_name, ( | |
|
27 | ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)), | |
|
28 | ('user', models.ForeignKey(orm[u'boards.user'], null=False)), | |
|
29 | ('tag', models.ForeignKey(orm[u'boards.tag'], null=False)) | |
|
30 | )) | |
|
31 | db.create_unique(m2m_table_name, ['user_id', 'tag_id']) | |
|
32 | ||
|
33 | # Adding M2M table for field fav_threads on 'User' | |
|
34 | m2m_table_name = db.shorten_name(u'boards_user_fav_threads') | |
|
35 | db.create_table(m2m_table_name, ( | |
|
36 | ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)), | |
|
37 | ('user', models.ForeignKey(orm[u'boards.user'], null=False)), | |
|
38 | ('post', models.ForeignKey(orm[u'boards.post'], null=False)) | |
|
39 | )) | |
|
40 | db.create_unique(m2m_table_name, ['user_id', 'post_id']) | |
|
41 | ||
|
42 | # Adding model 'Setting' | |
|
43 | db.create_table(u'boards_setting', ( | |
|
44 | (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), | |
|
45 | ('name', self.gf('django.db.models.fields.CharField')(max_length=50)), | |
|
46 | ('value', self.gf('django.db.models.fields.CharField')(max_length=50)), | |
|
47 | ('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['boards.User'])), | |
|
48 | )) | |
|
49 | db.send_create_signal(u'boards', ['Setting']) | |
|
50 | ||
|
51 | # Adding field 'Post.user' | |
|
52 | db.add_column(u'boards_post', 'user', | |
|
53 | self.gf('django.db.models.fields.related.ForeignKey')(default=None, to=orm['boards.User'], null=True), | |
|
54 | keep_default=False) | |
|
55 | ||
|
56 | ||
|
57 | def backwards(self, orm): | |
|
58 | # Adding model 'Admin' | |
|
59 | db.create_table(u'boards_admin', ( | |
|
60 | ('password', self.gf('django.db.models.fields.CharField')(max_length=100)), | |
|
61 | (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), | |
|
62 | ('name', self.gf('django.db.models.fields.CharField')(max_length=100)), | |
|
63 | )) | |
|
64 | db.send_create_signal(u'boards', ['Admin']) | |
|
65 | ||
|
66 | # Deleting model 'User' | |
|
67 | db.delete_table(u'boards_user') | |
|
68 | ||
|
69 | # Removing M2M table for field fav_tags on 'User' | |
|
70 | db.delete_table(db.shorten_name(u'boards_user_fav_tags')) | |
|
71 | ||
|
72 | # Removing M2M table for field fav_threads on 'User' | |
|
73 | db.delete_table(db.shorten_name(u'boards_user_fav_threads')) | |
|
74 | ||
|
75 | # Deleting model 'Setting' | |
|
76 | db.delete_table(u'boards_setting') | |
|
77 | ||
|
78 | # Deleting field 'Post.user' | |
|
79 | db.delete_column(u'boards_post', 'user_id') | |
|
80 | ||
|
81 | ||
|
82 | models = { | |
|
83 | u'boards.ban': { | |
|
84 | 'Meta': {'object_name': 'Ban'}, | |
|
85 | u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | |
|
86 | 'ip': ('django.db.models.fields.GenericIPAddressField', [], {'max_length': '39'}) | |
|
87 | }, | |
|
88 | u'boards.post': { | |
|
89 | 'Meta': {'object_name': 'Post'}, | |
|
90 | '_text_rendered': ('django.db.models.fields.TextField', [], {}), | |
|
91 | u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | |
|
92 | 'image': ('boards.thumbs.ImageWithThumbsField', [], {'max_length': '100', 'blank': 'True'}), | |
|
93 | 'image_height': ('django.db.models.fields.IntegerField', [], {'default': '0'}), | |
|
94 | 'image_width': ('django.db.models.fields.IntegerField', [], {'default': '0'}), | |
|
95 | 'last_edit_time': ('django.db.models.fields.DateTimeField', [], {}), | |
|
96 | 'parent': ('django.db.models.fields.BigIntegerField', [], {}), | |
|
97 | 'poster_ip': ('django.db.models.fields.GenericIPAddressField', [], {'max_length': '39'}), | |
|
98 | 'poster_user_agent': ('django.db.models.fields.TextField', [], {}), | |
|
99 | 'pub_time': ('django.db.models.fields.DateTimeField', [], {}), | |
|
100 | 'tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['boards.Tag']", 'symmetrical': 'False'}), | |
|
101 | 'text': ('markupfield.fields.MarkupField', [], {'rendered_field': 'True'}), | |
|
102 | 'text_markup_type': ('django.db.models.fields.CharField', [], {'default': "'markdown'", 'max_length': '30'}), | |
|
103 | 'title': ('django.db.models.fields.CharField', [], {'max_length': '50'}), | |
|
104 | 'user': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'to': u"orm['boards.User']", 'null': 'True'}) | |
|
105 | }, | |
|
106 | u'boards.setting': { | |
|
107 | 'Meta': {'object_name': 'Setting'}, | |
|
108 | u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | |
|
109 | 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}), | |
|
110 | 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['boards.User']"}), | |
|
111 | 'value': ('django.db.models.fields.CharField', [], {'max_length': '50'}) | |
|
112 | }, | |
|
113 | u'boards.tag': { | |
|
114 | 'Meta': {'object_name': 'Tag'}, | |
|
115 | u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | |
|
116 | 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) | |
|
117 | }, | |
|
118 | u'boards.user': { | |
|
119 | 'Meta': {'object_name': 'User'}, | |
|
120 | 'fav_tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['boards.Tag']", 'symmetrical': 'False'}), | |
|
121 | 'fav_threads': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'+'", 'symmetrical': 'False', 'to': u"orm['boards.Post']"}), | |
|
122 | u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | |
|
123 | 'last_access_time': ('django.db.models.fields.DateTimeField', [], {}), | |
|
124 | 'rank': ('django.db.models.fields.IntegerField', [], {}), | |
|
125 | 'registration_time': ('django.db.models.fields.DateTimeField', [], {}), | |
|
126 | 'user_id': ('django.db.models.fields.CharField', [], {'max_length': '50'}) | |
|
127 | } | |
|
128 | } | |
|
129 | ||
|
130 | complete_apps = ['boards'] No newline at end of file |
@@ -1,7 +1,7 b'' | |||
|
1 | 1 | from django.contrib import admin |
|
2 |
from boards.models import Post, Tag, |
|
|
2 | from boards.models import Post, Tag, User, Ban | |
|
3 | 3 | |
|
4 | 4 | admin.site.register(Post) |
|
5 | 5 | admin.site.register(Tag) |
|
6 |
admin.site.register( |
|
|
7 | admin.site.register(Ban) No newline at end of file | |
|
6 | admin.site.register(User) | |
|
7 | admin.site.register(Ban) |
@@ -2,7 +2,7 b' import re' | |||
|
2 | 2 | from captcha.fields import CaptchaField |
|
3 | 3 | from django import forms |
|
4 | 4 | from django.forms.util import ErrorList |
|
5 | from boards.models import TITLE_MAX_LENGTH | |
|
5 | from boards.models import TITLE_MAX_LENGTH, User | |
|
6 | 6 | from neboard import settings |
|
7 | 7 | from boards import utils |
|
8 | 8 | |
@@ -67,7 +67,6 b' class PostForm(forms.Form):' | |||
|
67 | 67 | self._errors['image'] = self.error_class([error_message]) |
|
68 | 68 | |
|
69 | 69 | |
|
70 | ||
|
71 | 70 | class ThreadForm(PostForm): |
|
72 | 71 | regex_tags = re.compile(ur'^[\w\s\d]+$', re.UNICODE) |
|
73 | 72 | tags = forms.CharField(max_length=100) |
@@ -132,3 +131,21 b' class ThreadCaptchaForm(ThreadForm):' | |||
|
132 | 131 | |
|
133 | 132 | class SettingsForm(forms.Form): |
|
134 | 133 | theme = forms.ChoiceField(choices=settings.THEMES, widget=forms.RadioSelect) |
|
134 | ||
|
135 | ||
|
136 | class LoginForm(forms.Form): | |
|
137 | user_id = forms.CharField() | |
|
138 | ||
|
139 | def clean_user_id(self): | |
|
140 | user_id = self.cleaned_data['user_id'] | |
|
141 | if user_id: | |
|
142 | users = User.objects.filter(user_id=user_id) | |
|
143 | if len(users) == 0: | |
|
144 | raise forms.ValidationError('No such user found') | |
|
145 | ||
|
146 | return user_id | |
|
147 | ||
|
148 | def clean(self): | |
|
149 | cleaned_data = super(LoginForm, self).clean() | |
|
150 | ||
|
151 | return cleaned_data No newline at end of file |
|
1 | NO CONTENT: modified file, binary diff hidden |
@@ -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-0 |
|
|
10 | "POT-Creation-Date: 2013-09-07 19:43+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" |
@@ -54,24 +54,37 b' msgstr "\xd0\x92\xd0\xb0\xd1\x88 IP \xd0\xb0\xd0\xb4\xd1\x80\xd0\xb5\xd1\x81 \xd0\xb1\xd1\x8b\xd0\xbb \xd0\xb7\xd0\xb0\xd0\xb1\xd0\xbb\xd0\xbe\xd0\xba\xd0\xb8\xd1\x80\xd0\xbe\xd0\xb2\xd0\xb0\xd0\xbd. \xd0\xa1\xd0\xb2\xd1\x8f\xd0\xb6\xd0\xb8\xd1\x82\xd0\xb5\xd1\x81\xd1\x8c \xd1\x81 \xd0\xb0\xd0\xb4\xd0\xbc\xd0\xb8\xd0\xbd\xd0\xb8\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd1\x82\xd0\xbe\xd1\x80\xd0\xbe\xd0\xbc"' | |||
|
54 | 54 | msgid "Feed" |
|
55 | 55 | msgstr "Лента" |
|
56 | 56 | |
|
57 |
#: templates/boards/base.html: |
|
|
57 | #: templates/boards/base.html:29 | |
|
58 | 58 | msgid "All threads" |
|
59 | 59 | msgstr "Все темы" |
|
60 | 60 | |
|
61 |
#: templates/boards/base.html: |
|
|
61 | #: templates/boards/base.html:35 | |
|
62 | 62 | msgid "Settings" |
|
63 | 63 | msgstr "Настройки" |
|
64 | 64 | |
|
65 |
#: templates/boards/base.html: |
|
|
65 | #: templates/boards/base.html:42 templates/boards/login.html:6 | |
|
66 | #: templates/boards/login.html.py:21 | |
|
67 | msgid "Login" | |
|
68 | msgstr "Вход" | |
|
69 | ||
|
70 | #: templates/boards/base.html:43 | |
|
66 | 71 | msgid "Up" |
|
67 | 72 | msgstr "Вверх" |
|
68 | 73 | |
|
74 | #: templates/boards/login.html:15 | |
|
75 | msgid "User ID" | |
|
76 | msgstr "ID пользователя" | |
|
77 | ||
|
78 | #: templates/boards/login.html:24 | |
|
79 | msgid "Insert your user id above" | |
|
80 | msgstr "Вставьте свой ID пользователя выше" | |
|
81 | ||
|
69 | 82 | #: templates/boards/posting_general.html:18 |
|
70 | 83 | msgid "Tag: " |
|
71 | 84 | msgstr "Тег: " |
|
72 | 85 | |
|
73 | 86 | #: templates/boards/posting_general.html:35 |
|
74 |
#: templates/boards/posting_general.html:8 |
|
|
87 | #: templates/boards/posting_general.html:89 templates/boards/thread.html:27 | |
|
75 | 88 | #: templates/boards/rss/post.html:5 |
|
76 | 89 | msgid "Post image" |
|
77 | 90 | msgstr "Изображение сообщения" |
@@ -80,93 +93,124 b' msgstr "\xd0\x98\xd0\xb7\xd0\xbe\xd0\xb1\xd1\x80\xd0\xb0\xd0\xb6\xd0\xb5\xd0\xbd\xd0\xb8\xd0\xb5 \xd1\x81\xd0\xbe\xd0\xbe\xd0\xb1\xd1\x89\xd0\xb5\xd0\xbd\xd0\xb8\xd1\x8f"' | |||
|
80 | 93 | msgid "Reply" |
|
81 | 94 | msgstr "Ответ" |
|
82 | 95 | |
|
83 |
#: templates/boards/posting_general.html:5 |
|
|
96 | #: templates/boards/posting_general.html:54 templates/boards/thread.html:46 | |
|
97 | msgid "Delete" | |
|
98 | msgstr "Удалить" | |
|
99 | ||
|
100 | #: templates/boards/posting_general.html:63 templates/boards/thread.html:113 | |
|
84 | 101 | msgid "replies" |
|
85 | 102 | msgstr "ответов" |
|
86 | 103 | |
|
87 |
#: templates/boards/posting_general.html: |
|
|
104 | #: templates/boards/posting_general.html:64 templates/boards/thread.html:114 | |
|
88 | 105 | msgid "images" |
|
89 | 106 | msgstr "изображений" |
|
90 | 107 | |
|
91 |
#: templates/boards/posting_general.html: |
|
|
92 |
#: templates/boards/posting_general.html:13 |
|
|
93 | #: templates/boards/rss/post.html:10 | |
|
108 | #: templates/boards/posting_general.html:66 | |
|
109 | #: templates/boards/posting_general.html:139 templates/boards/tags.html:7 | |
|
110 | #: templates/boards/thread.html:56 templates/boards/rss/post.html:10 | |
|
94 | 111 | msgid "Tags" |
|
95 | 112 | msgstr "Теги" |
|
96 | 113 | |
|
97 |
#: templates/boards/posting_general.html:11 |
|
|
114 | #: templates/boards/posting_general.html:115 | |
|
115 | msgid "No threads exist. Create the first one!" | |
|
116 | msgstr "Нет тем. Создайте первую!" | |
|
117 | ||
|
118 | #: templates/boards/posting_general.html:121 | |
|
98 | 119 | msgid "Create new thread" |
|
99 | 120 | msgstr "Создать новую тему" |
|
100 | 121 | |
|
101 |
#: templates/boards/posting_general.html:1 |
|
|
122 | #: templates/boards/posting_general.html:124 templates/boards/thread.html:75 | |
|
102 | 123 | msgid "Title" |
|
103 | 124 | msgstr "Заголовок" |
|
104 | 125 | |
|
105 |
#: templates/boards/posting_general.html:12 |
|
|
126 | #: templates/boards/posting_general.html:129 templates/boards/thread.html:80 | |
|
106 | 127 | msgid "Text" |
|
107 | 128 | msgstr "Текст" |
|
108 | 129 | |
|
109 |
#: templates/boards/posting_general.html:1 |
|
|
130 | #: templates/boards/posting_general.html:134 templates/boards/thread.html:85 | |
|
110 | 131 | msgid "Image" |
|
111 | 132 | msgstr "Изображение" |
|
112 | 133 | |
|
113 |
#: templates/boards/posting_general.html:14 |
|
|
134 | #: templates/boards/posting_general.html:149 templates/boards/thread.html:96 | |
|
114 | 135 | msgid "Post" |
|
115 | 136 | msgstr "Отправить" |
|
116 | 137 | |
|
117 |
#: templates/boards/posting_general.html:1 |
|
|
138 | #: templates/boards/posting_general.html:151 | |
|
118 | 139 | msgid "Tags must be delimited by spaces. Text or image is required." |
|
119 | 140 | msgstr "" |
|
120 | 141 | "Теги должны быть разделены пробелами. Текст или изображение обязательны." |
|
121 | 142 | |
|
122 |
#: templates/boards/posting_general.html:14 |
|
|
143 | #: templates/boards/posting_general.html:154 templates/boards/thread.html:98 | |
|
123 | 144 | msgid "Basic markdown syntax." |
|
124 | 145 | msgstr "Базовый синтаксис markdown." |
|
125 | 146 | |
|
126 |
#: templates/boards/posting_general.html:1 |
|
|
147 | #: templates/boards/posting_general.html:164 | |
|
127 | 148 | msgid "Pages:" |
|
128 | 149 | msgstr "Страницы: " |
|
129 | 150 | |
|
130 |
#: templates/boards/settings.html:1 |
|
|
151 | #: templates/boards/settings.html:12 | |
|
152 | msgid "User:" | |
|
153 | msgstr "Пользователь:" | |
|
154 | ||
|
155 | #: templates/boards/settings.html:14 | |
|
156 | msgid "You are moderator." | |
|
157 | msgstr "Вы модератор." | |
|
158 | ||
|
159 | #: templates/boards/settings.html:20 | |
|
131 | 160 | msgid "Theme" |
|
132 | 161 | msgstr "Тема" |
|
133 | 162 | |
|
134 |
#: templates/boards/settings.html: |
|
|
163 | #: templates/boards/settings.html:36 | |
|
135 | 164 | msgid "Save" |
|
136 | 165 | msgstr "Сохранить" |
|
137 | 166 | |
|
138 | #: templates/boards/tags.html:7 | |
|
139 |
msgid "t |
|
|
140 |
msgstr "те |
|
|
167 | #: templates/boards/tags.html:17 | |
|
168 | msgid "threads" | |
|
169 | msgstr "тем" | |
|
170 | ||
|
171 | #: templates/boards/tags.html:20 | |
|
172 | msgid "Remove" | |
|
173 | msgstr "Удалить" | |
|
141 | 174 | |
|
142 |
#: templates/boards/t |
|
|
175 | #: templates/boards/tags.html:23 | |
|
176 | msgid "Add" | |
|
177 | msgstr "Добавить" | |
|
178 | ||
|
179 | #: templates/boards/tags.html:28 | |
|
180 | msgid "No tags found." | |
|
181 | msgstr "Теги не найдены." | |
|
182 | ||
|
183 | #: templates/boards/thread.html:72 | |
|
143 | 184 | msgid "Reply to thread" |
|
144 | 185 | msgstr "Ответить в тему" |
|
145 | 186 | |
|
146 |
#: templates/boards/thread.html:9 |
|
|
187 | #: templates/boards/thread.html:99 | |
|
147 | 188 | msgid "Example: " |
|
148 | 189 | msgstr "Пример: " |
|
149 | 190 | |
|
150 |
#: templates/boards/thread.html:9 |
|
|
191 | #: templates/boards/thread.html:99 | |
|
151 | 192 | msgid "italic" |
|
152 | 193 | msgstr "курсив" |
|
153 | 194 | |
|
154 |
#: templates/boards/thread.html: |
|
|
195 | #: templates/boards/thread.html:100 | |
|
155 | 196 | msgid "bold" |
|
156 | 197 | msgstr "полужирный" |
|
157 | 198 | |
|
158 |
#: templates/boards/thread.html: |
|
|
199 | #: templates/boards/thread.html:101 | |
|
159 | 200 | msgid "Quotes can be inserted with" |
|
160 | 201 | msgstr "Цитаты могут быть вставлены при помощи" |
|
161 | 202 | |
|
162 |
#: templates/boards/thread.html: |
|
|
203 | #: templates/boards/thread.html:102 | |
|
163 | 204 | msgid "Links to answers can be inserted with" |
|
164 | 205 | msgstr "Ссылки на ответы могут быть вставлены с помощью" |
|
165 | 206 | |
|
166 |
#: templates/boards/thread.html:11 |
|
|
207 | #: templates/boards/thread.html:115 | |
|
167 | 208 | msgid "Last update: " |
|
168 | 209 | msgstr "Последнее обновление: " |
|
169 | 210 | |
|
211 | #~ msgid "tags" | |
|
212 | #~ msgstr "тегов" | |
|
213 | ||
|
170 | 214 | #~ msgid "Get!" |
|
171 | 215 | #~ msgstr "Гет!" |
|
172 | 216 |
@@ -27,10 +27,14 b' OPENING_POST_POPULARITY_WEIGHT = 2' | |||
|
27 | 27 | IMAGES_DIRECTORY = 'images/' |
|
28 | 28 | FILE_EXTENSION_DELIMITER = '.' |
|
29 | 29 | |
|
30 | RANK_ADMIN = 0 | |
|
31 | RANK_MODERATOR = 10 | |
|
32 | RANK_USER = 100 | |
|
33 | ||
|
30 | 34 | |
|
31 | 35 | class PostManager(models.Manager): |
|
32 | 36 | def create_post(self, title, text, image=None, parent_id=NO_PARENT, |
|
33 | ip=NO_IP, tags=None): | |
|
37 | ip=NO_IP, tags=None, user=None): | |
|
34 | 38 | post = self.create(title=title, |
|
35 | 39 | text=text, |
|
36 | 40 | pub_time=timezone.now(), |
@@ -38,7 +42,8 b' class PostManager(models.Manager):' | |||
|
38 | 42 | image=image, |
|
39 | 43 | poster_ip=ip, |
|
40 | 44 | poster_user_agent=UNKNOWN_UA, |
|
41 |
last_edit_time=timezone.now() |
|
|
45 | last_edit_time=timezone.now(), | |
|
46 | user=user) | |
|
42 | 47 | |
|
43 | 48 | if tags: |
|
44 | 49 | map(post.tags.add, tags) |
@@ -224,6 +229,7 b' class Post(models.Model):' | |||
|
224 | 229 | parent = models.BigIntegerField() |
|
225 | 230 | tags = models.ManyToManyField(Tag) |
|
226 | 231 | last_edit_time = models.DateTimeField() |
|
232 | user = models.ForeignKey('User', null=True, default=None) | |
|
227 | 233 | |
|
228 | 234 | def __unicode__(self): |
|
229 | 235 | return '#' + str(self.id) + ' ' + self.title + ' (' + \ |
@@ -271,19 +277,54 b' class Post(models.Model):' | |||
|
271 | 277 | return last_replies |
|
272 | 278 | |
|
273 | 279 | |
|
274 |
class |
|
|
275 | """ | |
|
276 | Model for admin users | |
|
277 | """ | |
|
278 | name = models.CharField(max_length=100) | |
|
279 | password = models.CharField(max_length=100) | |
|
280 | class User(models.Model): | |
|
281 | ||
|
282 | user_id = models.CharField(max_length=50) | |
|
283 | rank = models.IntegerField() | |
|
284 | ||
|
285 | registration_time = models.DateTimeField() | |
|
286 | last_access_time = models.DateTimeField() | |
|
287 | ||
|
288 | fav_tags = models.ManyToManyField(Tag, null=True, blank=True) | |
|
289 | fav_threads = models.ManyToManyField(Post, related_name='+', null=True, | |
|
290 | blank=True) | |
|
291 | ||
|
292 | def save_setting(self, name, value): | |
|
293 | setting, created = Setting.objects.get_or_create(name=name, user=self) | |
|
294 | setting.value = value | |
|
295 | setting.save() | |
|
296 | ||
|
297 | return setting | |
|
298 | ||
|
299 | def get_setting(self, name): | |
|
300 | settings = Setting.objects.filter(name=name, user=self) | |
|
301 | if len(settings) > 0: | |
|
302 | setting = settings[0] | |
|
303 | else: | |
|
304 | setting = None | |
|
305 | ||
|
306 | if setting: | |
|
307 | setting_value = setting.value | |
|
308 | else: | |
|
309 | setting_value = None | |
|
310 | ||
|
311 | return setting_value | |
|
312 | ||
|
313 | def is_moderator(self): | |
|
314 | return RANK_MODERATOR >= self.rank | |
|
280 | 315 | |
|
281 | 316 | def __unicode__(self): |
|
282 | return self.name + '/' + '*' * len(self.password) | |
|
317 | return self.user_id | |
|
318 | ||
|
319 | ||
|
320 | class Setting(models.Model): | |
|
321 | ||
|
322 | name = models.CharField(max_length=50) | |
|
323 | value = models.CharField(max_length=50) | |
|
324 | user = models.ForeignKey(User) | |
|
283 | 325 | |
|
284 | 326 | |
|
285 | 327 | class Ban(models.Model): |
|
286 | ||
|
287 | 328 | ip = models.GenericIPAddressField() |
|
288 | 329 | |
|
289 | 330 | def __unicode__(self): |
@@ -128,7 +128,7 b' p {' | |||
|
128 | 128 | .form-errors { |
|
129 | 129 | padding-left: 1ex; |
|
130 | 130 | font-weight: bold; |
|
131 |
vertical-align: |
|
|
131 | vertical-align: middle; | |
|
132 | 132 | } |
|
133 | 133 | |
|
134 | 134 | .post-form input, .post-form textarea { |
@@ -274,6 +274,11 b' li {' | |||
|
274 | 274 | color: #ddd; |
|
275 | 275 | } |
|
276 | 276 | |
|
277 | .moderator_info { | |
|
278 | color: #e99d41; | |
|
279 | float: right; | |
|
280 | } | |
|
281 | ||
|
277 | 282 | .refmap { |
|
278 | 283 | font-size: 0.9em; |
|
279 | 284 | color: #ccc; |
@@ -263,8 +263,13 b' li {' | |||
|
263 | 263 | margin-left: 1ex; |
|
264 | 264 | } |
|
265 | 265 | |
|
266 | .moderator_info { | |
|
267 | font-weight: bold; | |
|
268 | float: right; | |
|
269 | } | |
|
270 | ||
|
266 | 271 | .refmap { |
|
267 | 272 | border: 1px dashed #aaa; |
|
268 | 273 | padding: 0.5em; |
|
269 | 274 | display: table; |
|
270 | } No newline at end of file | |
|
275 | } |
@@ -24,19 +24,12 b'' | |||
|
24 | 24 | <script src="{% url 'django.views.i18n.javascript_catalog' %}"></script> |
|
25 | 25 | <script src="{{ STATIC_URL }}js/refmaps.js"></script> |
|
26 | 26 | <script src="{{ STATIC_URL }}js/main.js"></script> |
|
27 | <div id="admin_panel"> | |
|
28 | ||
|
29 | {% if request.session.admin == True %} | |
|
30 | Admin panel TODO: Need to implement <BR /> | |
|
31 | {% endif %} | |
|
32 | ||
|
33 | </div> | |
|
34 | 27 | |
|
35 | 28 | <div class="navigation_panel"> |
|
36 | 29 | <a class="link" href="{% url 'index' %}">{% trans "All threads" %}</a> |
|
37 | 30 | {% for tag in tags %} |
|
38 | 31 |
<a class="tag" href=" |
|
39 |
{{ tag.name }}</a> |
|
|
32 | {{ tag.name }}</a> | |
|
40 | 33 | {% endfor %} |
|
41 | 34 | <a class="tag" href="{% url 'tags' %}">[...]</a> |
|
42 | 35 | <a class="link" href="{% url 'settings' %}">{% trans 'Settings' %}</a> |
@@ -46,7 +39,7 b'' | |||
|
46 | 39 | |
|
47 | 40 | <div class="navigation_panel"> |
|
48 | 41 | {% block metapanel %}{% endblock %} |
|
49 | [<a href="rss/">RSS</a>] | |
|
42 | [<a href="{% url "login" %}">{% trans 'Login' %}</a>] | |
|
50 | 43 | <a class="link" href="#top">{% trans 'Up' %}</a> |
|
51 | 44 | </div> |
|
52 | 45 |
@@ -1,22 +1,29 b'' | |||
|
1 | <!DOCTYPE html> | |
|
2 | <html> | |
|
3 | <head> | |
|
4 | <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/md/login.css" media="all"/> | |
|
5 | <title>Login page</title> | |
|
6 | </head> | |
|
1 | {% extends "boards/base.html" %} | |
|
2 | ||
|
3 | {% load i18n %} | |
|
4 | ||
|
5 | {% block head %} | |
|
6 | <title>{% trans 'Login' %}</title> | |
|
7 | {% endblock %} | |
|
8 | ||
|
9 | {% block content %} | |
|
7 | 10 | |
|
8 | <body> | |
|
9 | {% if error != none%} | |
|
10 | <span id="error_message"> | |
|
11 | {{ error }} | |
|
12 | </span> | |
|
13 | {% endif %} | |
|
11 | <form enctype="multipart/form-data" method="post"> | |
|
12 | <div class="post-form-w"> | |
|
13 | <div class="post-form"> | |
|
14 | <div class="form-row"> | |
|
15 | <div class="form-label">{% trans 'User ID' %}</div> | |
|
16 | <div class="form-input">{{ form.user_id }}</div> | |
|
17 | <div class="form-errors">{{ form.user_id.errors }}</div> | |
|
18 | </div> | |
|
19 | </div> | |
|
20 | <div class="form-submit"> | |
|
21 | <input type="submit" value="{% trans "Login" %}"/> | |
|
22 | </div> | |
|
23 | <div> | |
|
24 | {% trans 'Insert your user id above' %} | |
|
25 | </div> | |
|
26 | </div> | |
|
27 | </form> | |
|
14 | 28 | |
|
15 | <form action="login" method="POST">{% csrf_token %} | |
|
16 | ||
|
17 | Login: <input type="text" name="name"><br /> | |
|
18 | Password: <input type="password" name="password"><br /> | |
|
19 | <input type="submit"> | |
|
20 | </form> | |
|
21 | </body> | |
|
22 | </html> No newline at end of file | |
|
29 | {% endblock %} No newline at end of file |
@@ -46,6 +46,14 b'' | |||
|
46 | 46 | [{{ thread.pub_time }}] |
|
47 | 47 | [<a class="link" href="{% url 'thread' thread.id %}#form" |
|
48 | 48 | >{% trans "Reply" %}</a>] |
|
49 | ||
|
50 | {% if user.is_moderator %} | |
|
51 | <span class="moderator_info"> | |
|
52 | ({{ thread.poster_ip }}) | |
|
53 | [<a href="{% url 'delete' post_id=thread.id %}" | |
|
54 | >{% trans 'Delete' %}</a>] | |
|
55 | </span> | |
|
56 | {% endif %} | |
|
49 | 57 | </div> |
|
50 | 58 | {% autoescape off %} |
|
51 | 59 | {{ thread.text.rendered|truncatewords_html:50 }} |
@@ -103,8 +111,8 b'' | |||
|
103 | 111 | </div> |
|
104 | 112 | {% endfor %} |
|
105 | 113 | {% else %} |
|
106 | No threads found. | |
|
107 | <hr /> | |
|
114 | <div class="post"> | |
|
115 | {% trans 'No threads exist. Create the first one!' %}</div> | |
|
108 | 116 | {% endif %} |
|
109 | 117 | |
|
110 | 118 | <form enctype="multipart/form-data" method="post">{% csrf_token %} |
@@ -163,6 +171,7 b'' | |||
|
163 | 171 | {% endif %} |
|
164 | 172 | ">{{ page }}</a>] |
|
165 | 173 | {% endfor %} |
|
174 | [<a href="rss/">RSS</a>] | |
|
166 | 175 | </span> |
|
167 | 176 | |
|
168 | 177 | {% endblock %} |
@@ -8,6 +8,13 b'' | |||
|
8 | 8 | |
|
9 | 9 | {% block content %} |
|
10 | 10 | |
|
11 | <div class="post"> | |
|
12 | {% trans 'User:' %} <b>{{ user.user_id }}</b>. | |
|
13 | {% if user.is_moderator %} | |
|
14 | {% trans 'You are moderator.' %} | |
|
15 | {% endif %} | |
|
16 | </div> | |
|
17 | ||
|
11 | 18 | <div class="post-form-w"> |
|
12 | 19 | <div class="post-form"> |
|
13 | 20 | <span class="form-title">{% trans "Theme" %}</span> |
@@ -4,20 +4,28 b'' | |||
|
4 | 4 | {% load markup %} |
|
5 | 5 | |
|
6 | 6 | {% block head %} |
|
7 |
<title>Neboard - {% trans " |
|
|
7 | <title>Neboard - {% trans "Tags" %}</title> | |
|
8 | 8 | {% endblock %} |
|
9 | 9 | |
|
10 | 10 | {% block content %} |
|
11 | 11 | |
|
12 | 12 | <div class="post"> |
|
13 | {% if tags %} | |
|
13 | {% if all_tags %} | |
|
14 | 14 | {% for tag in all_tags %} |
|
15 | 15 | <a class="tag" href="{% url 'tag' tag.name %}"> |
|
16 |
{{ tag.name }}</a> |
|
|
16 | {{ tag.name }}</a> | |
|
17 | ({{ tag.get_post_count }} {% trans 'threads' %}) | |
|
18 | {% if tag in user.fav_tags.all %} | |
|
19 | [<a href="{% url 'tag_unsubscribe' tag.name %}" | |
|
20 | >{% trans 'Remove' %}</a>] | |
|
21 | {% else %} | |
|
22 | [<a href="{% url 'tag_subscribe' tag.name %}" | |
|
23 | >{% trans 'Add' %}</a>] | |
|
24 | {% endif %} | |
|
25 | <br /> | |
|
17 | 26 | {% endfor %} |
|
18 | 27 | {% else %} |
|
19 | No tags found. | |
|
20 | <hr /> | |
|
28 | {% trans 'No tags found.' %} | |
|
21 | 29 | {% endif %} |
|
22 | 30 | </div> |
|
23 | 31 |
@@ -38,6 +38,14 b'' | |||
|
38 | 38 | [{{ post.pub_time }}] |
|
39 | 39 | [<a href="#" onclick="javascript:addQuickReply('{{ post.id }}') |
|
40 | 40 | ; return false;">>></a>] |
|
41 | ||
|
42 | {% if user.is_moderator %} | |
|
43 | <span class="moderator_info"> | |
|
44 | ({{ post.poster_ip }}) | |
|
45 | [<a href="{% url 'delete' post_id=post.id %}" | |
|
46 | >{% trans 'Delete' %}</a>] | |
|
47 | </span> | |
|
48 | {% endif %} | |
|
41 | 49 | </div> |
|
42 | 50 | {% autoescape off %} |
|
43 | 51 | {{ post.text.rendered }} |
@@ -56,9 +64,6 b'' | |||
|
56 | 64 | </div> |
|
57 | 65 | {% endfor %} |
|
58 | 66 | </div> |
|
59 | {% else %} | |
|
60 | No thread found. | |
|
61 | <hr /> | |
|
62 | 67 | {% endif %} |
|
63 | 68 | |
|
64 | 69 | <form id="form" enctype="multipart/form-data" method="post" |
@@ -108,6 +113,7 b'' | |||
|
108 | 113 | {{ posts.0.get_reply_count }} {% trans 'replies' %}, |
|
109 | 114 | {{ posts.0.get_images_count }} {% trans 'images' %}. |
|
110 | 115 | {% trans 'Last update: ' %}{{ posts.0.last_edit_time }} |
|
116 | [<a href="rss/">RSS</a>] | |
|
111 | 117 | </span> |
|
112 | 118 | |
|
113 | 119 | {% endblock %} |
@@ -4,7 +4,7 b' from django.test.client import Client' | |||
|
4 | 4 | |
|
5 | 5 | import boards |
|
6 | 6 | |
|
7 |
from boards.models import Post, |
|
|
7 | from boards.models import Post, Tag | |
|
8 | 8 | from neboard import settings |
|
9 | 9 | |
|
10 | 10 | TEST_TEXT = 'test text' |
@@ -54,48 +54,6 b' class BoardTests(TestCase):' | |||
|
54 | 54 | admin.save() |
|
55 | 55 | return admin |
|
56 | 56 | |
|
57 | def test_admin_login(self): | |
|
58 | client = Client() | |
|
59 | ||
|
60 | self.assertFalse('admin' in client.session) | |
|
61 | ||
|
62 | admin = self._create_test_user() | |
|
63 | ||
|
64 | response = client.post('/login', | |
|
65 | {'name': admin.name, 'password': admin.password}) | |
|
66 | ||
|
67 | # it means that login passed and user are redirected to another page | |
|
68 | self.assertEqual(302, response.status_code) | |
|
69 | ||
|
70 | self.assertTrue('admin' in client.session) | |
|
71 | self.assertTrue(client.session['admin']) | |
|
72 | ||
|
73 | admin.delete() | |
|
74 | ||
|
75 | wrong_name = 'sd2f1s3d21fs3d21f' | |
|
76 | wrong_password = 'sd2f1s3d21fs3d21fsdfsd' | |
|
77 | ||
|
78 | client.post('/login', {'name': wrong_name, 'password': wrong_password}) | |
|
79 | self.assertFalse(client.session['admin']) | |
|
80 | ||
|
81 | def test_admin_logout(self): | |
|
82 | client = Client() | |
|
83 | ||
|
84 | self.assertFalse('admin' in client.session) | |
|
85 | ||
|
86 | admin = self._create_test_user() | |
|
87 | ||
|
88 | client.post('/login', | |
|
89 | {'name': admin.name, 'password': admin.password}) | |
|
90 | ||
|
91 | self.assertTrue(client.session['admin']) | |
|
92 | ||
|
93 | client.get('/logout') | |
|
94 | ||
|
95 | self.assertFalse(client.session['admin']) | |
|
96 | ||
|
97 | admin.delete() | |
|
98 | ||
|
99 | 57 | def test_get_thread(self): |
|
100 | 58 | opening_post = self._create_post() |
|
101 | 59 | op_id = opening_post.id |
@@ -120,13 +78,6 b' class BoardTests(TestCase):' | |||
|
120 | 78 | self.assertEqual(settings.MAX_THREAD_COUNT, |
|
121 | 79 | len(Post.objects.get_threads())) |
|
122 | 80 | |
|
123 | def test_get(self): | |
|
124 | """Test if the get computes properly""" | |
|
125 | ||
|
126 | post = self._create_post() | |
|
127 | ||
|
128 | self.assertTrue(post.is_get()) | |
|
129 | ||
|
130 | 81 | def test_pages(self): |
|
131 | 82 | """Test that the thread list is properly split into pages""" |
|
132 | 83 | |
@@ -202,6 +153,7 b' class BoardTests(TestCase):' | |||
|
202 | 153 | |
|
203 | 154 | response_not_existing = client.get(THREAD_PAGE + str( |
|
204 | 155 | existing_post_id + 1) + '/') |
|
156 | response_not_existing.get_full_path() | |
|
205 | 157 | self.assertEqual(HTTP_CODE_NOT_FOUND, |
|
206 | 158 | response_not_existing.status_code, |
|
207 | 159 | u'Not existing thread is opened') |
@@ -9,6 +9,7 b' from PIL import Image' | |||
|
9 | 9 | from django.core.files.base import ContentFile |
|
10 | 10 | import cStringIO |
|
11 | 11 | |
|
12 | ||
|
12 | 13 | def generate_thumb(img, thumb_size, format): |
|
13 | 14 | """ |
|
14 | 15 | Generates a thumbnail image and returns a ContentFile object with the thumbnail |
@@ -38,7 +39,8 b' def generate_thumb(img, thumb_size, form' | |||
|
38 | 39 | xnewsize = (xsize-minsize)/2 |
|
39 | 40 | ynewsize = (ysize-minsize)/2 |
|
40 | 41 | # crop it |
|
41 | image2 = image.crop((xnewsize, ynewsize, xsize-xnewsize, ysize-ynewsize)) | |
|
42 | image2 = image.crop( | |
|
43 | (xnewsize, ynewsize, xsize - xnewsize, ysize - ynewsize)) | |
|
42 | 44 | # load is necessary after crop |
|
43 | 45 | image2.load() |
|
44 | 46 | # thumbnail of the cropped image (with ANTIALIAS to make it look better) |
@@ -56,10 +58,12 b' def generate_thumb(img, thumb_size, form' | |||
|
56 | 58 | image2.save(io, format) |
|
57 | 59 |
return ContentFile(io.getvalue()) |
|
58 | 60 | |
|
61 | ||
|
59 | 62 | class ImageWithThumbsFieldFile(ImageFieldFile): |
|
60 | 63 | """ |
|
61 | 64 | See ImageWithThumbsField for usage example |
|
62 | 65 | """ |
|
66 | ||
|
63 | 67 | def __init__(self, *args, **kwargs): |
|
64 | 68 | super(ImageWithThumbsFieldFile, self).__init__(*args, **kwargs) |
|
65 | 69 | self.sizes = self.field.sizes |
@@ -92,7 +96,8 b' class ImageWithThumbsFieldFile(ImageFiel' | |||
|
92 | 96 |
thumb_name_ = self.storage.save(thumb_name, thumb_content) |
|
93 | 97 | |
|
94 | 98 | if not thumb_name == thumb_name_: |
|
95 |
raise ValueError( |
|
|
99 | raise ValueError( | |
|
100 | 'There is already a file named %s' % thumb_name) | |
|
96 | 101 | |
|
97 | 102 | def delete(self, save=True): |
|
98 | 103 | name=self.name |
@@ -107,6 +112,7 b' class ImageWithThumbsFieldFile(ImageFiel' | |||
|
107 | 112 | except: |
|
108 | 113 | pass |
|
109 | 114 | |
|
115 | ||
|
110 | 116 | class ImageWithThumbsField(ImageField): |
|
111 | 117 | attr_class = ImageWithThumbsFieldFile |
|
112 | 118 | """ |
@@ -152,7 +158,9 b' class ImageWithThumbsField(ImageField):' | |||
|
152 | 158 | |
|
153 | 159 | |
|
154 | 160 | """ |
|
155 | def __init__(self, verbose_name=None, name=None, width_field=None, height_field=None, sizes=None, **kwargs): | |
|
161 | ||
|
162 | def __init__(self, verbose_name=None, name=None, width_field=None, | |
|
163 | height_field=None, sizes=None, **kwargs): | |
|
156 | 164 | self.verbose_name=verbose_name |
|
157 | 165 | self.name=name |
|
158 | 166 | self.width_field=width_field |
@@ -162,4 +170,4 b' class ImageWithThumbsField(ImageField):' | |||
|
162 | 170 | |
|
163 | 171 | |
|
164 | 172 | from south.modelsinspector import add_introspection_rules |
|
165 | add_introspection_rules([], ["^boards\.thumbs\.ImageWithThumbsField"]) No newline at end of file | |
|
173 | add_introspection_rules([], ["^boards\.thumbs\.ImageWithThumbsField"]) |
@@ -14,22 +14,29 b" urlpatterns = patterns(''," | |||
|
14 | 14 | url(r'^page/(?P<page>\w+)/$', views.index, name='index'), |
|
15 | 15 | |
|
16 | 16 | # login page |
|
17 | url(r'^login$', views.login, name='login'), | |
|
18 | # logout page | |
|
19 | url(r'^logout$', views.logout, name='logout'), | |
|
17 | url(r'^login/$', views.login, name='login'), | |
|
20 | 18 | |
|
21 | 19 | # /boards/tag/tag_name/ |
|
22 | 20 | url(r'^tag/(?P<tag_name>\w+)/$', views.tag, name='tag'), |
|
23 | 21 | # /boards/tag/tag_id/page/ |
|
24 | 22 | url(r'^tag/(?P<tag_name>\w+)/page/(?P<page>\w+)/$', views.tag, name='tag'), |
|
23 | ||
|
24 | # /boards/tag/tag_name/unsubscribe/ | |
|
25 | url(r'^tag/(?P<tag_name>\w+)/subscribe/$', views.tag_subscribe, | |
|
26 | name='tag_subscribe'), | |
|
27 | # /boards/tag/tag_name/unsubscribe/ | |
|
28 | url(r'^tag/(?P<tag_name>\w+)/unsubscribe/$', views.tag_unsubscribe, | |
|
29 | name='tag_unsubscribe'), | |
|
30 | ||
|
25 | 31 | # /boards/thread/ |
|
26 | 32 | url(r'^thread/(?P<post_id>\w+)/$', views.thread, name='thread'), |
|
27 | 33 | # /boards/theme/theme_name/ |
|
28 | url(r'^settings$', views.settings, name='settings'), | |
|
29 | url(r'^tags$', views.all_tags, name='tags'), | |
|
34 | url(r'^settings/$', views.settings, name='settings'), | |
|
35 | url(r'^tags/$', views.all_tags, name='tags'), | |
|
30 | 36 | url(r'^captcha/', include('captcha.urls')), |
|
31 | 37 | url(r'^jump/(?P<post_id>\w+)/$', views.jump_to_post, name='jumper'), |
|
32 | 38 | url(r'^authors/$', views.authors, name='authors'), |
|
39 | url(r'^delete/(?P<post_id>\w+)/$', views.delete, name='delete'), | |
|
33 | 40 | url(r'^banned/$', views.you_are_banned, name='banned'), |
|
34 | 41 | |
|
35 | 42 | # RSS feeds |
@@ -40,4 +47,4 b" urlpatterns = patterns(''," | |||
|
40 | 47 | url(r'^thread/(?P<post_id>\w+)/rss/$', ThreadPostsFeed()), |
|
41 | 48 | |
|
42 | 49 | url(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict), |
|
43 | ) No newline at end of file | |
|
50 | ) |
@@ -1,15 +1,17 b'' | |||
|
1 | import hashlib | |
|
1 | 2 | from django.core.urlresolvers import reverse |
|
2 | 3 | from django.template import RequestContext |
|
3 | 4 | from django.shortcuts import render, redirect, get_object_or_404 |
|
4 | 5 | from django.http import HttpResponseRedirect |
|
6 | from django.utils import timezone | |
|
5 | 7 | |
|
6 | 8 | from boards import forms |
|
7 | 9 | import boards |
|
8 | 10 | from boards import utils |
|
9 | 11 | from boards.forms import ThreadForm, PostForm, SettingsForm, PlainErrorList, \ |
|
10 | ThreadCaptchaForm, PostCaptchaForm | |
|
12 | ThreadCaptchaForm, PostCaptchaForm, LoginForm | |
|
11 | 13 | |
|
12 |
from boards.models import Post, |
|
|
14 | from boards.models import Post, Tag, Ban, User, RANK_USER, RANK_MODERATOR, NO_PARENT | |
|
13 | 15 | from boards import authors |
|
14 | 16 | import neboard |
|
15 | 17 | |
@@ -148,51 +150,43 b' def thread(request, post_id):' | |||
|
148 | 150 | |
|
149 | 151 | |
|
150 | 152 | def login(request): |
|
151 |
"""Log in |
|
|
153 | """Log in with user id""" | |
|
152 | 154 | |
|
153 | if 'name' in request.POST and 'password' in request.POST: | |
|
154 | request.session['admin'] = False | |
|
155 | context = _init_default_context(request) | |
|
155 | 156 | |
|
156 | isAdmin = len(Admin.objects.filter(name=request.POST['name'], | |
|
157 | password=request.POST[ | |
|
158 | 'password'])) > 0 | |
|
159 | ||
|
160 | if isAdmin: | |
|
161 | request.session['admin'] = True | |
|
162 | ||
|
163 | response = HttpResponseRedirect('/') | |
|
157 | if request.method == 'POST': | |
|
158 | form = LoginForm(request.POST, request.FILES, error_class=PlainErrorList) | |
|
159 | if form.is_valid(): | |
|
160 | user = User.objects.get(user_id=form.cleaned_data['user_id']) | |
|
161 | request.session['user_id'] = user.id | |
|
162 | return redirect(index) | |
|
164 | 163 | |
|
165 | 164 |
|
|
166 | response = render(request, 'boards/login.html', {'error': 'Login error'}) | |
|
167 | else: | |
|
168 | response = render(request, 'boards/login.html', {}) | |
|
165 | form = LoginForm() | |
|
169 | 166 | |
|
170 | return response | |
|
171 | ||
|
167 | context['form'] = form | |
|
172 | 168 | |
|
173 | def logout(request): | |
|
174 | request.session['admin'] = False | |
|
175 | return HttpResponseRedirect('/') | |
|
169 | return render(request, 'boards/login.html', context) | |
|
176 | 170 | |
|
177 | 171 | |
|
178 | 172 | def settings(request): |
|
179 | 173 | """User's settings""" |
|
180 | 174 | |
|
181 |
context = |
|
|
175 | context = _init_default_context(request) | |
|
182 | 176 | |
|
183 | 177 | if request.method == 'POST': |
|
184 | 178 | form = SettingsForm(request.POST) |
|
185 | 179 | if form.is_valid(): |
|
186 | 180 | selected_theme = form.cleaned_data['theme'] |
|
187 | request.session['theme'] = selected_theme | |
|
181 | ||
|
182 | user = _get_user(request) | |
|
183 | user.save_setting('theme', selected_theme) | |
|
188 | 184 | |
|
189 | 185 | return redirect(settings) |
|
190 | 186 | else: |
|
191 | 187 | selected_theme = _get_theme(request) |
|
192 | 188 | form = SettingsForm(initial={'theme': selected_theme}) |
|
193 | 189 | context['form'] = form |
|
194 | context['tags'] = Tag.objects.get_popular_tags() | |
|
195 | context['theme'] = _get_theme(request) | |
|
196 | 190 | |
|
197 | 191 | return render(request, 'boards/settings.html', context) |
|
198 | 192 | |
@@ -226,6 +220,19 b' def authors(request):' | |||
|
226 | 220 | return render(request, 'boards/authors.html', context) |
|
227 | 221 | |
|
228 | 222 | |
|
223 | def delete(request, post_id): | |
|
224 | user = _get_user(request) | |
|
225 | post = get_object_or_404(Post, id=post_id) | |
|
226 | ||
|
227 | if user.is_moderator(): | |
|
228 | Post.objects.delete_post(post) | |
|
229 | ||
|
230 | if NO_PARENT == post.parent: | |
|
231 | return redirect(index) | |
|
232 | else: | |
|
233 | return redirect(thread, post_id=post.parent) | |
|
234 | ||
|
235 | ||
|
229 | 236 | def you_are_banned(request): |
|
230 | 237 | context = _init_default_context(request) |
|
231 | 238 | return render(request, 'boards/banned.html', context) |
@@ -236,10 +243,35 b' def page_404(request):' | |||
|
236 | 243 | return render(request, 'boards/404.html', context) |
|
237 | 244 | |
|
238 | 245 | |
|
246 | def tag_subscribe(request, tag_name): | |
|
247 | user = _get_user(request) | |
|
248 | tag = get_object_or_404(Tag, name=tag_name) | |
|
249 | ||
|
250 | if not tag in user.fav_tags.all(): | |
|
251 | user.fav_tags.add(tag) | |
|
252 | ||
|
253 | return redirect(all_tags) | |
|
254 | ||
|
255 | ||
|
256 | def tag_unsubscribe(request, tag_name): | |
|
257 | user = _get_user(request) | |
|
258 | tag = get_object_or_404(Tag, name=tag_name) | |
|
259 | ||
|
260 | if tag in user.fav_tags.all(): | |
|
261 | user.fav_tags.remove(tag) | |
|
262 | ||
|
263 | return redirect(all_tags) | |
|
264 | ||
|
265 | ||
|
239 | 266 | def _get_theme(request): |
|
240 | 267 | """Get user's CSS theme""" |
|
241 | 268 | |
|
242 | return request.session.get('theme', neboard.settings.DEFAULT_THEME) | |
|
269 | user = _get_user(request) | |
|
270 | theme = user.get_setting('theme') | |
|
271 | if not theme: | |
|
272 | theme = neboard.settings.DEFAULT_THEME | |
|
273 | ||
|
274 | return theme | |
|
243 | 275 | |
|
244 | 276 | |
|
245 | 277 | def _get_client_ip(request): |
@@ -255,7 +287,34 b' def _init_default_context(request):' | |||
|
255 | 287 | """Create context with default values that are used in most views""" |
|
256 | 288 | |
|
257 | 289 | context = RequestContext(request) |
|
258 | context['tags'] = Tag.objects.get_popular_tags() | |
|
290 | context['user'] = _get_user(request) | |
|
291 | context['tags'] = _get_user(request).fav_tags.all() | |
|
259 | 292 | context['theme'] = _get_theme(request) |
|
260 | 293 | |
|
261 | 294 | return context |
|
295 | ||
|
296 | ||
|
297 | def _get_user(request): | |
|
298 | """Get current user from the session""" | |
|
299 | ||
|
300 | session = request.session | |
|
301 | if not 'user_id' in session: | |
|
302 | request.session.save() | |
|
303 | ||
|
304 | md5 = hashlib.md5() | |
|
305 | md5.update(session.session_key) | |
|
306 | new_id = md5.hexdigest() | |
|
307 | ||
|
308 | time_now = timezone.now() | |
|
309 | user = User.objects.create(user_id=new_id, rank=RANK_USER, | |
|
310 | registration_time=time_now, | |
|
311 | last_access_time=time_now) | |
|
312 | ||
|
313 | session['user_id'] = user.id | |
|
314 | else: | |
|
315 | user = User.objects.get(id=session['user_id']) | |
|
316 | user.save() | |
|
317 | ||
|
318 | user.last_access_time = timezone.now() | |
|
319 | ||
|
320 | return user |
@@ -188,13 +188,14 b" SITE_NAME = 'Neboard'" | |||
|
188 | 188 | |
|
189 | 189 | THEMES = [ |
|
190 | 190 | ('md', 'Mystic Dark'), |
|
191 |
('sw', 'Snow White') |
|
|
191 | ('sw', 'Snow White') | |
|
192 | ] | |
|
192 | 193 | |
|
193 | 194 | DEFAULT_THEME = 'md' |
|
194 | 195 | |
|
195 | 196 | POPULAR_TAGS = 10 |
|
196 | 197 | LAST_REPLIES_COUNT = 3 |
|
197 | 198 | |
|
198 |
ENABLE_CAPTCHA = |
|
|
199 | ENABLE_CAPTCHA = False | |
|
199 | 200 | # if user tries to post before CAPTCHA_DEFAULT_SAFE_TIME. Captcha will be shown |
|
200 | 201 | CAPTCHA_DEFAULT_SAFE_TIME = 30 # seconds |
General Comments 0
You need to be logged in to leave comments.
Login now