Commit 928d3bd8b196681ef328cc1c2612c6ed31c396ec
1 parent
4a8e972a
Exists in
master
and in
2 other branches
Modified bulletin form to include the new field
Showing
1 changed file
with
18 additions
and
1 deletions
Show diff stats
bulletin/forms.py
... | ... | @@ -31,7 +31,7 @@ class BulletinForm(forms.ModelForm): |
31 | 31 | |
32 | 32 | class Meta: |
33 | 33 | model = Bulletin |
34 | - fields = ['name', 'content', 'brief_description', 'show_window', 'visible','file_content'] | |
34 | + fields = ['name', 'content', 'brief_description', 'show_window', 'visible','file_content','indicators'] | |
35 | 35 | labels = { |
36 | 36 | 'name': _('Bulletin name'), |
37 | 37 | 'content': _('Bulletin content'), |
... | ... | @@ -77,6 +77,23 @@ class BulletinForm(forms.ModelForm): |
77 | 77 | |
78 | 78 | return file_content |
79 | 79 | |
80 | + def clean_indicators(self): | |
81 | + indicators = self.cleaned_data.get('indicators', False) | |
82 | + | |
83 | + if indicators: | |
84 | + if hasattr(indicators, '_size'): | |
85 | + if indicators._size > self.MAX_UPLOAD_SIZE: | |
86 | + self._errors['indicators'] = [_("The file is too large. It should have less than 1MB.")] | |
87 | + | |
88 | + return ValueError | |
89 | + | |
90 | + elif not self.instance.pk: | |
91 | + self._errors['indicators'] = [_('This field is required.')] | |
92 | + | |
93 | + return ValueError | |
94 | + | |
95 | + return indicators | |
96 | + | |
80 | 97 | def save(self, commit = True): |
81 | 98 | super(BulletinForm, self).save(commit = True) |
82 | 99 | ... | ... |