# HG changeset patch # User Madhusudan.C.S # Date 1252096967 -7200 # Node ID ea99091618401ad9223ec6be52fac28bf0d66c73 # Parent 391766c2aacf2e435f63cb19431420ada0d72af0 Added cleaning method to validate a list of mentor's link_ids. Reviewed by: Lennard de Rijk diff -r 391766c2aacf -r ea9909161840 app/soc/modules/ghop/logic/cleaning.py --- a/app/soc/modules/ghop/logic/cleaning.py Fri Sep 04 22:35:13 2009 +0200 +++ b/app/soc/modules/ghop/logic/cleaning.py Fri Sep 04 22:42:47 2009 +0200 @@ -25,6 +25,7 @@ from django import forms from django.utils.translation import ugettext +from soc.logic import cleaning def cleanTaskComment(comment_field, action_field, ws_field): """Cleans the comment form and checks to see if there is either @@ -56,3 +57,40 @@ return cleaned_data return wrapper + + +def clean_mentors_list(field_name): + """Clean method to check and validate list of mentor's link_ids. + """ + + @check_field_is_empty(field_name) + def wrapper(self): + """Decorator wrapped method. + """ + + from soc.modules.ghop.logic.models.mentor import logic as ghop_mentor_logic + + mentors_list_str = cleaning.str2set(field_name) + + filter = { + 'scope_path': self.cleaned_data.get('scope_path'), + 'status': ['active'] + } + + mentors_list = [] + for link_id in mentors_list_str: + + if not validate.isLinkIdFormatValid(link_id): + raise forms.ValidationError( + "%s is not a valid link ID." % link_id) + + filter['link_id'] = link_id + + if not ghop_mentor_logic.getFromKeyFields(filter): + raise forms.ValidationError( + 'link_id "%s" is not a valid Mentor.' % link_id) + + mentors_list.append(link_id) + + return mentors_list + return wrapper