-
Notifications
You must be signed in to change notification settings - Fork 1
/
forms.py
114 lines (91 loc) · 3.34 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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, BuddyRequestMatch
from apps.fiestaforms.fields.array import ChoicedArrayField
from apps.fiestaforms.forms import BaseModelForm
from apps.fiestaforms.widgets.models import ActiveLocalMembersFromSectionWidget, FacultyWidget, 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 = (
"note",
"interests",
"responsible_section",
"issuer",
"issuer_faculty",
)
field_classes = {
"interests": ChoicedArrayField,
}
widgets = {
"responsible_section": HiddenInput,
"issuer": HiddenInput,
"issuer_faculty": FacultyWidget,
}
labels = {
"note": _("Tell us about yourself"),
"interests": _("What are you into?"),
"issuer_faculty": _("Your faculty"),
}
help_texts = {
"note": lazy(
lambda: render_to_string("buddy_system/parts/buddy_request_note_help.html"),
str,
)
}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if self.initial.get("issuer_faculty"):
self.fields["issuer_faculty"].disabled = True
# 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["note"].disabled = True
self.fields["interests"].disabled = True
class Meta:
model = BuddyRequest
fields = (
"issuer",
"state",
"note",
"interests",
# "matched_by",
# "matched_at",
)
field_classes = {
"interests": ChoicedArrayField,
# "matched_at": DateTimeLocalField,
}
widgets = {
"issuer": UserWidget,
# "matched_by": ActiveLocalMembersFromSectionWidget,
}
class QuickBuddyMatchForm(BaseModelForm):
submit_text = _("Match")
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# self.fields["issuer"].disabled = True
class Meta:
model = BuddyRequestMatch
fields = ("matcher",)
widgets = {
"matcher": ActiveLocalMembersFromSectionWidget,
}