From 928d3bd8b196681ef328cc1c2612c6ed31c396ec Mon Sep 17 00:00:00 2001 From: Gustavo Date: Tue, 15 Aug 2017 12:20:49 -0300 Subject: [PATCH] Modified bulletin form to include the new field --- bulletin/forms.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/bulletin/forms.py b/bulletin/forms.py index 3ef48a5..cabcf7f 100644 --- a/bulletin/forms.py +++ b/bulletin/forms.py @@ -31,7 +31,7 @@ class BulletinForm(forms.ModelForm): class Meta: model = Bulletin - fields = ['name', 'content', 'brief_description', 'show_window', 'visible','file_content'] + fields = ['name', 'content', 'brief_description', 'show_window', 'visible','file_content','indicators'] labels = { 'name': _('Bulletin name'), 'content': _('Bulletin content'), @@ -77,6 +77,23 @@ class BulletinForm(forms.ModelForm): return file_content + def clean_indicators(self): + indicators = self.cleaned_data.get('indicators', False) + + if indicators: + if hasattr(indicators, '_size'): + if indicators._size > self.MAX_UPLOAD_SIZE: + self._errors['indicators'] = [_("The file is too large. It should have less than 1MB.")] + + return ValueError + + elif not self.instance.pk: + self._errors['indicators'] = [_('This field is required.')] + + return ValueError + + return indicators + def save(self, commit = True): super(BulletinForm, self).save(commit = True) -- libgit2 0.21.2