-
Notifications
You must be signed in to change notification settings - Fork 4
/
forms.py
58 lines (47 loc) · 1.6 KB
/
forms.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ==============================================================================
#
# File Name : letsagree/forms.py
#
# Creation Date : Mon 25 Feb 2019 05:44:28 PM EET (17:44)
#
# Last Modified : Mon 08 Apr 2019 03:16:38 PM EEST (15:16)
#
# ==============================================================================
from django import forms
from django.conf import settings
from django.utils.translation import gettext_lazy as _
from letsagree import models
from translated_fields import to_attribute
class PendingConsentForm(forms.ModelForm):
agree = forms.BooleanField(required=True, label=_("I Give my Consent"))
def save(self, *args, **kwargs):
"""
There is nothing to save. This form is a building block of a formset
with read-only contents.
"""
pass
def __init__(self, *args, **kwargs):
"""
All Fields are disabled. They are rendered as read-only fields.
"""
super().__init__(*args, **kwargs)
for field in self.fields.keys():
if field == "agree":
continue
self.fields[field].disabled = True
class Media:
css = getattr(settings, "LETSAGREE_CSS", dict())
js = getattr(settings, "LETSAGREE_JS", tuple())
class Meta:
model = models.Term
fields = (
"date_created",
to_attribute("summary"),
to_attribute("content"),
"agree",
)
PendingAgreementFormSet = forms.modelformset_factory(
models.Term, form=PendingConsentForm, extra=0
)