From c8ddfda0b0af15fa98c38c5b20efee3b3c6b3464 Mon Sep 17 00:00:00 2001
From: Ben Sturmfels <ben@sturm.com.au>
Date: Sun, 23 Aug 2015 22:17:13 +1000
Subject: [PATCH 1/2] trac#994: Don't require users to type the website URL
scheme when updating profile.
Adds 'http://' if no scheme is provided. Eg. If you enter 'www.example.com', this will be updated to 'http://www.example.com'.
---
mediagoblin/edit/forms.py | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/mediagoblin/edit/forms.py b/mediagoblin/edit/forms.py
index cf5056c..b9eef04 100644
|
a
|
b
|
from mediagoblin.tools.metadata import DEFAULT_SCHEMA, DEFAULT_CHECKER
|
| 24 | 24 | from mediagoblin.auth.tools import normalize_user_or_email_field |
| 25 | 25 | |
| 26 | 26 | |
| | 27 | class WebsiteField(wtforms.StringField): |
| | 28 | """A field that expects a website URL but adds http:// if not provided.""" |
| | 29 | def process_formdata(self, valuelist): |
| | 30 | data = valuelist[0] |
| | 31 | if not (data.startswith(u'http://') or data.startswith(u'https://')): |
| | 32 | data = u'http://' + data |
| | 33 | self.data = data |
| | 34 | |
| | 35 | |
| 27 | 36 | class EditForm(wtforms.Form): |
| 28 | 37 | title = wtforms.StringField( |
| 29 | 38 | _('Title'), |
| … |
… |
class EditForm(wtforms.Form):
|
| 49 | 58 | [wtforms.validators.Optional(),], |
| 50 | 59 | choices=licenses_as_choices()) |
| 51 | 60 | |
| | 61 | |
| 52 | 62 | class EditProfileForm(wtforms.Form): |
| 53 | 63 | bio = wtforms.TextAreaField( |
| 54 | 64 | _('Bio'), |
| … |
… |
class EditProfileForm(wtforms.Form):
|
| 56 | 66 | description=_("""You can use |
| 57 | 67 | <a href="http://daringfireball.net/projects/markdown/basics"> |
| 58 | 68 | Markdown</a> for formatting.""")) |
| 59 | | url = wtforms.StringField( |
| | 69 | url = WebsiteField( |
| 60 | 70 | _('Website'), |
| 61 | 71 | [wtforms.validators.Optional(), |
| 62 | 72 | wtforms.validators.URL(message=_("This address contains errors"))]) |
| 63 | 73 | |
| 64 | 74 | location = wtforms.StringField(_('Hometown')) |
| 65 | 75 | |
| | 76 | |
| 66 | 77 | class EditAccountForm(wtforms.Form): |
| 67 | 78 | wants_comment_notification = wtforms.BooleanField( |
| 68 | 79 | description=_("Email me when others comment on my media")) |
| … |
… |
class ChangeEmailForm(wtforms.Form):
|
| 126 | 137 | description=_( |
| 127 | 138 | "Enter your password to prove you own this account.")) |
| 128 | 139 | |
| | 140 | |
| 129 | 141 | class MetaDataValidator(object): |
| 130 | 142 | """ |
| 131 | 143 | Custom validator which runs form data in a MetaDataForm through a jsonschema |
| … |
… |
class MetaDataValidator(object):
|
| 152 | 164 | raise wtforms.validators.ValidationError( |
| 153 | 165 | errors.pop()) |
| 154 | 166 | |
| | 167 | |
| 155 | 168 | class MetaDataForm(wtforms.Form): |
| 156 | 169 | identifier = wtforms.StringField(_(u'Identifier'),[MetaDataValidator()]) |
| 157 | 170 | value = wtforms.StringField(_(u'Value')) |
| 158 | 171 | |
| | 172 | |
| 159 | 173 | class EditMetaDataForm(wtforms.Form): |
| 160 | 174 | media_metadata = wtforms.FieldList( |
| 161 | 175 | wtforms.FormField(MetaDataForm, ""), |
--
1.9.1
From b5d3f9a444ac30bd151c662a0beb96a41d83ed9b Mon Sep 17 00:00:00 2001
From: Ben Sturmfels <ben@sturm.com.au>
Date: Tue, 25 Aug 2015 01:00:28 +1000
Subject: [PATCH 2/2] trac#994: Simplify the "startswith" test and add website
field description.
---
mediagoblin/edit/forms.py | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/mediagoblin/edit/forms.py b/mediagoblin/edit/forms.py
index b9eef04..cbc176c 100644
|
a
|
b
|
class WebsiteField(wtforms.StringField):
|
| 28 | 28 | """A field that expects a website URL but adds http:// if not provided.""" |
| 29 | 29 | def process_formdata(self, valuelist): |
| 30 | 30 | data = valuelist[0] |
| 31 | | if not (data.startswith(u'http://') or data.startswith(u'https://')): |
| | 31 | if not data.startswith((u'http://', u'https://')): |
| 32 | 32 | data = u'http://' + data |
| 33 | 33 | self.data = data |
| 34 | 34 | |
| … |
… |
class EditProfileForm(wtforms.Form):
|
| 69 | 69 | url = WebsiteField( |
| 70 | 70 | _('Website'), |
| 71 | 71 | [wtforms.validators.Optional(), |
| 72 | | wtforms.validators.URL(message=_("This address contains errors"))]) |
| | 72 | wtforms.validators.URL(message=_("This address contains errors"))], |
| | 73 | description=_("www.example.com")) |
| 73 | 74 | |
| 74 | 75 | location = wtforms.StringField(_('Hometown')) |
| 75 | 76 | |