equal
deleted
inserted
replaced
23 |
23 |
24 |
24 |
25 from django import forms |
25 from django import forms |
26 from django.utils.translation import ugettext |
26 from django.utils.translation import ugettext |
27 |
27 |
|
28 from soc.logic import cleaning |
28 |
29 |
29 def cleanTaskComment(comment_field, action_field, ws_field): |
30 def cleanTaskComment(comment_field, action_field, ws_field): |
30 """Cleans the comment form and checks to see if there is either |
31 """Cleans the comment form and checks to see if there is either |
31 action or comment content. |
32 action or comment content. |
32 |
33 |
54 'submission fields empty.')) |
55 'submission fields empty.')) |
55 |
56 |
56 return cleaned_data |
57 return cleaned_data |
57 |
58 |
58 return wrapper |
59 return wrapper |
|
60 |
|
61 |
|
62 def clean_mentors_list(field_name): |
|
63 """Clean method to check and validate list of mentor's link_ids. |
|
64 """ |
|
65 |
|
66 @check_field_is_empty(field_name) |
|
67 def wrapper(self): |
|
68 """Decorator wrapped method. |
|
69 """ |
|
70 |
|
71 from soc.modules.ghop.logic.models.mentor import logic as ghop_mentor_logic |
|
72 |
|
73 mentors_list_str = cleaning.str2set(field_name) |
|
74 |
|
75 filter = { |
|
76 'scope_path': self.cleaned_data.get('scope_path'), |
|
77 'status': ['active'] |
|
78 } |
|
79 |
|
80 mentors_list = [] |
|
81 for link_id in mentors_list_str: |
|
82 |
|
83 if not validate.isLinkIdFormatValid(link_id): |
|
84 raise forms.ValidationError( |
|
85 "%s is not a valid link ID." % link_id) |
|
86 |
|
87 filter['link_id'] = link_id |
|
88 |
|
89 if not ghop_mentor_logic.getFromKeyFields(filter): |
|
90 raise forms.ValidationError( |
|
91 'link_id "%s" is not a valid Mentor.' % link_id) |
|
92 |
|
93 mentors_list.append(link_id) |
|
94 |
|
95 return mentors_list |
|
96 return wrapper |