Django

Code

Ticket #7238 (closed: wontfix)

Opened 2 months ago

Last modified 2 months ago

Feature Request: Validation for Uploaded Images/Files

Reported by: btaylordesign Assigned to: nobody
Milestone: Component: Validators
Version: SVN Keywords: images, files, upload
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

Change History

05/14/08 11:04:31 changed by btaylordesign

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

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

05/14/08 11:19:08 changed 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

05/14/08 12:07:49 changed by brosner

  • status changed from new to closed.
  • resolution set to wontfix.

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/Change #7238 (Feature Request: Validation for Uploaded Images/Files)




Change Properties
Action