##// END OF EJS Templates
Added timezone support (time zone is selected in settings)
neko259 -
r1065:eb6bb3e8 default
parent child Browse files
Show More
@@ -1,5 +1,6 b''
1 1 import re
2 2 import time
3 import pytz
3 4
4 5 from django import forms
5 6 from django.core.files.uploadedfile import SimpleUploadedFile
@@ -47,6 +48,13 b' HTTP_RESULT_OK = 200'
47 48 TEXTAREA_ROWS = 4
48 49
49 50
51 def get_timezones():
52 timezones = []
53 for tz in pytz.common_timezones:
54 timezones.append((tz, tz),)
55 return timezones
56
57
50 58 class FormatPanel(forms.Textarea):
51 59 """
52 60 Panel for text formatting. Consists of buttons to add different tags to the
@@ -321,9 +329,9 b' class ThreadForm(PostForm):'
321 329
322 330 class SettingsForm(NeboardForm):
323 331
324 theme = forms.ChoiceField(choices=settings.THEMES,
325 label=_('Theme'))
332 theme = forms.ChoiceField(choices=settings.THEMES, label=_('Theme'))
326 333 username = forms.CharField(label=_('User name'), required=False)
334 timezone = forms.ChoiceField(choices=get_timezones(), label=_('Time zone'))
327 335
328 336 def clean_username(self):
329 337 username = self.cleaned_data['username']
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: 2015-03-29 16:19+0300\n"
10 "POT-Creation-Date: 2015-03-30 18:42+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"
@@ -38,93 +38,97 b' msgstr "\xd1\x80\xd0\xb0\xd0\xb7\xd1\x80\xd0\xb0\xd0\xb1\xd0\xbe\xd1\x82\xd1\x87\xd0\xb8\xd0\xba javascript"'
38 38 msgid "designer"
39 39 msgstr "дизайнер"
40 40
41 #: forms.py:33
41 #: forms.py:34
42 42 msgid "Type message here. Use formatting panel for more advanced usage."
43 43 msgstr ""
44 44 "Вводите сообщение сюда. Используйте панель для более сложного форматирования."
45 45
46 #: forms.py:34
46 #: forms.py:35
47 47 msgid "tag1 several_words_tag"
48 48 msgstr "метка1 метка_из_нескольких_слов"
49 49
50 #: forms.py:36
50 #: forms.py:37
51 51 msgid "Title"
52 52 msgstr "Заголовок"
53 53
54 #: forms.py:37
54 #: forms.py:38
55 55 msgid "Text"
56 56 msgstr "Текст"
57 57
58 #: forms.py:38
58 #: forms.py:39
59 59 msgid "Tag"
60 60 msgstr "Метка"
61 61
62 #: forms.py:39 templates/boards/base.html:36 templates/search/search.html:13
62 #: forms.py:40 templates/boards/base.html:36 templates/search/search.html:13
63 63 #: templates/search/search.html.py:17
64 64 msgid "Search"
65 65 msgstr "Поиск"
66 66
67 #: forms.py:131
67 #: forms.py:139
68 68 msgid "Image"
69 69 msgstr "Изображение"
70 70
71 #: forms.py:134
71 #: forms.py:142
72 72 msgid "Image URL"
73 73 msgstr "URL изображения"
74 74
75 #: forms.py:140
75 #: forms.py:148
76 76 msgid "e-mail"
77 77 msgstr ""
78 78
79 #: forms.py:151
79 #: forms.py:159
80 80 #, python-format
81 81 msgid "Title must have less than %s characters"
82 82 msgstr "Заголовок должен иметь меньше %s символов"
83 83
84 #: forms.py:160
84 #: forms.py:168
85 85 #, python-format
86 86 msgid "Text must have less than %s characters"
87 87 msgstr "Текст должен быть короче %s символов"
88 88
89 #: forms.py:182
89 #: forms.py:190
90 90 msgid "Invalid URL"
91 91 msgstr "Неверный URL"
92 92
93 #: forms.py:219
93 #: forms.py:227
94 94 msgid "Either text or image must be entered."
95 95 msgstr "Текст или картинка должны быть введены."
96 96
97 #: forms.py:235
97 #: forms.py:243
98 98 #, python-format
99 99 msgid "Wait %s seconds after last posting"
100 100 msgstr "Подождите %s секунд после последнего постинга"
101 101
102 #: forms.py:247
102 #: forms.py:255
103 103 #, python-format
104 104 msgid "Image must be less than %s bytes"
105 105 msgstr "Изображение должно быть менее %s байт"
106 106
107 #: forms.py:294 templates/boards/rss/post.html:10 templates/boards/tags.html:7
107 #: forms.py:302 templates/boards/rss/post.html:10 templates/boards/tags.html:7
108 108 msgid "Tags"
109 109 msgstr "Метки"
110 110
111 #: forms.py:301
111 #: forms.py:309
112 112 msgid "Inappropriate characters in tags."
113 113 msgstr "Недопустимые символы в метках."
114 114
115 #: forms.py:312
115 #: forms.py:320
116 116 msgid "Need at least 1 required tag."
117 117 msgstr "Нужна хотя бы 1 обязательная метка."
118 118
119 #: forms.py:325
119 #: forms.py:332
120 120 msgid "Theme"
121 121 msgstr "Тема"
122 122
123 #: forms.py:326
123 #: forms.py:333
124 124 msgid "User name"
125 125 msgstr "Имя пользователя"
126 126
127 #: forms.py:332
127 #: forms.py:334
128 msgid "Time zone"
129 msgstr "Часовой пояс"
130
131 #: forms.py:340
128 132 msgid "Inappropriate characters."
129 133 msgstr "Недопустимые символы."
130 134
@@ -169,7 +173,7 b' msgstr "\xd0\xa3\xd0\xbf\xd1\x80\xd0\xb0\xd0\xb2\xd0\xbb\xd0\xb5\xd0\xbd\xd0\xb8\xd0\xb5 \xd0\xbc\xd0\xb5\xd1\x82\xd0\xba\xd0\xb0\xd0\xbc\xd0\xb8"'
169 173 msgid "Notifications"
170 174 msgstr "Уведомления"
171 175
172 #: templates/boards/base.html:47 templates/boards/settings.html:8
176 #: templates/boards/base.html:47 templates/boards/settings.html:9
173 177 msgid "Settings"
174 178 msgstr "Настройки"
175 179
@@ -187,12 +191,12 b' msgid "Up"'
187 191 msgstr "Вверх"
188 192
189 193 #: templates/boards/notifications.html:17
190 #: templates/boards/posting_general.html:79 templates/search/search.html:26
194 #: templates/boards/posting_general.html:81 templates/search/search.html:26
191 195 msgid "Previous page"
192 196 msgstr "Предыдущая страница"
193 197
194 198 #: templates/boards/notifications.html:27
195 #: templates/boards/posting_general.html:119 templates/search/search.html:37
199 #: templates/boards/posting_general.html:121 templates/search/search.html:37
196 200 msgid "Next page"
197 201 msgstr "Следующая страница"
198 202
@@ -216,52 +220,52 b' msgstr "\xd0\x98\xd0\xb7\xd0\xbc\xd0\xb5\xd0\xbd\xd0\xb8\xd1\x82\xd1\x8c \xd1\x82\xd0\xb5\xd0\xbc\xd1\x83"'
216 220 msgid "Replies"
217 221 msgstr "Ответы"
218 222
219 #: templates/boards/post.html:86 templates/boards/thread.html:28
223 #: templates/boards/post.html:86 templates/boards/thread.html:30
220 224 msgid "messages"
221 225 msgstr "сообщений"
222 226
223 #: templates/boards/post.html:87 templates/boards/thread.html:29
227 #: templates/boards/post.html:87 templates/boards/thread.html:31
224 228 msgid "images"
225 229 msgstr "изображений"
226 230
227 #: templates/boards/posting_general.html:63
231 #: templates/boards/posting_general.html:65
228 232 msgid "Edit tag"
229 233 msgstr "Изменить метку"
230 234
231 #: templates/boards/posting_general.html:66
235 #: templates/boards/posting_general.html:68
232 236 #, python-format
233 237 msgid "This tag has %(thread_count)s threads and %(post_count)s posts."
234 238 msgstr "С этой меткой есть %(thread_count)s тем и %(post_count)s сообщений."
235 239
236 #: templates/boards/posting_general.html:94
240 #: templates/boards/posting_general.html:96
237 241 #, python-format
238 242 msgid "Skipped %(count)s replies. Open thread to see all replies."
239 243 msgstr "Пропущено %(count)s ответов. Откройте тред, чтобы увидеть все ответы."
240 244
241 #: templates/boards/posting_general.html:124
245 #: templates/boards/posting_general.html:126
242 246 msgid "No threads exist. Create the first one!"
243 247 msgstr "Нет тем. Создайте первую!"
244 248
245 #: templates/boards/posting_general.html:130
249 #: templates/boards/posting_general.html:132
246 250 msgid "Create new thread"
247 251 msgstr "Создать новую тему"
248 252
249 #: templates/boards/posting_general.html:135 templates/boards/preview.html:16
250 #: templates/boards/thread_normal.html:44
253 #: templates/boards/posting_general.html:137 templates/boards/preview.html:16
254 #: templates/boards/thread_normal.html:46
251 255 msgid "Post"
252 256 msgstr "Отправить"
253 257
254 #: templates/boards/posting_general.html:141
258 #: templates/boards/posting_general.html:143
255 259 msgid "Tags must be delimited by spaces. Text or image is required."
256 260 msgstr ""
257 261 "Метки должны быть разделены пробелами. Текст или изображение обязательны."
258 262
259 #: templates/boards/posting_general.html:144
260 #: templates/boards/thread_normal.html:50
263 #: templates/boards/posting_general.html:146
264 #: templates/boards/thread_normal.html:51
261 265 msgid "Text syntax"
262 266 msgstr "Синтаксис текста"
263 267
264 #: templates/boards/posting_general.html:156
268 #: templates/boards/posting_general.html:158
265 269 msgid "Pages:"
266 270 msgstr "Страницы: "
267 271
@@ -273,19 +277,19 b' msgstr "\xd0\x9f\xd1\x80\xd0\xb5\xd0\xb4\xd0\xbf\xd1\x80\xd0\xbe\xd1\x81\xd0\xbc\xd0\xbe\xd1\x82\xd1\x80"'
273 277 msgid "Post image"
274 278 msgstr "Изображение сообщения"
275 279
276 #: templates/boards/settings.html:16
280 #: templates/boards/settings.html:17
277 281 msgid "You are moderator."
278 282 msgstr "Вы модератор."
279 283
280 #: templates/boards/settings.html:20
284 #: templates/boards/settings.html:21
281 285 msgid "Hidden tags:"
282 286 msgstr "Скрытые метки:"
283 287
284 #: templates/boards/settings.html:28
288 #: templates/boards/settings.html:29
285 289 msgid "No hidden tags."
286 290 msgstr "Нет скрытых меток."
287 291
288 #: templates/boards/settings.html:37
292 #: templates/boards/settings.html:38
289 293 msgid "Save"
290 294 msgstr "Сохранить"
291 295
@@ -342,36 +346,36 b' msgstr "\xd0\x92\xd1\x8b \xd0\xbc\xd0\xbe\xd0\xb6\xd0\xb5\xd1\x82\xd0\xb5 \xd0\xbf\xd0\xbe\xd0\xbf\xd1\x80\xd0\xbe\xd0\xb1\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x82\xd1\x8c \xd0\xb2\xd1\x81\xd1\x82\xd0\xb0\xd0\xb2\xd0\xb8\xd1\x82\xd1\x8c \xd1\x82\xd0\xb5\xd0\xba\xd1\x81\xd1\x82 \xd0\xb8 \xd0\xbf\xd1\x80\xd0\xbe\xd0\xb2\xd0\xb5\xd1\x80\xd0\xb8\xd1\x82\xd1\x8c \xd1\x80\xd0\xb5\xd0\xb7\xd1\x83\xd0\xbb\xd1\x8c\xd1\x82\xd0\xb0\xd1\x82 \xd0\xb7\xd0\xb4\xd0\xb5\xd1\x81\xd1\x8c:"'
342 346 msgid "No tags found."
343 347 msgstr "Метки не найдены."
344 348
345 #: templates/boards/thread.html:30
349 #: templates/boards/thread.html:32
346 350 msgid "Last update: "
347 351 msgstr "Последнее обновление: "
348 352
349 #: templates/boards/thread_gallery.html:20
350 #: templates/boards/thread_normal.html:14
353 #: templates/boards/thread_gallery.html:21
354 #: templates/boards/thread_normal.html:16
351 355 msgid "Normal mode"
352 356 msgstr "Нормальный режим"
353 357
354 #: templates/boards/thread_gallery.html:21
355 #: templates/boards/thread_normal.html:15
358 #: templates/boards/thread_gallery.html:22
359 #: templates/boards/thread_normal.html:17
356 360 msgid "Gallery mode"
357 361 msgstr "Режим галереи"
358 362
359 #: templates/boards/thread_gallery.html:51
363 #: templates/boards/thread_gallery.html:52
360 364 msgid "No images."
361 365 msgstr "Нет изображений."
362 366
363 #: templates/boards/thread_normal.html:23
367 #: templates/boards/thread_normal.html:25
364 368 msgid "posts to bumplimit"
365 369 msgstr "сообщений до бамплимита"
366 370
367 #: templates/boards/thread_normal.html:37
371 #: templates/boards/thread_normal.html:39
368 372 msgid "Reply to thread"
369 373 msgstr "Ответить в тему"
370 374
371 #: templates/boards/thread_normal.html:51
375 #: templates/boards/thread_normal.html:52
372 376 msgid "Close form"
373 377 msgstr "Закрыть форму"
374 378
375 #: templates/boards/thread_normal.html:67
379 #: templates/boards/thread_normal.html:68
376 380 msgid "Update"
377 381 msgstr "Обновить"
@@ -1,4 +1,8 b''
1 import pytz
2
1 3 from django.shortcuts import redirect
4 from django.utils import timezone
5
2 6 from boards import utils
3 7 from boards.models import Ban
4 8
@@ -26,3 +30,13 b' class BanMiddleware:'
26 30 ban = bans[0]
27 31 if not ban.can_read:
28 32 return redirect('banned')
33
34
35 class TimezoneMiddleware(object):
36 def process_request(self, request):
37 tzname = request.session.get('django_timezone')
38 if tzname:
39 timezone.activate(pytz.timezone(tzname))
40 else:
41 timezone.deactivate()
42
@@ -23,17 +23,6 b''
23 23 for the JavaScript code in this page.
24 24 */
25 25
26 if (window.Intl) {
27 var LOCALE = window.navigator.language;
28 var FORMATTER = new Intl.DateTimeFormat(
29 LOCALE,
30 {
31 weekday: 'short', year: 'numeric', month: 'short', day: 'numeric',
32 hour: 'numeric', minute: '2-digit', second: '2-digit'
33 }
34 );
35 }
36
37 26 /**
38 27 * An email is a hidden file to prevent spam bots from posting. It has to be
39 28 * hidden.
@@ -51,36 +40,6 b' function highlightCode(node) {'
51 40 });
52 41 }
53 42
54 /**
55 * Translate timestamps to local ones for all <time> tags inside node.
56 */
57 function translate_time(node) {
58 if (window.Intl === null) {
59 return;
60 }
61
62 var elements;
63
64 if (node === null) {
65 elements = $('time');
66 } else {
67 elements = node.find('time');
68 }
69
70 if (!elements.length) {
71 return;
72 }
73
74 elements.each(function() {
75 var element = $(this);
76 var dateAttr = element.attr('datetime');
77 if (dateAttr) {
78 var date = new Date(dateAttr);
79 element.text(FORMATTER.format(date));
80 }
81 });
82 }
83
84 43 $( document ).ready(function() {
85 44 hideEmailFromForm();
86 45
@@ -94,6 +53,4 b' function translate_time(node) {'
94 53 addRefLinkPreview();
95 54
96 55 highlightCode($(document));
97
98 translate_time(null);
99 56 });
@@ -20,7 +20,6 b' function mkPreview(cln, html) {'
20 20
21 21 highlightCode($(cln));
22 22 addRefLinkPreview(cln);
23 translate_time($(cln));
24 23 };
25 24
26 25 function isElementInViewport (el) {
@@ -196,7 +196,6 b' function updateMetadataPanel(lastUpdate)'
196 196 if (lastUpdate !== '') {
197 197 var lastUpdateField = $('#last-update');
198 198 lastUpdateField.html(lastUpdate);
199 translate_time(lastUpdateField);
200 199 blink(lastUpdateField);
201 200 }
202 201
@@ -305,7 +304,6 b' function showAsErrors(form, text) {'
305 304 function processNewPost(post) {
306 305 addRefLinkPreview(post[0]);
307 306 highlightCode(post);
308 translate_time(post);
309 307 blink(post);
310 308 }
311 309
@@ -4,6 +4,7 b''
4 4 {% load cache %}
5 5 {% load board %}
6 6 {% load static %}
7 {% load tz %}
7 8
8 9 {% block head %}
9 10 <meta name="robots" content="noindex">
@@ -38,6 +39,7 b''
38 39 {% block content %}
39 40
40 41 {% get_current_language as LANGUAGE_CODE %}
42 {% get_current_timezone as TIME_ZONE %}
41 43
42 44 {% if tag %}
43 45 <div class="tag_info">
@@ -81,7 +83,7 b''
81 83 {% endif %}
82 84
83 85 {% for thread in threads %}
84 {% cache 600 thread_short thread.id thread.last_edit_time moderator LANGUAGE_CODE %}
86 {% cache 600 thread_short thread.id thread.last_edit_time moderator LANGUAGE_CODE TIME_ZONE %}
85 87 <div class="thread">
86 88 {% post_view thread.get_opening_post moderator is_opening=True thread=thread truncated=True need_open_link=True %}
87 89 {% if not thread.archived %}
@@ -2,6 +2,7 b''
2 2
3 3 {% load i18n %}
4 4 {% load humanize %}
5 {% load tz %}
5 6
6 7 {% block head %}
7 8 <meta name="robots" content="noindex">
@@ -4,6 +4,7 b''
4 4 {% load cache %}
5 5 {% load static from staticfiles %}
6 6 {% load board %}
7 {% load tz %}
7 8
8 9 {% block head %}
9 10 <title>{{ opening_post.get_title|striptags|truncatewords:10 }}
@@ -13,6 +14,7 b''
13 14 {% block metapanel %}
14 15
15 16 {% get_current_language as LANGUAGE_CODE %}
17 {% get_current_timezone as TIME_ZONE %}
16 18
17 19 <span class="metapanel"
18 20 data-last-update="{{ last_update }}"
@@ -24,7 +26,7 b''
24 26 {% block thread_meta_panel %}
25 27 {% endblock %}
26 28
27 {% cache 600 thread_meta thread.last_edit_time moderator LANGUAGE_CODE %}
29 {% cache 600 thread_meta thread.last_edit_time moderator LANGUAGE_CODE TIME_ZONE %}
28 30 <span id="reply-count">{{ thread.get_reply_count }}</span>{% if thread.has_post_limit %}/{{ thread.max_posts }}{% endif %} {% trans 'messages' %},
29 31 <span id="image-count">{{ thread.get_images_count }}</span> {% trans 'images' %}.
30 32 {% trans 'Last update: ' %}<span id="last-update"><time datetime="{{ thread.last_edit_time|date:'c' }}">{{ thread.last_edit_time|date:'r' }}</time></span>
@@ -4,6 +4,7 b''
4 4 {% load cache %}
5 5 {% load static from staticfiles %}
6 6 {% load board %}
7 {% load tz %}
7 8
8 9 {% block head %}
9 10 <meta name="robots" content="noindex">
@@ -12,10 +13,10 b''
12 13 {% endblock %}
13 14
14 15 {% block content %}
15 {% spaceless %}
16 16 {% get_current_language as LANGUAGE_CODE %}
17 {% get_current_timezone as TIME_ZONE %}
17 18
18 {% cache 600 thread_gallery_view thread.id thread.last_edit_time LANGUAGE_CODE request.get_host %}
19 {% cache 600 thread_gallery_view thread.id thread.last_edit_time LANGUAGE_CODE request.get_host TIME_ZONE %}
19 20 <div class="image-mode-tab">
20 21 <a href="{% url 'thread' thread.get_opening_post.id %}">{% trans 'Normal mode' %}</a>,
21 22 <a class="current_mode" href="{% url 'thread_gallery' thread.get_opening_post.id %}">{% trans 'Gallery mode' %}</a>
@@ -52,6 +53,4 b''
52 53 {% endif %}
53 54 </div>
54 55 {% endcache %}
55
56 {% endspaceless %}
57 56 {% endblock %}
@@ -4,11 +4,13 b''
4 4 {% load cache %}
5 5 {% load static from staticfiles %}
6 6 {% load board %}
7 {% load tz %}
7 8
8 9 {% block content %}
9 10 {% get_current_language as LANGUAGE_CODE %}
11 {% get_current_timezone as TIME_ZONE %}
10 12
11 {% cache 600 thread_view thread.id thread.last_edit_time moderator LANGUAGE_CODE %}
13 {% cache 600 thread_view thread.id thread.last_edit_time moderator LANGUAGE_CODE TIME_ZONE %}
12 14
13 15 <div class="image-mode-tab">
14 16 <a class="current_mode" href="{% url 'thread' opening_post.id %}">{% trans 'Normal mode' %}</a>,
@@ -1,5 +1,8 b''
1 import pytz
2
1 3 from django.db import transaction
2 4 from django.shortcuts import render, redirect
5 from django.utils import timezone
3 6
4 7 from boards.abstracts.settingsmanager import get_settings_manager, \
5 8 SETTING_USERNAME, SETTING_LAST_NOTIFICATION_ID
@@ -8,6 +11,7 b' from boards.forms import SettingsForm, P'
8 11
9 12 FORM_THEME = 'theme'
10 13 FORM_USERNAME = 'username'
14 FORM_TIMEZONE = 'timezone'
11 15
12 16 CONTEXT_HIDDEN_TAGS = 'hidden_tags'
13 17
@@ -25,7 +29,9 b' class SettingsView(BaseBoardView):'
25 29 form = SettingsForm(
26 30 initial={
27 31 FORM_THEME: selected_theme,
28 FORM_USERNAME: settings_manager.get_setting(SETTING_USERNAME)},
32 FORM_USERNAME: settings_manager.get_setting(SETTING_USERNAME),
33 FORM_TIMEZONE: request.session.get('django_timezone', timezone.get_current_timezone()),
34 },
29 35 error_class=PlainErrorList)
30 36
31 37 params[CONTEXT_FORM] = form
@@ -50,6 +56,8 b' class SettingsView(BaseBoardView):'
50 56 settings_manager.set_setting(SETTING_USERNAME, username)
51 57 settings_manager.set_setting(SETTING_LAST_NOTIFICATION_ID, None)
52 58
59 request.session['django_timezone'] = form.cleaned_data[FORM_TIMEZONE]
60
53 61 return redirect('settings')
54 62 else:
55 63 params = dict()
@@ -116,6 +116,7 b' MIDDLEWARE_CLASSES = ('
116 116 'django.contrib.auth.middleware.AuthenticationMiddleware',
117 117 'django.contrib.messages.middleware.MessageMiddleware',
118 118 'boards.middlewares.BanMiddleware',
119 'boards.middlewares.TimezoneMiddleware',
119 120 )
120 121
121 122 ROOT_URLCONF = 'neboard.urls'
General Comments 0
You need to be logged in to leave comments. Login now