app/soc/logic/cleaning.py
changeset 788 892877b7db07
parent 650 33b6dcae5615
child 837 bc1c951bf3a0
equal deleted inserted replaced
787:63d7f170b63c 788:892877b7db07
    24 
    24 
    25 
    25 
    26 from django import forms
    26 from django import forms
    27 
    27 
    28 from soc.logic import validate
    28 from soc.logic import validate
       
    29 from soc.logic.models import user as user_logic
    29 
    30 
    30 
    31 
    31 def clean_new_link_id(logic):
    32 def clean_new_link_id(logic):
    32   """Clean method for new link_id's
    33   """Clean method for new link_id's
    33 
    34 
    54   if not validate.isLinkIdFormatValid(link_id):
    55   if not validate.isLinkIdFormatValid(link_id):
    55     raise forms.ValidationError("This link ID is in wrong format.")
    56     raise forms.ValidationError("This link ID is in wrong format.")
    56   return link_id
    57   return link_id
    57 
    58 
    58 
    59 
       
    60 def clean_existing_user(field_name):
       
    61   """Check if the field_name field is a valid user.
       
    62   """
       
    63 
       
    64   def wrapped(self):
       
    65     link_id = self.cleaned_data.get(field_name).lower()
       
    66   
       
    67     if not validate.isLinkIdFormatValid(link_id):
       
    68       raise forms.ValidationError("This link ID is in wrong format.")
       
    69   
       
    70     user_entity = user_logic.logic.getForFields({'link_id' : link_id}, unique=True)
       
    71   
       
    72     if not user_entity:
       
    73       # user does not exist
       
    74       raise forms.ValidationError("This user does not exist")
       
    75   
       
    76     return user_entity
       
    77   return wrapped
       
    78 
       
    79 
    59 def clean_feed_url(self):
    80 def clean_feed_url(self):
    60   feed_url = self.cleaned_data.get('feed_url')
    81   feed_url = self.cleaned_data.get('feed_url')
    61 
    82 
    62   if feed_url == '':
    83   if feed_url == '':
    63     # feed url not supplied (which is OK), so do not try to validate it
    84     # feed url not supplied (which is OK), so do not try to validate it