Opened 17 years ago

Closed 17 years ago

#7238 closed (wontfix)

Feature Request: Validation for Uploaded Images/Files

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

Description

Hello,

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 by Brandon Taylor, 17 years ago

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

comment:2 by Michiel, 17 years ago

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
        else:
            self.error_message = _("Only the following extensions are allowed: " +
                                   unicode(self.extensions)[1:-1])
        self.always_test = True
    def __call__(self, field_data, all_data):
        name = ''
        try:
            name = field_data['filename'].lower()
        except:
            pass
        else:
            for ext in self.extensions:
                if name.endswith(ext):
                    return
            raise ValidationError, self.error_message

comment:3 by Brian Rosner, 17 years ago

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