-
Notifications
You must be signed in to change notification settings - Fork 1
/
forms.py
90 lines (74 loc) · 2.72 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from __future__ import annotations
from django.forms import BooleanField, HiddenInput, fields_for_model
from django.template.loader import render_to_string
from django.utils.functional import lazy
from django.utils.translation import gettext_lazy as _
from apps.accounts.models import UserProfile
from apps.buddy_system.models import BuddyRequest
from apps.fiestaforms.fields.array import ChoicedArrayField
from apps.fiestaforms.fields.datetime import DateTimeLocalField
from apps.fiestaforms.forms import BaseModelForm
from apps.fiestaforms.widgets.models import MembersFromSectionSpaceWidget, UserWidget
USER_PROFILE_CONTACT_FIELDS = fields_for_model(
UserProfile,
fields=("facebook", "instagram", "telegram", "whatsapp"),
)
class NewBuddyRequestForm(BaseModelForm):
submit_text = _("Send request for buddy")
# TODO: group field somehow and add group headings
facebook, instagram, telegram, whatsapp = USER_PROFILE_CONTACT_FIELDS.values()
approving_request = BooleanField(required=True, label=_("I really want a buddy"))
class Meta:
model = BuddyRequest
fields = (
"description",
"interests",
"responsible_section",
"issuer",
)
field_classes = {
"interests": ChoicedArrayField,
}
widgets = {
"responsible_section": HiddenInput,
"issuer": HiddenInput,
}
labels = {
"description": _("Tell us about yourself"),
"interests": _("What are you into?"),
}
help_texts = {
"description": lazy(
lambda: render_to_string("buddy_system/parts/buddy_request_description_help.html"),
str,
)
}
# TODO: add save/load of contacts to/from user_profile
class BuddyRequestEditorForm(BaseModelForm):
submit_text = _("Save")
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["issuer"].disabled = True
if self.instance.state != BuddyRequest.State.CREATED:
self.fields["matched_by"].disabled = True
self.fields["matched_at"].disabled = True
self.fields["description"].disabled = True
self.fields["interests"].disabled = True
class Meta:
model = BuddyRequest
fields = (
"issuer",
"state",
"description",
"interests",
"matched_by",
"matched_at",
)
field_classes = {
"interests": ChoicedArrayField,
"matched_at": DateTimeLocalField,
}
widgets = {
"issuer": UserWidget,
"matched_by": MembersFromSectionSpaceWidget,
}