Thanks for the code snippets Anthony--but a minor caveat I didn't realize 
ahead of time is that the user is free to either upload an image or not. If 
the user does not upload an image, the IS_IMAGE() validators barks at the 
user. Is there a easy way of implementing such a logic: "if a file is 
uploaded, check for IS_IMAGE(), otherwise ignore."?


On Thursday, March 22, 2012 3:38:01 PM UTC-7, Anthony wrote:
>
> On Thursday, March 22, 2012 6:09:25 PM UTC-4, Peter G. wrote:
>>
>> I'm using the auth.settengs.extra_fields to add an extra upload field for 
>> the user to upload an avatar, how can I add an IS_IMAGE validator to the 
>> upload field so that the user can't upload random files?
>
>
> When you define the field, you can do:
>
> Field('avatar', 'upload', requires=IS_IMAGE())
>
> or after the tables have been defined:
>
> db.auth_user.avatar.requires = IS_IMAGE()
>  
>
>>
>> Also, how would I add an IS_ALPHANUMERIC to the built in First name and 
>> Last name form fields? Right now there are users registering with names 
>> like "!@#$%^~" and some such...
>>
>
> After the tables have been defined, you can do:
>
> db.auth_user.first_name.requires.append(IS_ALPHANUMERIC())
>
> That adds the validator to the existing IS_NOT_EMPTY validator.
>
> However, I wouldn't use that validator for names because it doesn't allow 
> valid name characters such as spaces, hyphens, and apostrophes. Anyway, if 
> you prevent fake names with special characters, those users will just 
> create fake names with alphanumeric characters, so either way you don't 
> have a real name.
>
> Anthony
>

Reply via email to