-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathforms.py
More file actions
159 lines (133 loc) Β· 5.93 KB
/
forms.py
File metadata and controls
159 lines (133 loc) Β· 5.93 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit
from django import forms
from django.forms import ModelChoiceField, ChoiceField
from django_summernote.widgets import SummernoteInplaceWidget
from django.shortcuts import reverse
from django.utils.translation import ugettext_lazy as _
from .models import Proposal, OpenReview, ProgramCategory, LightningTalk
from constance import config
class ProposalForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(ProposalForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_method = 'post'
self.helper.add_input(Submit('submit', _('Submit')))
self.fields['brief'].initial = config.CFP_BRIEF_TEMPLATE
self.fields['desc'].initial = config.CFP_DESC_TEMPLATE
self.fields['category'].queryset = ProgramCategory.objects.filter(visible=True)
class Meta:
model = Proposal
fields = ('title', 'brief', 'desc', 'comment',
'difficulty', 'duration', 'language', 'category',)
widgets = {
'desc': SummernoteInplaceWidget(),
'comment': SummernoteInplaceWidget(),
}
labels = {
'title': _('Proposal title (required)'),
'brief': _('Brief (required)'),
'desc': _('Detailed description (required)'),
'comment': _('Comment to reviewers (optional)'),
'difficulty': _('Session difficulty'),
'duration': _('Session duration'),
'language': _('Session language'),
'category': _('Category'),
}
class CategoryChoiceField(ModelChoiceField):
def label_from_instance(self, obj):
return f'{obj.name}'
class LanguageChoiceField(ModelChoiceField):
def label_from_instance(self, obj):
return f'{obj}'
class OpenReviewLanguageForm(forms.Form):
def __init__(self, *args, **kwargs):
super(OpenReviewLanguageForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_method = 'post'
self.helper.add_input(Submit('next', _('Next')))
self.fields['language'] = ChoiceField(choices=(
('N', 'μκ΄ μμ'),
('K', 'νκ΅μ΄'),
('E', 'English'),
), help_text=_('μ΄λ€ μΈμ΄λ‘ μμ±λ λ°ν μ μμ 리뷰ν μ§ μ ννμΈμ.'))
class Meta:
fields = ('language',)
labels = {
'language': _('μΈμ΄'),
}
class OpenReviewCategoryForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(OpenReviewCategoryForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_method = 'post'
self.helper.add_input(Submit('next', _('Next')))
self.fields['category'] = CategoryChoiceField(label=_('μΉ΄ν
κ³ λ¦¬'),
queryset=ProgramCategory.objects.filter(visible=True).exclude(
proposal=None),
help_text=_('리뷰ν λΆμΌλ₯Ό μ ννμΈμ. λ°ν μ μμ΄ μλ λΆμΌλ νμλμ§ μμ΅λλ€.')
)
# μ΄μ νΌμμ μ νν μΈμ΄μ 보 μ μ₯μ© Hidden input μμ± (Viewμμ helperλ₯Ό μ΄μ©ν΄ μΆκ°)
class Meta:
model = OpenReview
fields = ('category',)
labels = {
'category': _('μΉ΄ν
κ³ λ¦¬ μ΄λ¦'),
}
class OpenReviewCommentForm(forms.ModelForm):
comment = forms.CharField(min_length=20, max_length=2000, widget=forms.Textarea())
def __init__(self, *args, **kwargs):
super(OpenReviewCommentForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_method = 'post'
self.helper.add_input(Submit('save', _('Save')))
class Meta:
model = OpenReview
fields = ('comment',)
labels = {
'comment': _('Comment')
}
class LightningTalkForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(LightningTalkForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_method = 'post'
self.helper.add_input(Submit('submit', _('Submit')))
LT_N = config.LIGHTNING_TALK_N
if len(LightningTalk.objects.filter(day=1)) >= LT_N:
if len(LightningTalk.objects.filter(day=2)) < LT_N:
self.fields['day'] = ChoiceField(choices=((2, _('μΌμμΌ')),))
else:
if len(LightningTalk.objects.filter(day=2)) < LT_N:
self.fields['day'] = ChoiceField(choices=((1, _('ν μμΌ')), (2, _('μΌμμΌ')),))
else:
self.fields['day'] = ChoiceField(choices=((1, _('ν μμΌ')),))
self.fields['video_url'].required = True
class Meta:
model = LightningTalk
fields = ('title', 'video_url', 'slide_url', 'day', 'brief', 'comment',)
labels = {
'title': _('λ°ν μ λͺ©'),
'video_url': _('λ°ν μμ URL'),
'slide_url': _('λ°ν μ¬λΌμ΄λ URL'),
'day': _('λ°ν μμΌ'),
'brief': _('λ°ν μκ° λ¬Έκ΅¬'),
'comment': _('μ€λΉμμνμκ² λ¨κΈ°κ³ μΆμ λ§'),
}
class ProgramUpdateForm(forms.ModelForm):
class Meta:
model = Proposal
fields = ('title', 'introduction', 'slide_url',)
labels = {
'title': _('Proposal title (required)'),
'introduction': _('λ°ν μκ° λ¬Έκ΅¬'),
'slide_url': _('λ°ν μλ£ URL'),
}
widgets = {
'introduction': SummernoteInplaceWidget(),
}
def __init__(self, *args, **kwargs):
super(ProgramUpdateForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_method = 'post'
self.helper.add_input(Submit('submit', _('Submit')))