Changed clean_link_id to be in a wrapper form as well.
Patch by: Lennard de Rijk
Reviewed by: to-be-reviewed
--- a/app/soc/logic/cleaning.py Fri Jan 30 09:44:46 2009 +0000
+++ b/app/soc/logic/cleaning.py Fri Jan 30 10:36:23 2009 +0000
@@ -33,12 +33,16 @@
from soc.logic.models import user as user_logic
-def clean_link_id(self):
- # convert to lowercase for user comfort
- link_id = self.cleaned_data.get('link_id').lower()
- if not validate.isLinkIdFormatValid(link_id):
- raise forms.ValidationError("This link ID is in wrong format.")
- return link_id
+def clean_link_id(field_name):
+ """Checks if the field_name value is in a valid link ID format.
+ """
+ def wrapper(self):
+ # convert to lowercase for user comfort
+ link_id = self.cleaned_data.get(field_name).lower()
+ if not validate.isLinkIdFormatValid(link_id):
+ raise forms.ValidationError("This link ID is in wrong format.")
+ return link_id
+ return wrapper
def clean_agrees_to_tos(field_name):
@@ -68,10 +72,7 @@
"""
def wrapped(self):
- link_id = self.cleaned_data.get(field_name).lower()
-
- if not validate.isLinkIdFormatValid(link_id):
- raise forms.ValidationError("This link ID is in wrong format.")
+ link_id = clean_link_id(field_name)(self)
user_entity = user_logic.logic.getForFields({'link_id': link_id},
unique=True)
@@ -90,10 +91,7 @@
"""
def wrapped(self):
- link_id = self.cleaned_data.get(field_name).lower()
-
- if not validate.isLinkIdFormatValid(link_id):
- raise forms.ValidationError("This link ID is in wrong format.")
+ link_id = clean_link_id(field_name)(self)
user_entity = user_logic.logic.getForFields({'link_id': link_id},
unique=True)
--- a/app/soc/views/helper/params.py Fri Jan 30 09:44:46 2009 +0000
+++ b/app/soc/views/helper/params.py Fri Jan 30 10:36:23 2009 +0000
@@ -179,7 +179,7 @@
new_params['dynabase'] = helper.forms.BaseForm
create_dynafields = {
- 'clean_link_id': cleaning.clean_link_id,
+ 'clean_link_id': cleaning.clean_link_id('link_id'),
'clean_feed_url': cleaning.clean_feed_url,
}
create_dynafields.update(params.get('create_extra_dynafields', {}))
@@ -190,7 +190,7 @@
new_params['create_dynafields'] = create_dynafields
edit_dynafields = {
- 'clean_link_id': cleaning.clean_link_id,
+ 'clean_link_id': cleaning.clean_link_id('link_id'),
'link_id': forms.CharField(widget=helper.widgets.ReadOnlyInput()),
}
edit_dynafields.update(params.get('edit_extra_dynafields', {}))
--- a/app/soc/views/models/organization.py Fri Jan 30 09:44:46 2009 +0000
+++ b/app/soc/views/models/organization.py Fri Jan 30 10:36:23 2009 +0000
@@ -58,7 +58,7 @@
new_params['create_extra_dynafields'] = {
'scope_path': forms.CharField(widget=forms.HiddenInput,
required=True),
- 'clean_link_id': cleaning.clean_link_id,
+ 'clean_link_id': cleaning.clean_link_id('link_id'),
}
params = dicts.merge(params, new_params)
--- a/app/soc/views/models/presence.py Fri Jan 30 09:44:46 2009 +0000
+++ b/app/soc/views/models/presence.py Fri Jan 30 10:36:23 2009 +0000
@@ -71,7 +71,7 @@
help_text=soc.models.work.Work.link_id.help_text),
# add cleaning of the link id and feed url
- 'clean_link_id': cleaning.clean_link_id,
+ 'clean_link_id': cleaning.clean_link_id('link_id'),
'clean_feed_url': cleaning.clean_feed_url,
}
--- a/app/soc/views/models/user.py Fri Jan 30 09:44:46 2009 +0000
+++ b/app/soc/views/models/user.py Fri Jan 30 10:36:23 2009 +0000
@@ -81,7 +81,7 @@
new_params['edit_extra_dynafields'] = {
'link_id': forms.CharField(widget=widgets.ReadOnlyInput(),
required=True),
- 'clean_link_id': cleaning.clean_link_id,
+ 'clean_link_id': cleaning.clean_link_id('link_id'),
'agreed_to_tos_on' : forms.CharField(widget=widgets.ReadOnlyInput(),
required=False),
'clean_account': cleaning.clean_user_account('account'),
--- a/app/soc/views/models/user_self.py Fri Jan 30 09:44:46 2009 +0000
+++ b/app/soc/views/models/user_self.py Fri Jan 30 10:36:23 2009 +0000
@@ -90,7 +90,7 @@
'clean_link_id': cleaning.clean_user_not_exist('link_id'),}
new_params['edit_extra_dynafields'] = {
- 'clean_link_id': cleaning.clean_link_id
+ 'clean_link_id': cleaning.clean_link_id('link_id')
}
new_params['sidebar_heading'] = 'User (self)'