from mediagoblin.auth.tools import normalize_user_or_email_field
+class WebsiteField(wtforms.StringField):
+ """A field that expects a website URL but adds http:// if not provided."""
+ def process_formdata(self, valuelist):
+ data = valuelist[0]
+ if not data.startswith((u'http://', u'https://')):
+ data = u'http://' + data
+ self.data = data
+
+
class EditForm(wtforms.Form):
title = wtforms.StringField(
_('Title'),
[wtforms.validators.Optional(),],
choices=licenses_as_choices())
+
class EditProfileForm(wtforms.Form):
bio = wtforms.TextAreaField(
_('Bio'),
description=_("""You can use
<a href="http://daringfireball.net/projects/markdown/basics">
Markdown</a> for formatting."""))
- url = wtforms.StringField(
+ url = WebsiteField(
_('Website'),
[wtforms.validators.Optional(),
- wtforms.validators.URL(message=_("This address contains errors"))])
+ wtforms.validators.URL(message=_("This address contains errors"))],
+ description=_("www.example.com, http://www.example.com or "
+ "https://www.example.com"))
location = wtforms.StringField(_('Hometown'))
+
class EditAccountForm(wtforms.Form):
wants_comment_notification = wtforms.BooleanField(
description=_("Email me when others comment on my media"))
description=_(
"Enter your password to prove you own this account."))
+
class MetaDataValidator(object):
"""
Custom validator which runs form data in a MetaDataForm through a jsonschema
raise wtforms.validators.ValidationError(
errors.pop())
+
class MetaDataForm(wtforms.Form):
identifier = wtforms.StringField(_(u'Identifier'),[MetaDataValidator()])
value = wtforms.StringField(_(u'Value'))
+
class EditMetaDataForm(wtforms.Form):
media_metadata = wtforms.FieldList(
wtforms.FormField(MetaDataForm, ""),