Ticket #1687: UploadSize.2.diff

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

Alternate solution (I think this might look better)

  • 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        self.length = length
    642644
    643645    def isNonEmptyFile(self, field_data, all_data):
    644646        if not field_data['content']:
    645647            raise validators.CriticalValidationError, gettext("The submitted file is empty.")
    646648
    647649    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)
     650        if self.length:
     651            length = "size=\"%s\"" % str(self.length)
     652        else:
     653            length = ""
    650654
     655        return '<input type="file" id="%s" class="v%s" %s name="%s" />' % \
     656            (self.get_id(), self.__class__.__name__, length,
     657             self.field_name)
     658
    651659    def html2python(data):
    652660        if data is None:
    653661            raise EmptyValue
Back to Top