Opened 10 years ago

Closed 10 years ago

#7238 closed (wontfix)

Feature Request: Validation for Uploaded Images/Files

Reported by: Brandon Taylor Owned by: nobody
Component: Validators Version: master
Severity: Keywords: images, files, upload
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:



It would be great to have validators to ensure uploaded images/files are in a list of accepted file types, and to be able to check to see if an image falls within certain width and height restrictions and that the uploaded file doesn't exceed a file size limit.

Change History (3)

comment:1 Changed 10 years ago by Brandon Taylor

Sorry, forgot to mention that this feature would part of the Django Admin app.

comment:2 Changed 10 years ago by Michiel

For the first you can use a validator and second should be possible as well.

See: validator-list

class hasValidExtension(object):
    "Check if file has a allowed extension"
    def __init__(self, extensions, error_message=None):
        self.extensions = [ ext.lower() for ext in extensions ]
        if error_message:
            self.error_message = error_message
            self.error_message = _("Only the following extensions are allowed: " +
        self.always_test = True
    def __call__(self, field_data, all_data):
        name = ''
            name = field_data['filename'].lower()
            for ext in self.extensions:
                if name.endswith(ext):
            raise ValidationError, self.error_message

comment:3 Changed 10 years ago by Brian Rosner

Resolution: wontfix
Status: newclosed

As the trunk admin is no longer supported for features and several bug fixes please use a validator and the validator_list as pointed out by michiel_1981. Otherwise the newforms-admin branch will also allow you to write custom validation for the admin using newforms. Marking as wontfix.

Note: See TracTickets for help on using tickets.
Back to Top