##// END OF EJS Templates
Count total files size in a post instead of per-file basis
neko259 -
r1983:1ad01970 default
parent child Browse files
Show More
@@ -17,7 +17,7 b' PowDifficulty = 0'
17 17 PostingDelay = 30
18 18 Autoban = false
19 19 DefaultTag = test
20 MaxFileCount = 1
20 MaxFileCount = 5
21 21 AdditionalSpoilerSpaces = false
22 22
23 23 [Messages]
@@ -320,14 +320,19 b' class PostForm(NeboardForm):'
320 320 raise forms.ValidationError(
321 321 ungettext_lazy(ERROR_MANY_FILES, ERROR_MANY_FILES,
322 322 max_file_count) % {'files': max_file_count})
323
324 size = 0
323 325 for file_input in inputs:
324 326 if isinstance(file_input, UploadedFile):
325 files.append(self._clean_file_file(file_input))
327 file = self._clean_file_file(file_input)
328 size += file.size
329 files.append(file)
326 330 else:
327 331 files.append(self._clean_file_url(file_input))
328 332
329 333 for file in files:
330 334 self._validate_image_dimensions(file)
335 validate_file_size(size)
331 336
332 337 return files
333 338
@@ -342,7 +347,6 b' class PostForm(NeboardForm):'
342 347 raise forms.ValidationError('Possible decompression bomb or large image.')
343 348
344 349 def _clean_file_file(self, file):
345 validate_file_size(file.size)
346 350 self._update_file_extension(file)
347 351
348 352 return file
@@ -367,8 +371,6 b' class PostForm(NeboardForm):'
367 371 file = self._get_file_from_url(url)
368 372 if not file:
369 373 raise forms.ValidationError(_('Invalid URL'))
370 else:
371 validate_file_size(file.size)
372 374 self._update_file_extension(file)
373 375 except forms.ValidationError as e:
374 376 # Assume we will get the plain URL instead of a file and save it
1 NO CONTENT: modified file, binary diff hidden
@@ -480,8 +480,8 b' msgstr "\xd0\x9e\xd0\xba"'
480 480
481 481 #: utils.py:120
482 482 #, python-format
483 msgid "File must be less than %s but is %s."
484 msgstr "Файл должен быть менее %s, но его размер %s."
483 msgid "Total file size must be less than %s but is %s."
484 msgstr "Общий размер файлов должен быть менее %s, но является %s."
485 485
486 486 msgid "Please wait %(delay)d second before sending message"
487 487 msgid_plural "Please wait %(delay)d seconds before sending message"
@@ -493,8 +493,8 b' msgid "New threads"'
493 493 msgstr "Новые темы"
494 494
495 495 #, python-format
496 msgid "Max file size is %(size)s."
497 msgstr "Максимальный размер файла %(size)s."
496 msgid "Max total file size is %(size)s."
497 msgstr "Максимальный общий размер файлов %(size)s."
498 498
499 499 msgid "Size of media:"
500 500 msgstr "Размер медиа:"
1 NO CONTENT: modified file, binary diff hidden
@@ -480,8 +480,8 b' msgstr "\xd0\xa4\xd0\xb0\xd0\xb9\xd0\xbd\xd0\xbe"'
480 480
481 481 #: utils.py:120
482 482 #, python-format
483 msgid "File must be less than %s but is %s."
484 msgstr "Файл мусить бути менше %s, але його розмір %s."
483 msgid "Total file size must be less than %s but is %s."
484 msgstr "Загальний розмір файлів мусить бути менше %s, але є %s."
485 485
486 486 msgid "Please wait %(delay)d second before sending message"
487 487 msgid_plural "Please wait %(delay)d seconds before sending message"
@@ -493,8 +493,8 b' msgid "New threads"'
493 493 msgstr "Нові нитки"
494 494
495 495 #, python-format
496 msgid "Max file size is %(size)s."
497 msgstr "Максимальний розмір файлу %(size)s."
496 msgid "Max total file size is %(size)s."
497 msgstr "Максимальний загальний розмір файлів %(size)s."
498 498
499 499 msgid "Size of media:"
500 500 msgstr "Розмір посередника:"
@@ -172,7 +172,7 b''
172 172 <div>
173 173 {% trans 'Tags must be delimited by spaces. Text or image is required.' %}
174 174 {% with size=max_file_size|filesizeformat %}
175 {% blocktrans %}Max file size is {{ size }}.{% endblocktrans %}
175 {% blocktrans %}Max total file size is {{ size }}.{% endblocktrans %}
176 176 {% endwith %}
177 177 {% blocktrans %}Max file number is {{ max_files }}.{% endblocktrans %}
178 178 </div>
@@ -60,7 +60,7 b''
60 60 <div id="preview-text"></div>
61 61 <div>
62 62 {% with size=max_file_size|filesizeformat %}
63 {% blocktrans %}Max file size is {{ size }}.{% endblocktrans %}
63 {% blocktrans %}Max total file size is {{ size }}.{% endblocktrans %}
64 64 {% endwith %}
65 65 {% blocktrans %}Max file number is {{ max_files }}.{% endblocktrans %}
66 66 </div>
@@ -102,7 +102,7 b' def validate_file_size(size: int):'
102 102 max_size = boards.settings.get_int('Forms', 'MaxFileSize')
103 103 if 0 < max_size < size:
104 104 raise forms.ValidationError(
105 _('File must be less than %s but is %s.')
105 _('Total file size must be less than %s but is %s.')
106 106 % (filesizeformat(max_size), filesizeformat(size)))
107 107
108 108
General Comments 0
You need to be logged in to leave comments. Login now