-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathforms.py
More file actions
75 lines (52 loc) · 2.03 KB
/
forms.py
File metadata and controls
75 lines (52 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from django import forms
from django.forms.forms import NON_FIELD_ERRORS
from plugins.apc import models
from core import models as core_models
class APCForm(forms.ModelForm):
class Meta:
model = models.SectionAPC
exclude = ('section',)
def save(self, section, commit=True):
section_apc = super(APCForm, self).save(commit=False)
section_apc.section = section
if commit:
section_apc.save()
return section_apc
class WaiverResponse(forms.ModelForm):
class Meta:
model = models.WaiverApplication
fields = ('response',)
class WaiverApplication(forms.ModelForm):
class Meta:
model = models.WaiverApplication
fields = ('rationale',)
class BillingStafferForm(forms.ModelForm):
class Meta:
model = models.BillingStaffer
fields = ('staffer', 'type_of_notification', 'receives_notifications')
def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request')
super(BillingStafferForm, self).__init__(*args, **kwargs)
user_pks = self.request.journal.journal_users(objects=False)
self.fields['staffer'].queryset = core_models.Account.objects.filter(
pk__in=user_pks,
)
def clean(self):
staffer = self.cleaned_data.get('staffer')
type_of_notification = self.cleaned_data.get('type_of_notification')
journal = self.request.journal
if not self.instance.pk and models.BillingStaffer.objects.filter(
staffer=staffer,
journal=journal,
type_of_notification=type_of_notification,
).exists():
self._errors[NON_FIELD_ERRORS] = self.error_class(
['A Billing Staffer with this user, journal and type already exists.']
)
return self.cleaned_data
def save(self, commit=True):
staffer = super(BillingStafferForm, self).save(commit=False)
staffer.journal = self.request.journal
if commit:
staffer.save()
return staffer