##// END OF EJS Templates
3 modes of downloading urls to a form instead of 2
neko259 -
r1916:ce53df59 default
parent child Browse files
Show More
@@ -83,6 +83,10 b' MIMETYPE_EXTENSIONS = {'
83 83 'image/bmp': 'bmp',
84 84 }
85 85
86 DOWN_MODE_DOWNLOAD = 'DOWNLOAD'
87 DOWN_MODE_URL = 'URL'
88 DOWN_MODE_TRY = 'TRY'
89
86 90
87 91 logger = logging.getLogger('boards.forms')
88 92
@@ -180,7 +184,14 b' class PostForm(NeboardForm):'
180 184 ATTRIBUTE_ROWS: TEXTAREA_ROWS,
181 185 }),
182 186 required=False, label=LABEL_TEXT)
183 no_download = forms.BooleanField(required=False, label=LABEL_URL)
187 download_mode = forms.ChoiceField(
188 choices=(
189 (DOWN_MODE_TRY, _('Download if possible')),
190 (DOWN_MODE_DOWNLOAD, _('Download')),
191 (DOWN_MODE_URL, _('Insert as URLs')),
192 ),
193 initial=DOWN_MODE_TRY,
194 label=_('URL download mode'))
184 195 file = UrlFileField(required=False, label=LABEL_FILE)
185 196
186 197 # This field is for spam prevention only
@@ -347,7 +358,8 b' class PostForm(NeboardForm):'
347 358 file = None
348 359
349 360 if url:
350 if self.cleaned_data['no_download']:
361 mode = self.cleaned_data['download_mode']
362 if mode == DOWN_MODE_URL:
351 363 return url
352 364
353 365 try:
@@ -366,7 +378,7 b' class PostForm(NeboardForm):'
366 378 self._update_file_extension(file)
367 379 except forms.ValidationError as e:
368 380 # Assume we will get the plain URL instead of a file and save it
369 if REGEX_URL.match(url) or REGEX_MAGNET.match(url):
381 if mode == DOWN_MODE_TRY and (REGEX_URL.match(url) or REGEX_MAGNET.match(url)):
370 382 logger.info('Error in forms: {}'.format(e))
371 383 return url
372 384 else:
1 NO CONTENT: modified file, binary diff hidden
@@ -599,3 +599,14 b' msgstr "\xd0\x92\xd1\x8b \xd1\x83\xd0\xb2\xd0\xb5\xd1\x80\xd0\xb5\xd0\xbd\xd1\x8b?"'
599 599 msgid "Ban"
600 600 msgstr "Забанить"
601 601
602 msgid "URL download mode"
603 msgstr "Режим загрузки ссылок"
604
605 msgid "Download if possible"
606 msgstr "Загружать если возможно"
607
608 msgid "Download"
609 msgstr "Загружать"
610
611 msgid "Insert as URLs"
612 msgstr "Вставлять как ссылки"
1 NO CONTENT: modified file, binary diff hidden
@@ -599,3 +599,14 b' msgstr "\xd0\xa7\xd0\xb8 \xd0\xb2\xd0\xb8 \xd0\xbf\xd0\xb5\xd0\xb2\xd0\xbd\xd1\x96?"'
599 599 msgid "Ban"
600 600 msgstr "Заблокувати"
601 601
602 msgid "URL download mode"
603 msgstr "Режим завантаження посилань"
604
605 msgid "Download if possible"
606 msgstr "Завантажувати якщо можливо"
607
608 msgid "Download"
609 msgstr "Завантажувати"
610
611 msgid "Insert as URLs"
612 msgstr "Вставляти як посилання"
@@ -43,7 +43,7 b' function getForm() {'
43 43 function resetForm() {
44 44 var form = getForm();
45 45
46 form.find('input:text, input:password, input:file, select, textarea').val('');
46 form.find('input:text, input:password, input:file, textarea').val('');
47 47 form.find('input:radio, input:checkbox').removeAttr('checked').removeAttr('selected');
48 48 $('.file_wrap').find('.file-thumb').remove();
49 49 $('#preview-text').hide();
General Comments 0
You need to be logged in to leave comments. Login now