Help needed re: creating custom validator

DrBix dryklim at gmail.com
Fri Oct 5 09:31:41 UTC 2007


I needed a product for users to be able to upload a file of a specific
MIMETYPE which I have registered via ZMI as 'application/x-msdownload' ( DNL
format )

I figured I needed a custom product so I created a product containing an
attribute of type FILE which works well and is working. Users can add the
item and upload a file - no problems.

However, a user is able to upload a file of literally any type whereas I
want to restrict the file type to be the MIMETYPE which I mentioned above
i.e 'application/x-msdownload'. I am new to development so I dug around,
read lots of documentation, posts etc . and also asked for pointers and I
figured I needed to 'Create a Custom Validator' in the following steps:
(please correct me if my thinking is wrong)

1. write a new Class called 'DNLValidator' to add to the validators module
2. register the new validation as 'isDNL'
3. use this validator in the product's schema to validate that the uploaded
file is of the correct type

So where I need help now is with regards to creating the method / function
in the Class that checks if the uploaded file is of type
'application/x-msdownload'. I am not sure how to check for the allowable
MIMETYPE and I got as far as this only... don;t laugh ok.:P

def __call__( self, value, *args, **kwargs):
     
      (missing bits: help needed here)

return 1

Any help or further pointers as to where I might be able to dig for further
clues would be most appreciated.

Thanks in advance,

DrBix






-- 
View this message in context: http://www.nabble.com/Help-needed-re%3A-creating-custom-validator-tf4574100s20094.html#a13056257
Sent from the Product Developers mailing list archive at Nabble.com.





More information about the Product-Developers mailing list