Code

Opened 6 years ago

Closed 6 years ago

#7238 closed (wontfix)

Feature Request: Validation for Uploaded Images/Files

Reported by: btaylordesign 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:

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.

Attachments (0)

Change History (3)

comment:1 Changed 6 years ago by btaylordesign

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

comment:2 Changed 6 years ago by michiel_1981

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 Changed 6 years ago by brosner

  • Resolution set to wontfix
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.