I have one custom field in my form and I can't get the help_text in a
template. In the admin the help_text shows up fine so I assume it has
something todo with my custom field:
###template####################
{{ form.guests.help_text }} #where 'guests' is a
CommaSeparatedEmailField as specified below
###custom formField###############
class CommaSeparatedEmailField(forms.Field):
'''A form field for multiple, comma-separated email adresses'''
widget = forms.Textarea(attrs={'rows':
2,'cols':settings.TEXTAREA_COLS})
def __init__(self, *args, **kwargs):
super(CommaSeparatedEmailField, self).__init__(*args,
**kwargs)
def clean(self, value):
'''
Checks whether all email adresses are valid and returns the
original string with abundant whitespaces removed
'''
if not value:
#this field may be blank
return ''
#remove leading/trailing whitespaces and empty emails
emails = [email.strip() for email in value.split(',') if
email.strip()]
if len(emails) > settings.EMAIL_MAX_NR_RECIPIENTS:
raise forms.ValidationError('Too many e-mail addresses
(%s), maximum number is %s' %
(len(emails),
settings.EMAIL_MAX_NR_RECIPIENTS))
for email in emails:
if not self.isValidEmail(email):
raise forms.ValidationError('%s is not a valid e-mail
address.' % email)
return ','.join(emails)
def isValidEmail(self, email):
if len(email) > 7:
import re
if re.match("[EMAIL PROTECTED]
{2,6}$", email) != None:
return True
return False
######################
thanks,
2B
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---