Revision 0f4fa26d snf-astakos-app/astakos/im/forms.py
b/snf-astakos-app/astakos/im/forms.py | ||
---|---|---|
490 | 490 |
user.save() |
491 | 491 |
return user |
492 | 492 |
|
493 |
def get_astakos_group_creation_form(request): |
|
494 |
class AstakosGroupCreationForm(forms.ModelForm): |
|
495 |
issue_date = forms.DateField(widget=SelectDateWidget(), initial=datetime.now()) |
|
496 |
# TODO set initial in exact one month |
|
497 |
expiration_date = forms.DateField(widget=SelectDateWidget(), initial = datetime.now() + timedelta(days=30)) |
|
498 |
kind = forms.ModelChoiceField(queryset=GroupKind.objects.all(), empty_label=None) |
|
499 |
name = forms.URLField() |
|
500 |
|
|
501 |
class Meta: |
|
502 |
model = AstakosGroup |
|
503 |
|
|
504 |
def __init__(self, *args, **kwargs): |
|
505 |
super(AstakosGroupCreationForm, self).__init__(*args, **kwargs) |
|
506 |
self.fields.keyOrder = ['kind', 'name', 'desc', 'issue_date', |
|
507 |
'expiration_date', 'estimated_participants', |
|
508 |
'moderation_enabled'] |
|
509 |
|
|
510 |
def save(self, commit=True): |
|
511 |
g = super(AstakosGroupCreationForm, self).save(commit=False) |
|
512 |
if commit: |
|
513 |
g.save() |
|
514 |
g.owner = [request.user] |
|
515 |
g.approve_member(request.user) |
|
516 |
return g |
|
493 |
class AstakosGroupCreationForm(forms.ModelForm): |
|
494 |
# issue_date = forms.DateField(widget=SelectDateWidget()) |
|
495 |
# expiration_date = forms.DateField(widget=SelectDateWidget()) |
|
496 |
kind = forms.ModelChoiceField( |
|
497 |
queryset=GroupKind.objects.all(), |
|
498 |
label="", |
|
499 |
widget=forms.HiddenInput() |
|
500 |
) |
|
501 |
name = forms.URLField() |
|
517 | 502 |
|
518 |
return AstakosGroupCreationForm |
|
519 |
|
|
520 |
def get_astakos_group_policy_creation_form(astakosgroup): |
|
521 |
class AstakosGroupPolicyCreationForm(forms.ModelForm): |
|
522 |
choices = Resource.objects.filter(~Q(astakosgroup=astakosgroup)) |
|
523 |
resource = forms.ModelChoiceField(queryset=choices, empty_label=None) |
|
524 |
# TODO check that it does not hit the db |
|
525 |
group = forms.ModelChoiceField(queryset=AstakosGroup.objects.all(), initial=astakosgroup, widget=forms.HiddenInput()) |
|
526 |
|
|
527 |
class Meta: |
|
528 |
model = AstakosGroupQuota |
|
503 |
class Meta: |
|
504 |
model = AstakosGroup |
|
529 | 505 |
|
530 |
return AstakosGroupPolicyCreationForm |
|
506 |
def __init__(self, *args, **kwargs): |
|
507 |
try: |
|
508 |
resources = kwargs.pop('resources') |
|
509 |
except KeyError: |
|
510 |
resources = {} |
|
511 |
super(AstakosGroupCreationForm, self).__init__(*args, **kwargs) |
|
512 |
self.fields.keyOrder = ['kind', 'name', 'desc', 'issue_date', |
|
513 |
'expiration_date', 'estimated_participants', |
|
514 |
'moderation_enabled'] |
|
515 |
for id, r in resources.iteritems(): |
|
516 |
self.fields['resource_%s' % id] = forms.IntegerField( |
|
517 |
label=r, |
|
518 |
required=False, |
|
519 |
help_text=_('Leave it blank for no additional quota.') |
|
520 |
) |
|
521 |
|
|
522 |
def resources(self): |
|
523 |
for name, value in self.cleaned_data.items(): |
|
524 |
prefix, delimiter, suffix = name.partition('resource_') |
|
525 |
if suffix: |
|
526 |
# yield only those having a value |
|
527 |
if not value: |
|
528 |
continue |
|
529 |
yield (suffix, value) |
|
531 | 530 |
|
532 | 531 |
class AstakosGroupSearchForm(forms.Form): |
533 | 532 |
q = forms.CharField(max_length=200, label='') |
534 | 533 |
|
535 | 534 |
class MembershipCreationForm(forms.ModelForm): |
536 | 535 |
# TODO check not to hit the db |
537 |
group = forms.ModelChoiceField(queryset=AstakosGroup.objects.all(), widget=forms.HiddenInput()) |
|
538 |
person = forms.ModelChoiceField(queryset=AstakosUser.objects.all(), widget=forms.HiddenInput()) |
|
539 |
date_requested = forms.DateField(widget=forms.HiddenInput(), input_formats="%d/%m/%Y") |
|
536 |
group = forms.ModelChoiceField( |
|
537 |
queryset=AstakosGroup.objects.all(), |
|
538 |
widget=forms.HiddenInput() |
|
539 |
) |
|
540 |
person = forms.ModelChoiceField( |
|
541 |
queryset=AstakosUser.objects.all(), |
|
542 |
widget=forms.HiddenInput() |
|
543 |
) |
|
544 |
date_requested = forms.DateField( |
|
545 |
widget=forms.HiddenInput(), |
|
546 |
input_formats="%d/%m/%Y" |
|
547 |
) |
|
540 | 548 |
|
541 | 549 |
class Meta: |
542 | 550 |
model = Membership |
Also available in: Unified diff