app/soc/logic/cleaning.py
changeset 1985 4ff03ca639fd
parent 1984 eb02fd5427c5
child 1988 d826f7aed8f2
equal deleted inserted replaced
1984:eb02fd5427c5 1985:4ff03ca639fd
   170 
   170 
   171     return user_entity
   171     return user_entity
   172   return wrapped
   172   return wrapped
   173 
   173 
   174 
   174 
   175 def clean_user_is_current(field_name):
   175 def clean_user_is_current(field_name, as_user=True):
   176   """Check if the field_name value is a valid link_id and resembles the
   176   """Check if the field_name value is a valid link_id and resembles the
   177      current user.
   177      current user.
   178   """
   178   """
   179 
   179 
   180   @check_field_is_empty(field_name)
   180   @check_field_is_empty(field_name)
   187 
   187 
   188     if not user_entity or user_entity.link_id != link_id:
   188     if not user_entity or user_entity.link_id != link_id:
   189       # this user is not the current user
   189       # this user is not the current user
   190       raise forms.ValidationError("This user is not you.")
   190       raise forms.ValidationError("This user is not you.")
   191 
   191 
   192     return user_entity
   192     return user_entity if as_user else link_id
   193   return wrapped
   193   return wrapped
   194 
   194 
   195 
   195 
   196 def clean_user_not_exist(field_name):
   196 def clean_user_not_exist(field_name):
   197   """Check if the field_name value is a valid link_id and a user with the
   197   """Check if the field_name value is a valid link_id and a user with the