stage 2: nice button
[edumed.git] / stage2 / forms.py
index 7a68314..8317504 100644 (file)
@@ -24,7 +24,10 @@ class AttachmentForm(forms.ModelForm):
         max_mb = options.get('max', 20)
         self.max_upload_size = max_mb * 1024 * 1024
         self.fields['file'].widget.attrs['data-max'] = max_mb
-        self.fields['file'].label = label + u' (maks. %s MB)' % max_mb
+        label_extra = ['maks. %s MB' % max_mb]
+        if extensions:
+            label_extra.append('format: %s' % ', '.join(extensions))
+        self.fields['file'].label = label + u' (%s)' % '; '.join(label_extra)
         if extensions:
             self.fields['file'].widget.attrs['data-ext'] = '|'.join(extensions)
         self.extensions = extensions
@@ -53,11 +56,12 @@ class AssignmentFieldForm(forms.Form):
         self.type = options['type']
         self.fields['assignment_id'].initial = answer.assignment.id
         max_length = options.get('max_length')
+        if options.get('widget') == 'area':
+            self.fields['value'].widget = forms.Textarea(attrs={'cols': 80, 'rows': 25})
         if max_length:
             self.fields['value'].validators.append(validators.MaxLengthValidator(int(max_length)))
             self.fields['value'].label += u' (maks. %s znaków)' % max_length
-        if options.get('widget') == 'area':
-            self.fields['value'].widget = forms.Textarea(attrs={'cols': 80, 'rows': 25})
+            self.fields['value'].widget.attrs['data-max-length'] = max_length
         if self.type == 'options':
             option_set = FieldOptionSet.objects.get(name=options['option_set'])
             self.fields['value'].widget = forms.Select(choices=option_set.choices(answer))