app/soc/logic/cleaning.py
changeset 1681 b0e10552f5c2
parent 1680 fbf8101f6eff
child 1682 242ca517c340
equal deleted inserted replaced
1680:fbf8101f6eff 1681:b0e10552f5c2
   120     return scope_path
   120     return scope_path
   121   return wrapper
   121   return wrapper
   122 
   122 
   123 
   123 
   124 def clean_agrees_to_tos(field_name):
   124 def clean_agrees_to_tos(field_name):
   125   """Checks if there is a ToS to see if it is allowed to leave 
   125   """Checks if there is a ToS to see if it is allowed to leave
   126      the field_name field false.
   126      the field_name field false.
   127   """
   127   """
   128 
   128 
   129   @check_field_is_empty(field_name)
   129   @check_field_is_empty(field_name)
   130   def wrapper(self):
   130   def wrapper(self):
   136       return agrees_to_tos
   136       return agrees_to_tos
   137 
   137 
   138     # Site settings specify a site-wide ToS, so agreement is *required*
   138     # Site settings specify a site-wide ToS, so agreement is *required*
   139     if agrees_to_tos:
   139     if agrees_to_tos:
   140       return True
   140       return True
   141     
   141 
   142     # there was no agreement made so raise an error
   142     # there was no agreement made so raise an error
   143     raise forms.ValidationError(
   143     raise forms.ValidationError(
   144         'The site-wide Terms of Service must be accepted to participate'
   144         'The site-wide Terms of Service must be accepted to participate'
   145         ' on this site.')
   145         ' on this site.')
   146 
   146 
   167     return user_entity
   167     return user_entity
   168   return wrapped
   168   return wrapped
   169 
   169 
   170 
   170 
   171 def clean_user_is_current(field_name):
   171 def clean_user_is_current(field_name):
   172   """Check if the field_name value is a valid link_id and resembles the 
   172   """Check if the field_name value is a valid link_id and resembles the
   173      current user.
   173      current user.
   174   """
   174   """
   175 
   175 
   176   @check_field_is_empty(field_name)
   176   @check_field_is_empty(field_name)
   177   def wrapped(self):
   177   def wrapped(self):
   190 
   190 
   191 
   191 
   192 def clean_user_not_exist(field_name):
   192 def clean_user_not_exist(field_name):
   193   """Check if the field_name value is a valid link_id and a user with the
   193   """Check if the field_name value is a valid link_id and a user with the
   194      link id does not exist.
   194      link id does not exist.
   195   """ 
   195   """
   196 
   196 
   197   @check_field_is_empty(field_name)
   197   @check_field_is_empty(field_name)
   198   def wrapped(self):
   198   def wrapped(self):
   199     """Decorator wrapper method.
   199     """Decorator wrapper method.
   200     """
   200     """
   210     return link_id
   210     return link_id
   211   return wrapped
   211   return wrapped
   212 
   212 
   213 
   213 
   214 def clean_users_not_same(field_name):
   214 def clean_users_not_same(field_name):
   215   """Check if the field_name field is a valid user and is not 
   215   """Check if the field_name field is a valid user and is not
   216      equal to the current user.
   216      equal to the current user.
   217   """
   217   """
   218 
   218 
   219   @check_field_is_empty(field_name)
   219   @check_field_is_empty(field_name)
   220   def wrapped(self):
   220   def wrapped(self):
   246 
   246 
   247   return wrapped
   247   return wrapped
   248 
   248 
   249 
   249 
   250 def clean_user_account_not_in_use(field_name):
   250 def clean_user_account_not_in_use(field_name):
   251   """Check if the field_name value contains an email 
   251   """Check if the field_name value contains an email
   252      address that hasn't been used for an existing account.
   252      address that hasn't been used for an existing account.
   253   """ 
   253   """
   254 
   254 
   255   @check_field_is_empty(field_name)
   255   @check_field_is_empty(field_name)
   256   def wrapped(self):
   256   def wrapped(self):
   257     """Decorator wrapper method.
   257     """Decorator wrapper method.
   258     """
   258     """
   273 
   273 
   274 
   274 
   275 def clean_feed_url(self):
   275 def clean_feed_url(self):
   276   """Clean method for cleaning feed url.
   276   """Clean method for cleaning feed url.
   277   """
   277   """
       
   278 
   278   feed_url = self.cleaned_data.get('feed_url')
   279   feed_url = self.cleaned_data.get('feed_url')
   279 
   280 
   280   if feed_url == '':
   281   if feed_url == '':
   281     # feed url not supplied (which is OK), so do not try to validate it
   282     # feed url not supplied (which is OK), so do not try to validate it
   282     return None
   283     return None
   283   
   284 
   284   if not validate.isFeedURLValid(feed_url):
   285   if not validate.isFeedURLValid(feed_url):
   285     raise forms.ValidationError('This URL is not a valid ATOM or RSS feed.')
   286     raise forms.ValidationError('This URL is not a valid ATOM or RSS feed.')
   286 
   287 
   287   return feed_url
   288   return feed_url
   288 
   289 
   305 
   306 
   306   @check_field_is_empty(field_name)
   307   @check_field_is_empty(field_name)
   307   def wrapped(self):
   308   def wrapped(self):
   308     """Decorator wrapper method.
   309     """Decorator wrapper method.
   309     """
   310     """
       
   311 
   310     value = self.cleaned_data.get(field_name)
   312     value = self.cleaned_data.get(field_name)
   311 
   313 
   312     # call the Django URLField cleaning method to 
   314     # call the Django URLField cleaning method to
   313     # properly clean/validate this field
   315     # properly clean/validate this field
   314     return forms.URLField.clean(self.fields[field_name], value)
   316     return forms.URLField.clean(self.fields[field_name], value)
   315   return wrapped
   317   return wrapped
   316 
   318 
   317 
   319 
   318 def validate_user_edit(link_id_field, account_field):
   320 def validate_user_edit(link_id_field, account_field):
   319   """Clean method for cleaning user edit form.
   321   """Clean method for cleaning user edit form.
   320   
   322 
   321   Raises ValidationError if:
   323   Raises ValidationError if:
   322     -Another User has the given email address as account
   324     -Another User has the given email address as account
   323     -Another User has the given email address in it's FormerAccounts list
   325     -Another User has the given email address in it's FormerAccounts list
   324   """
   326   """
   325 
   327 
   354 
   356 
   355     return cleaned_data
   357     return cleaned_data
   356   return wrapper
   358   return wrapper
   357 
   359 
   358 
   360 
   359 def validate_new_group(link_id_field, scope_path_field, 
   361 def validate_new_group(link_id_field, scope_path_field,
   360                        group_logic, group_app_logic):
   362                        group_logic, group_app_logic):
   361   """Clean method used to clean the group application or new group form.
   363   """Clean method used to clean the group application or new group form.
   362   
   364 
   363     Raises ValidationError if:
   365     Raises ValidationError if:
   364     -A application with this link id and scope path already exists
   366     -A application with this link id and scope path already exists
   365     -A group with this link id and scope path already exists
   367     -A group with this link id and scope path already exists
   366   """
   368   """
   367 
   369 
   410   return wrapper
   412   return wrapper
   411 
   413 
   412 def validate_student_proposal(org_field, scope_field,
   414 def validate_student_proposal(org_field, scope_field,
   413                               student_logic, org_logic):
   415                               student_logic, org_logic):
   414   """Validates the form of a student proposal.
   416   """Validates the form of a student proposal.
   415   
   417 
   416   Raises ValidationError if:
   418   Raises ValidationError if:
   417     -The organization link_id does not match an active organization
   419     -The organization link_id does not match an active organization
   418     -The hidden scope path is not a valid active student
   420     -The hidden scope path is not a valid active student
   419   """
   421   """
   420   
   422 
   421   def wrapper(self):
   423   def wrapper(self):
   422     """Decorator wrapper method.
   424     """Decorator wrapper method.
   423     """
   425     """
   424     cleaned_data = self.cleaned_data
   426     cleaned_data = self.cleaned_data
   425 
   427