diff --git a/boards/forms.py b/boards/forms.py --- a/boards/forms.py +++ b/boards/forms.py @@ -47,6 +47,7 @@ LABEL_TITLE = _('Title') LABEL_TEXT = _('Text') LABEL_TAG = _('Tag') LABEL_SEARCH = _('Search') +LABEL_FILE = _('File') ERROR_SPEED = 'Please wait %(delay)d second before sending message' ERROR_SPEED_PLURAL = 'Please wait %(delay)d seconds before sending message' @@ -169,7 +170,8 @@ class PostForm(NeboardForm): ATTRIBUTE_ROWS: TEXTAREA_ROWS, }), required=False, label=LABEL_TEXT) - file = UrlFileField(required=False, label=_('File')) + 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'), @@ -217,9 +219,13 @@ class PostForm(NeboardForm): 'characters') % str(max_length)) return text - def clean_file(self): - file = self.cleaned_data['file'] + def clean_file_1(self): + return self._clean_file(self.cleaned_data['file_1']) + 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: @@ -233,7 +239,6 @@ class PostForm(NeboardForm): return file - def _clean_file_url(self, url): file = None @@ -297,18 +302,30 @@ class PostForm(NeboardForm): Gets file from form or URL. """ - file = self.cleaned_data['file'] - if isinstance(file, UploadedFile): - return [file] - else: - return [] + cleaned_files = [ + self.cleaned_data['file_1'], + self.cleaned_data['file_2'], + ] + + files = [] + for file in cleaned_files: + if isinstance(file, UploadedFile): + files.append(file) + + return files def get_file_urls(self): - file = self.cleaned_data['file'] - if type(file) == str: - return [file] - else: - return [] + cleaned_files = [ + self.cleaned_data['file_1'], + self.cleaned_data['file_2'], + ] + + files = [] + for file in cleaned_files: + if type(file) == str: + files.append(file) + + return files def get_tripcode(self): title = self.cleaned_data['title']