app/soc/logic/cleaning.py
changeset 1425 49d385edb6b4
parent 1395 08dbb5aa1dc9
child 1440 58ac0b3f59ac
equal deleted inserted replaced
1424:f8c762a33a43 1425:49d385edb6b4
    39 
    39 
    40 DEF_LINK_ID_IN_USE_MSG = ugettext(
    40 DEF_LINK_ID_IN_USE_MSG = ugettext(
    41     'This link ID is already in use, please specify another one')
    41     'This link ID is already in use, please specify another one')
    42 
    42 
    43 DEF_NO_RIGHTS_FOR_ACL_MSG = ugettext(
    43 DEF_NO_RIGHTS_FOR_ACL_MSG = ugettext(
    44      'You do not have the required rights for that ACL.')
    44     'You do not have the required rights for that ACL.')
       
    45 
       
    46 DEF_ORGANZIATION_NOT_ACTIVE_MSG = ugettext(
       
    47     'This organization is not active/existent')
    45 
    48 
    46 
    49 
    47 def check_field_is_empty(field_name):
    50 def check_field_is_empty(field_name):
    48   """Returns decorator that bypasses cleaning for empty fields.
    51   """Returns decorator that bypasses cleaning for empty fields.
    49   """
    52   """
   362           return cleaned_data
   365           return cleaned_data
   363 
   366 
   364       return cleaned_data
   367       return cleaned_data
   365   return wrapper
   368   return wrapper
   366 
   369 
       
   370 def validate_student_proposal(org_field, scope_field,
       
   371                               student_logic, org_logic):
       
   372   """Validates the form of a student proposal.
       
   373   
       
   374   Raises ValidationError if:
       
   375     -The organization link_id does not match an active organization
       
   376     -The hidden scope path is not a valid active student
       
   377   """
       
   378   
       
   379   def wrapper(self):
       
   380     cleaned_data = self.cleaned_data
       
   381 
       
   382     org_link_id = cleaned_data.get(org_field)
       
   383     scope_path = cleaned_data.get(scope_field)
       
   384 
       
   385     # only if both fields are valid
       
   386     if org_link_id and scope_path:
       
   387       filter = {'scope_path': scope_path,
       
   388                 'status': 'active'}
       
   389 
       
   390       student_entity = student_logic.logic.getFromKeyName(scope_path)
       
   391 
       
   392       if not student_entity or student_entity.status != 'active':
       
   393         # raise validation error, access checks should have prevented this
       
   394         raise forms.ValidationError(
       
   395             ugettext("The given student is not valid."))
       
   396 
       
   397       filter = {'link_id': org_link_id,
       
   398                 'scope': student_entity.scope,
       
   399                 'status': 'active'}
       
   400 
       
   401       org_entity = org_logic.logic.getForFields(filter, unique=True)
       
   402 
       
   403       if not org_entity:
       
   404         #raise validation error, non valid organization entered
       
   405         self._errors['organization'] = ErrorList(
       
   406             [DEF_ORGANZIATION_NOT_ACTIVE_MSG])
       
   407         del cleaned_data['organization']
       
   408 
       
   409     return cleaned_data
       
   410   return wrapper
   367 
   411 
   368 def validate_document_acl(view):
   412 def validate_document_acl(view):
   369   """Validates that the document ACL settings are correct.
   413   """Validates that the document ACL settings are correct.
   370   """
   414   """
   371 
   415