##// END OF EJS Templates
Clarified url download modes
neko259 -
r1922:5728b509 default
parent child Browse files
Show More
@@ -13,6 +13,7 b' from django.core.files.uploadedfile impo'
13 13 from django.forms.utils import ErrorList
14 14 from django.utils.translation import ugettext_lazy as _, ungettext_lazy
15 15 from django.core.files.images import get_image_dimensions
16 from django.core.cache import cache
16 17
17 18 import boards.settings as board_settings
18 19 import neboard
@@ -186,8 +187,8 b' class PostForm(NeboardForm):'
186 187 required=False, label=LABEL_TEXT)
187 188 download_mode = forms.ChoiceField(
188 189 choices=(
189 (DOWN_MODE_TRY, _('Download if possible')),
190 (DOWN_MODE_DOWNLOAD, _('Download')),
190 (DOWN_MODE_TRY, _('Download or add URL')),
191 (DOWN_MODE_DOWNLOAD, _('Download or fail')),
191 192 (DOWN_MODE_URL, _('Insert as URLs')),
192 193 ),
193 194 initial=DOWN_MODE_TRY,
@@ -393,6 +394,21 b' class PostForm(NeboardForm):'
393 394 error_message = _('Either text or file must be entered.')
394 395 self._add_general_error(error_message)
395 396
397 def _get_cache_key(self, key):
398 return '{}_{}'.format(self.session.session_key, key)
399
400 def _set_session_cache(self, key, value):
401 cache.set(self._get_cache_key(key), value)
402
403 def _get_session_cache(self, key):
404 return cache.get(self._get_cache_key(key))
405
406 def _get_last_post_time(self):
407 last = self._get_session_cache(LAST_POST_TIME)
408 if last is None:
409 last = self.session.get(LAST_POST_TIME)
410 return last
411
396 412 def _validate_posting_speed(self):
397 413 can_post = True
398 414
@@ -408,11 +424,13 b' class PostForm(NeboardForm):'
408 424
409 425 need_delay = True
410 426 else:
411 last_post_time = self.session.get(LAST_POST_TIME)
427 last_post_time = self._get_last_post_time()
412 428 current_delay = int(now - last_post_time)
413 429
414 430 need_delay = current_delay < posting_delay
415 431
432 self._set_session_cache(LAST_POST_TIME, now)
433
416 434 if need_delay:
417 435 delay = posting_delay - current_delay
418 436 error_message = ungettext_lazy(ERROR_SPEED, ERROR_SPEED_PLURAL,
@@ -423,6 +441,9 b' class PostForm(NeboardForm):'
423 441
424 442 if can_post:
425 443 self.session[LAST_POST_TIME] = now
444 else:
445 # Reset the time since posting failed
446 self._set_session_cache(LAST_POST_TIME, self.session[LAST_POST_TIME])
426 447
427 448 def _get_file_from_url(self, url: str) -> SimpleUploadedFile:
428 449 """
1 NO CONTENT: modified file, binary diff hidden
@@ -602,11 +602,11 b' msgstr "\xd0\x97\xd0\xb0\xd0\xb1\xd0\xb0\xd0\xbd\xd0\xb8\xd1\x82\xd1\x8c"'
602 602 msgid "URL download mode"
603 603 msgstr "Режим загрузки ссылок"
604 604
605 msgid "Download if possible"
606 msgstr "Загружать если возможно"
605 msgid "Download or add URL"
606 msgstr "Загрузить или добавить ссылку"
607 607
608 msgid "Download"
609 msgstr "Загружать"
608 msgid "Download or fail"
609 msgstr "Загрузить или отказать"
610 610
611 611 msgid "Insert as URLs"
612 612 msgstr "Вставлять как ссылки"
1 NO CONTENT: modified file, binary diff hidden
@@ -602,11 +602,11 b' msgstr "\xd0\x97\xd0\xb0\xd0\xb1\xd0\xbb\xd0\xbe\xd0\xba\xd1\x83\xd0\xb2\xd0\xb0\xd1\x82\xd0\xb8"'
602 602 msgid "URL download mode"
603 603 msgstr "Режим завантаження посилань"
604 604
605 msgid "Download if possible"
606 msgstr "Завантажувати якщо можливо"
605 msgid "Download or add URL"
606 msgstr "Завантажити або додати посилання"
607 607
608 msgid "Download"
609 msgstr "Завантажувати"
608 msgid "Download or fail"
609 msgstr "Завантажити або відмовити"
610 610
611 611 msgid "Insert as URLs"
612 612 msgstr "Вставляти як посилання"
General Comments 0
You need to be logged in to leave comments. Login now