Code

Ticket #1687: UploadSize.2.diff

File UploadSize.2.diff, 1.4 KB (added by rhettg@…, 8 years ago)

Alternate solution (I think this might look better)

Line 
1Index: magic-removal/django/forms/__init__.py
2===================================================================
3--- magic-removal/django/forms/__init__.py      (revision 2747)
4+++ magic-removal/django/forms/__init__.py      (working copy)
5@@ -636,18 +636,26 @@
6 ####################
7 
8 class FileUploadField(FormField):
9-    def __init__(self, field_name, is_required=False, validator_list=[]):
10+    def __init__(self, field_name, is_required=False, validator_list=[],
11+                 length=None):
12         self.field_name, self.is_required = field_name, is_required
13         self.validator_list = [self.isNonEmptyFile] + validator_list
14+        self.length = length
15 
16     def isNonEmptyFile(self, field_data, all_data):
17         if not field_data['content']:
18             raise validators.CriticalValidationError, gettext("The submitted file is empty.")
19 
20     def render(self, data):
21-        return '<input type="file" id="%s" class="v%s" name="%s" />' % \
22-            (self.get_id(), self.__class__.__name__, self.field_name)
23+        if self.length:
24+            length = "size=\"%s\"" % str(self.length)
25+        else:
26+            length = ""
27 
28+        return '<input type="file" id="%s" class="v%s" %s name="%s" />' % \
29+            (self.get_id(), self.__class__.__name__, length,
30+             self.field_name)
31+
32     def html2python(data):
33         if data is None:
34             raise EmptyValue