Revision f3342849 snf-astakos-app/astakos/im/forms.py
b/snf-astakos-app/astakos/im/forms.py | ||
---|---|---|
57 | 57 |
from astakos.im.models import ( |
58 | 58 |
AstakosUser, EmailChange, AstakosGroup, Invitation, GroupKind, |
59 | 59 |
Resource, PendingThirdPartyUser, get_latest_terms, RESOURCE_SEPARATOR, |
60 |
ProjectDefinition, ProjectApplication, create_application
|
|
60 |
ProjectDefinition, ProjectApplication, submit_application
|
|
61 | 61 |
) |
62 | 62 |
from astakos.im.settings import ( |
63 | 63 |
INVITATIONS_PER_LEVEL, BASEURL, SITENAME, RECAPTCHA_PRIVATE_KEY, |
... | ... | |
924 | 924 |
model = ProjectDefinition |
925 | 925 |
exclude = ('resource_grants') |
926 | 926 |
|
927 |
def __init__(self, *args, **kwargs): |
|
928 |
#update QueryDict |
|
929 |
args = list(args) |
|
930 |
qd = args.pop(0).copy() |
|
931 |
members_unlimited = qd.pop('members_unlimited', False) |
|
932 |
members_uplimit = qd.pop('members_uplimit', None) |
|
933 |
|
|
934 |
#substitue QueryDict |
|
935 |
args.insert(0, qd) |
|
936 |
|
|
937 |
super(AstakosGroupCreationForm, self).__init__(*args, **kwargs) |
|
938 |
|
|
939 |
self.fields.keyOrder = ['kind', 'name', 'homepage', 'desc', |
|
940 |
'issue_date', 'expiration_date', |
|
941 |
'moderation_enabled', 'max_participants'] |
|
942 |
def add_fields((k, v)): |
|
943 |
k = k.partition('_proxy')[0] |
|
944 |
self.fields[k] = forms.IntegerField( |
|
945 |
required=False, |
|
946 |
widget=forms.HiddenInput(), |
|
947 |
min_value=1 |
|
948 |
) |
|
949 |
map(add_fields, |
|
950 |
((k, v) for k,v in qd.iteritems() if k.endswith('_uplimit')) |
|
951 |
) |
|
952 |
|
|
953 |
def add_fields((k, v)): |
|
954 |
self.fields[k] = forms.BooleanField( |
|
955 |
required=False, |
|
956 |
#widget=forms.HiddenInput() |
|
957 |
) |
|
958 |
map(add_fields, |
|
959 |
((k, v) for k,v in qd.iteritems() if k.startswith('is_selected_')) |
|
960 |
) |
|
961 |
|
|
927 |
|
|
962 | 928 |
def clean(self): |
963 | 929 |
userid = self.data.get('user', None)[0] |
964 | 930 |
self.user = None |
... | ... | |
972 | 938 |
super(ProjectApplicationForm, self).clean() |
973 | 939 |
return self.cleaned_data |
974 | 940 |
|
975 |
def resource_policies(self, clean=True): |
|
976 |
if clean: |
|
977 |
self.clean() |
|
941 |
@property |
|
942 |
def resource_policies(self): |
|
978 | 943 |
policies = [] |
979 | 944 |
append = policies.append |
980 |
for name, uplimit in self.cleaned_data.iteritems(): |
|
945 |
for name, value in self.data.iteritems(): |
|
946 |
if not value: |
|
947 |
continue |
|
948 |
uplimit = value[0] |
|
981 | 949 |
subs = name.split('_uplimit') |
982 | 950 |
if len(subs) == 2: |
983 | 951 |
prefix, suffix = subs |
... | ... | |
985 | 953 |
resource = Resource.objects.get(service__name=s, name=r) |
986 | 954 |
|
987 | 955 |
# keep only resource limits for selected resource groups |
988 |
if self.cleaned_data.get( |
|
989 |
'is_selected_%s' % resource.group, False |
|
990 |
): |
|
956 |
# if self.data.get( |
|
957 |
# 'is_selected_%s' % resource.group, False |
|
958 |
# ): |
|
959 |
if uplimit: |
|
991 | 960 |
append(dict(service=s, resource=r, uplimit=uplimit)) |
992 | 961 |
return policies |
993 | 962 |
|
994 | 963 |
def save(self, commit=True): |
995 | 964 |
definition = super(ProjectApplicationForm, self).save(commit=commit) |
996 |
definition.resource_policies=self.resource_policies(clean=False)
|
|
965 |
definition.resource_policies=self.resource_policies |
|
997 | 966 |
applicant = self.user |
998 | 967 |
comments = self.cleaned_data.pop('comments', None) |
999 | 968 |
try: |
1000 | 969 |
precursor_application = self.instance.projectapplication |
1001 | 970 |
except: |
1002 | 971 |
precursor_application = None |
1003 |
return create_application(
|
|
972 |
return submit_application(
|
|
1004 | 973 |
definition, |
1005 | 974 |
applicant, |
1006 | 975 |
comments, |
Also available in: Unified diff