diff --git a/boards/forms/__init__.py b/boards/forms/__init__.py --- a/boards/forms/__init__.py +++ b/boards/forms/__init__.py @@ -45,7 +45,8 @@ LABEL_TITLE = _('Title') LABEL_TEXT = _('Text') LABEL_TAG = _('Tag') LABEL_SEARCH = _('Search') -LABEL_FILE = _('File') +LABEL_FILE_1 = _('File 1') +LABEL_FILE_2 = _('File 2') ERROR_SPEED = 'Please wait %(delay)d second before sending message' ERROR_SPEED_PLURAL = 'Please wait %(delay)d seconds before sending message' @@ -168,8 +169,8 @@ class PostForm(NeboardForm): ATTRIBUTE_ROWS: TEXTAREA_ROWS, }), required=False, label=LABEL_TEXT) - file_1 = UrlFileField(required=False, label=LABEL_FILE + ' 1') - file_2 = UrlFileField(required=False, label=LABEL_FILE + ' 2') + file_1 = UrlFileField(required=False, label=LABEL_FILE_1) + file_2 = UrlFileField(required=False, label=LABEL_FILE_2) # This field is for spam prevention only email = forms.CharField(max_length=100, required=False, label=_('e-mail'), @@ -185,20 +186,6 @@ class PostForm(NeboardForm): need_to_ban = False image = None - def _update_file_extension(self, file): - if file: - mimetype =get_file_mimetype(file) - extension = MIMETYPE_EXTENSIONS.get(mimetype) - if extension: - filename = file.name.split(FILE_EXTENSION_DELIMITER, 1)[0] - new_filename = filename + FILE_EXTENSION_DELIMITER + extension - - file.name = new_filename - else: - logger = logging.getLogger('boards.forms.extension') - - logger.info('Unrecognized file mimetype: {}'.format(mimetype)) - def clean_title(self): title = self.cleaned_data['title'] if title: @@ -223,48 +210,6 @@ class PostForm(NeboardForm): def clean_file_2(self): return self._clean_file(self.cleaned_data['file_2']) - def _clean_file(self, file): - if isinstance(file, UploadedFile): - file = self._clean_file_file(file) - else: - file = self._clean_file_url(file) - - return file - - def _clean_file_file(self, file): - validate_file_size(file.size) - self._update_file_extension(file) - - return file - - def _clean_file_url(self, url): - file = None - - if url: - try: - file = get_image_by_alias(url, self.session) - self.image = file - - if file is not None: - return - - if file is None: - file = self._get_file_from_url(url) - if not file: - raise forms.ValidationError(_('Invalid URL')) - else: - validate_file_size(file.size) - self._update_file_extension(file) - except forms.ValidationError as e: - # Assume we will get the plain URL instead of a file and save it - if REGEX_URL.match(url): - logger.info('Error in forms: {}'.format(e)) - return url - else: - raise e - - return file - def clean(self): cleaned_data = super(PostForm, self).clean() @@ -350,6 +295,60 @@ class PostForm(NeboardForm): def is_subscribe(self): return self.cleaned_data['subscribe'] + def _update_file_extension(self, file): + if file: + mimetype = get_file_mimetype(file) + extension = MIMETYPE_EXTENSIONS.get(mimetype) + if extension: + filename = file.name.split(FILE_EXTENSION_DELIMITER, 1)[0] + new_filename = filename + FILE_EXTENSION_DELIMITER + extension + + file.name = new_filename + else: + logger.info('Unrecognized file mimetype: {}'.format(mimetype)) + + def _clean_file(self, file): + if isinstance(file, UploadedFile): + file = self._clean_file_file(file) + else: + file = self._clean_file_url(file) + + return file + + def _clean_file_file(self, file): + validate_file_size(file.size) + self._update_file_extension(file) + + return file + + def _clean_file_url(self, url): + file = None + + if url: + try: + file = get_image_by_alias(url, self.session) + self.image = file + + if file is not None: + return + + if file is None: + file = self._get_file_from_url(url) + if not file: + raise forms.ValidationError(_('Invalid URL')) + else: + validate_file_size(file.size) + self._update_file_extension(file) + except forms.ValidationError as e: + # Assume we will get the plain URL instead of a file and save it + if REGEX_URL.match(url): + logger.info('Error in forms: {}'.format(e)) + return url + else: + raise e + + return file + def _clean_text_file(self): text = self.cleaned_data.get('text') file = self.get_files() @@ -404,9 +403,6 @@ class PostForm(NeboardForm): raise forms.ValidationError(e) def _validate_hash(self, timestamp: str, iteration: str, guess: str, message: str): - post_time = timezone.datetime.fromtimestamp( - int(timestamp[:-3]), tz=timezone.get_current_timezone()) - payload = timestamp + message.replace('\r\n', '\n') difficulty = board_settings.get_int('Forms', 'PowDifficulty') target = str(int(2 ** (POW_HASH_LENGTH * 3) / difficulty)) @@ -420,7 +416,6 @@ class PostForm(NeboardForm): [_('Invalid PoW.')]) - class ThreadForm(PostForm): tags = forms.CharField( diff --git a/boards/locale/ru/LC_MESSAGES/django.mo b/boards/locale/ru/LC_MESSAGES/django.mo index 0d28c0882964720772da76f1c0137e3ae3544526..cf234602dd8080368dbee794f050ab0e580fe459 GIT binary patch literal 10550 zc$~#pYiu0Xb-r#~M`1*flu}F7%a@`kQMPwQQb}yDM8~v5*-S`@CMm~G9IGSlh#YHo zW;3%(iH?(smLE!`n2BQ}fosQ>lh{8B7b{96C6c0&6ljB@C}s<{MT4ejei}YD)osT00~>&knE6itYk^~?{~6$K0MD-${oh`-#-91(z>-0kGeI|e&-r#ziW-mA6O&)c^tR_IJ!pkm@wnN25bSo z3fu|&!5XpaAI-d9tdaHK1O6KDLv>=$>N=6%P$%QJ07rq_P5)QwME;9);*ZzrM9z2X zB(9gt`_($}{~wxhKQ{e8sS`c_$;f%n$i1ar*86b1=(o0B{J*(g`djM7PqzaD;63%? zpLgm-{vXwgygxPg<9fq4;5u5TUi7MKFm?eyKz22V+|~vY&j#V~KJz{f+yVSjgZSmU z4PwW|2J!oBgXkNY_8&EfzyHR}Uj-%ZBYv+HKOb5v;~!cp`h9k-tmgs~z~5bKc(_*V z|Ct&8OM_$#$*ox@{Hj|g<2SDp{hEOv0q$NWemSsC@~;=T1^BsjvhEkmycZ0 zH#G?#b~H)*$D2g&o+erEao}Un=VX)k``vA#cWtxSwYgcww>67Dx|_wnBh9kj`DT&( z?PghTrdj;>ee?bk;920mnD_DR61Qiz3m^YryX56hx63~G^XHoJ@k+*7>;JRI6&sHGZtd8LRjFO9ZPdP>W z{FrGwV6e_$t-(7CQm&1f=LeOXGw9ln`xEAw{BR0)JNeDDJwP#2!dpt)_ZGIZJ%ZnZC!B#O;3EpU3@V znJ%>7d{Ifg8B)SGx`vgU)owBGNhN#CVe|e4B{hSt^#*&D)Q!h*AI1GS(>{j#b|p2C zu7d{m7^K=qe4?7>;iVAEgHExLUQe4tqH_yDQMvaMl^Kb#~OZtz@G!j!5# zPTCr=m%o<_P1`}RbckswA0%Q)|6{pyCgr4^?26uCX?NEWD-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C_MESSAGES/django.po +++ b/boards/locale/ru/LC_MESSAGES/django.po @@ -63,9 +63,13 @@ msgstr "Метка" msgid "Search" msgstr "Поиск" -#: forms.py:139 -msgid "File" -msgstr "Файл" +#: forms.py:48 +msgid "File 1" +msgstr "Файл 1" + +#: forms.py:48 +msgid "File 2" +msgstr "Файл 2" #: forms.py:142 msgid "File URL"