Ticket #1687: UploadSize.diff

File UploadSize.diff, 1.3 KB (added by rhettg@…, 19 years ago)
  • magic-removal/django/forms/__init__.py

     
    636636####################
    637637
    638638class FileUploadField(FormField):
    639     def __init__(self, field_name, is_required=False, validator_list=[]):
     639    def __init__(self, field_name, is_required=False, validator_list=[],
     640                 length=None):
    640641        self.field_name, self.is_required = field_name, is_required
    641642        self.validator_list = [self.isNonEmptyFile] + validator_list
     643        if length:
     644            self.length = "size=\"%s\"" % str(length)
     645        else:
     646            self.length = ""
    642647
    643648    def isNonEmptyFile(self, field_data, all_data):
    644649        if not field_data['content']:
    645650            raise validators.CriticalValidationError, gettext("The submitted file is empty.")
    646651
    647652    def render(self, data):
    648         return '<input type="file" id="%s" class="v%s" name="%s" />' % \
    649             (self.get_id(), self.__class__.__name__, self.field_name)
     653        return '<input type="file" id="%s" class="v%s" %s name="%s" />' % \
     654            (self.get_id(), self.__class__.__name__, self.length,
     655             self.field_name)
    650656
    651657    def html2python(data):
    652658        if data is None:
Back to Top