Code

Ticket #1687: UploadSize.diff

File UploadSize.diff, 1.3 KB (added by rhettg@…, 8 years ago)
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,17 +636,23 @@
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+        if length:
15+            self.length = "size=\"%s\"" % str(length)
16+        else:
17+            self.length = ""
18 
19     def isNonEmptyFile(self, field_data, all_data):
20         if not field_data['content']:
21             raise validators.CriticalValidationError, gettext("The submitted file is empty.")
22 
23     def render(self, data):
24-        return '<input type="file" id="%s" class="v%s" name="%s" />' % \
25-            (self.get_id(), self.__class__.__name__, self.field_name)
26+        return '<input type="file" id="%s" class="v%s" %s name="%s" />' % \
27+            (self.get_id(), self.__class__.__name__, self.length,
28+             self.field_name)
29 
30     def html2python(data):
31         if data is None: