Revision ccab6eb5 snf-astakos-app/astakos/im/forms.py
b/snf-astakos-app/astakos/im/forms.py | ||
---|---|---|
922 | 922 |
|
923 | 923 |
class Meta: |
924 | 924 |
model = ProjectDefinition |
925 |
exclude = ('resource_grants', 'serial')
|
|
925 |
exclude = ('resource_grants', 'id')
|
|
926 | 926 |
|
927 |
|
|
928 |
def __init__(self, *args, **kwargs): |
|
929 |
super(ProjectApplicationForm, self).__init__(*args, **kwargs) |
|
930 |
instance = kwargs.get('instance') |
|
931 |
if instance: |
|
932 |
self.initial['comments'] = instance.projectapplication.comments |
|
933 |
|
|
927 | 934 |
def clean(self): |
928 | 935 |
userid = self.data.get('user', None)[0] |
929 | 936 |
self.user = None |
... | ... | |
960 | 967 |
return policies |
961 | 968 |
|
962 | 969 |
def save(self, commit=True): |
963 |
definition = super(ProjectApplicationForm, self).save(commit=commit) |
|
964 |
definition.resource_policies=self.resource_policies |
|
970 |
definition = super(ProjectApplicationForm, self).save(commit=False) |
|
965 | 971 |
applicant = self.user |
966 | 972 |
comments = self.cleaned_data.pop('comments', None) |
967 | 973 |
try: |
... | ... | |
970 | 976 |
precursor_application = None |
971 | 977 |
return ProjectApplication.submit( |
972 | 978 |
definition, |
979 |
self.resource_policies, |
|
973 | 980 |
applicant, |
974 | 981 |
comments, |
975 | 982 |
precursor_application, |
... | ... | |
984 | 991 |
('definition__start_date', 'Sort by Start Date'), |
985 | 992 |
('definition__end_date', 'Sort by End Date'), |
986 | 993 |
# ('approved_members_num', 'Sort by Participants'), |
987 |
('definition__member_accept_policy', 'Sort by Member Accept Policy'),
|
|
988 |
('definition__member_reject_policy', 'Sort by Member Reject Policy')
|
|
994 |
('definition__member_join_policy__description', 'Sort by Member Join Policy'),
|
|
995 |
('definition__member_leave_policy__description', 'Sort by Member Leave Policy')
|
|
989 | 996 |
), |
990 | 997 |
required=True |
991 |
) |
|
998 |
) |
|
999 |
|
|
1000 |
class AddProjectMembersForm(forms.Form): |
|
1001 |
q = forms.CharField( |
|
1002 |
max_length=800, widget=forms.Textarea, label=_('Add members'), |
|
1003 |
help_text=_(astakos_messages.ADD_PROJECT_MEMBERS_Q_HELP), |
|
1004 |
required=True) |
|
1005 |
|
|
1006 |
def clean(self): |
|
1007 |
q = self.cleaned_data.get('q') or '' |
|
1008 |
users = q.split(',') |
|
1009 |
users = list(u.strip() for u in users if u) |
|
1010 |
db_entries = AstakosUser.objects.filter(email__in=users) |
|
1011 |
unknown = list(set(users) - set(u.email for u in db_entries)) |
|
1012 |
if unknown: |
|
1013 |
raise forms.ValidationError(_(astakos_messages.UNKNOWN_USERS) % ','.join(unknown)) |
|
1014 |
self.valid_users = db_entries |
|
1015 |
return self.cleaned_data |
|
1016 |
|
|
1017 |
def get_valid_users(self): |
|
1018 |
"""Should be called after form cleaning""" |
|
1019 |
try: |
|
1020 |
return self.valid_users |
|
1021 |
except: |
|
1022 |
return () |
Also available in: Unified diff