Skip to content

Commit 28772ec

Browse files
ArnavBallinCodemariobehling
authored andcommitted
Fixing the Cfp custom fields (fossasia#1408)
* added template files * cfp * fix: Add options management interface for CFP custom fields * fix: Reorder form fields to match Pretalx * fix: Display Field required radio buttons inline with proper Bootstrap styling --------- Co-authored-by: Mario Behling <mb@mariobehling.de>
1 parent d484f3f commit 28772ec

File tree

6 files changed

+199
-15
lines changed

6 files changed

+199
-15
lines changed
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
{% load i18n %}
2-
{% with widget_classes=field.field.widget.attrs.class|default:"" help_left=field.field.widget.attrs.help_left|default:False %}
32
<div class="form-group {{ form_group_class }}{% with classes=field.css_classes %}{% if classes %} {{ classes }}{% endif %}{% endwith %}">
43
{% block field_label_left %}
54
{% if field.field.widget.input_type != "checkbox" or field.field.widget.allow_multiple_selected %}
65
<label for="{{ field.auto_id }}" class="{{ label_class }}">
76
{{ field.label }}
87
{% if not field.field.required %}<span class="optional">{% translate "Optional" %}</span>{% endif %}
98
</label>
10-
{% if field.help_text and (help_left or 'multi-language-select' in widget_classes) %}
11-
<small class="form-text text-muted">{{ field.help_text|safe }}</small>
12-
{% endif %}
139
{% endif %}
1410
{% endblock %}
1511

@@ -25,9 +21,6 @@
2521
{% for text in field.errors %}
2622
<div class="invalid-feedback">{{ text }}</div>
2723
{% endfor %}
28-
{% if field.help_text and not (help_left or 'multi-language-select' in widget_classes) %}
29-
<small class="form-text text-muted"{% if field.auto_id %} id="{{ field.auto_id }}_helptext"{% endif %}>{{ field.help_text|safe }}</small>
30-
{% endif %}
24+
{% if field.help_text %}<small class="form-text text-muted"{% if field.auto_id %} id="{{ field.auto_id }}_helptext"{% endif %}>{{ field.help_text|safe }}</small>{% endif %}
3125
{% endblock %}
3226
</div>
33-
{% endwith %}

app/eventyay/orga/forms/cfp.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,17 +275,17 @@ class Meta:
275275
model = TalkQuestion
276276
fields = [
277277
'target',
278+
'variant',
278279
'question',
279280
'help_text',
280-
'question_required',
281-
'deadline',
282-
'freeze_after',
283-
'variant',
284281
'is_public',
282+
'contains_personal_data',
285283
'is_visible_to_reviewers',
286284
'tracks',
287285
'submission_types',
288-
'contains_personal_data',
286+
'question_required',
287+
'deadline',
288+
'freeze_after',
289289
'min_length',
290290
'max_length',
291291
'min_number',
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
{% extends "orga/generic/_form.html" %}
2+
3+
{% load compress %}
4+
{% load formset_tags %}
5+
{% load i18n %}
6+
{% load static %}
7+
8+
{% block stylesheets %}
9+
{% compress css %}
10+
<link rel="stylesheet" href="{% static "orga/css/dragsort.css" %}">
11+
{% endcompress %}
12+
{% endblock stylesheets %}
13+
14+
{% block scripts %}
15+
{% compress js %}
16+
<script defer src="{% static "js/jquery.js" %}"></script>
17+
<script defer src="{% static "js/jquery.formset.js" %}"></script>
18+
<script defer src="{% static "cfp/js/animateFormset.js" %}"></script>
19+
<script defer src="{% static "orga/js/questionForm.js" %}"></script>
20+
<script defer src="{% static "orga/js/dragsort.js" %}"></script>
21+
{% endcompress %}
22+
{% endblock scripts %}
23+
24+
{% block form %}
25+
<form method="post" enctype="multipart/form-data">
26+
{% csrf_token %}
27+
{% include "common/forms/errors.html" %}
28+
29+
{% block warnings %}{% endblock warnings %}
30+
31+
{{ form.target.as_field_group }}
32+
{{ form.variant.as_field_group }}
33+
{{ form.question.as_field_group }}
34+
{{ form.help_text.as_field_group }}
35+
{{ form.is_public.as_field_group }}
36+
{{ form.contains_personal_data.as_field_group }}
37+
<span id="is-visible-to-reviewers">{{ form.is_visible_to_reviewers.as_field_group }}</span>
38+
<fieldset class="limit-submission">
39+
<legend id="limit">{% translate "Limit to specific proposals" %}</legend>
40+
{% if form.tracks %}
41+
<span class="limit-submission">{{ form.tracks.as_field_group }}</span>
42+
{% endif %}
43+
{% if form.submission_types %}
44+
<span class="limit-submission">{{ form.submission_types.as_field_group }}</span>
45+
{% endif %}
46+
</fieldset>
47+
<fieldset>
48+
<legend id="validation">{% translate "Input validation" %}</legend>
49+
<div class="form-group row">
50+
<label class="col-md-3 col-form-label">{{ form.question_required.label }}</label>
51+
<div class="col-md-9">
52+
<div class="form-check form-check-inline" style="display: inline-block; margin-right: 1.5rem;">
53+
{% for choice in form.question_required %}
54+
<div class="form-check" style="display: inline-block; margin-right: 1.5rem;">
55+
{{ choice.tag }}
56+
<label class="form-check-label" for="{{ choice.id_for_label }}" style="margin-left: 0.25rem;">
57+
{{ choice.choice_label }}
58+
</label>
59+
</div>
60+
{% endfor %}
61+
</div>
62+
</div>
63+
</div>
64+
<div class="alert alert-info col-md-9 offset-md-3" id="alert-required-boolean">
65+
{% blocktranslate trimmed %}
66+
If you mark a Yes/No field as required, it means that the user has to select Yes and No is not
67+
accepted. If you want to allow both options, do not make this field required.
68+
{% endblocktranslate %}
69+
</div>
70+
{{ form.deadline.as_field_group }}
71+
{{ form.freeze_after.as_field_group }}
72+
<span id="limit-length">
73+
{{ form.min_length.as_field_group }}
74+
{{ form.max_length.as_field_group }}
75+
</span>
76+
<span id="limit-number">
77+
{{ form.min_number.as_field_group }}
78+
{{ form.max_number.as_field_group }}
79+
</span>
80+
<span id="limit-date">
81+
{{ form.min_date.as_field_group }}
82+
{{ form.max_date.as_field_group }}
83+
</span>
84+
<span id="limit-datetime">
85+
{{ form.min_datetime.as_field_group }}
86+
{{ form.max_datetime.as_field_group }}
87+
</span>
88+
</fieldset>
89+
90+
<fieldset id="answer-options" class="d-none">
91+
<legend id="options">{% translate "Response options" %}</legend>
92+
{% if formset %}
93+
<details class="col-md-9 offset-md-3 mb-3 hide-label" {% if form.errors.options or form.errors.options_replace %}open{% endif %}>
94+
<summary>{% translate "Upload options" %}</summary>
95+
<div class="pt-3"></div>
96+
{{ form.options.as_field_group }}
97+
{{ form.options_replace.as_field_group }}
98+
<hr>
99+
</details>
100+
<div class="formset" data-formset data-formset-prefix="{{ formset.prefix }}">
101+
{{ formset.management_form }}
102+
{{ formset.non_form_errors }}
103+
<div data-formset-body dragsort-url="{{ form.instance.urls.base }}">
104+
{% for form in formset %}
105+
<div data-formset-form dragsort-id="{{ form.instance.id }}">
106+
<div class="sr-only">
107+
{{ form.id }}
108+
{{ form.DELETE }}
109+
</div>
110+
<div class="question-option-row flip ml-auto col-md-9 mb-2 d-flex hide-label">
111+
<div class="question-option-input w-100{% if action == "view" %} disabled{% endif %}">
112+
{% include "common/forms/errors.html" %}
113+
{{ form.answer.as_field_group }}
114+
</div>
115+
{% if action != "view" %}
116+
<div class="question-option-delete d-flex align-items-start">
117+
<button draggable="true" type="button" class="btn btn-primary ml-1 mr-1 dragsort-button" title="{% translate "Move item" %}">
118+
<i class="fa fa-arrows"></i>
119+
</button>
120+
121+
<button type="button" class="btn btn-danger" data-formset-delete-button>
122+
<i class="fa fa-trash"></i>
123+
</button>
124+
</div>
125+
{% endif %}
126+
</div>
127+
</div>
128+
{% endfor %}
129+
</div>
130+
<script type="form-template" data-formset-empty-form>
131+
{% escapescript %}
132+
<div data-formset-form>
133+
<div class="sr-only">
134+
{{ formset.empty_form.id }}
135+
{{ formset.empty_form.DELETE }}
136+
</div>
137+
<div class="question-option-row flip ml-auto col-md-9 mb-2 d-flex hide-label">
138+
<div class="question-option-input w-100">
139+
{{ formset.empty_form.answer.as_field_group }}
140+
</div>
141+
<div class="question-option-delete ml-2">
142+
<button type="button" class="btn btn-danger" data-formset-delete-button>
143+
<i class="fa fa-trash"></i></button>
144+
</div>
145+
</div>
146+
</div>
147+
{% endescapescript %}
148+
</script>
149+
{% if action != "view" %}
150+
<p class="col-md-9 flip ml-auto">
151+
<button type="button" class="btn btn-info" data-formset-add>
152+
<i class="fa fa-plus"></i> {% translate "Add a new option" %}
153+
</button>
154+
</p>
155+
{% endif %}
156+
</div>
157+
{% endif %}
158+
</fieldset>
159+
160+
{% include "orga/includes/submit_row.html" %}
161+
162+
</form>
163+
{% endblock form %}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{% extends "orga/cfp/talkquestion/_form.html" %}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{% extends "orga/cfp/talkquestion/_form.html" %}
2+
3+
{% load i18n %}
4+
5+
{% block warnings %}
6+
{% if question.answers.count %}
7+
<div class="alert alert-warning col-md-9 offset-md-3">
8+
{% blocktranslate trimmed %}
9+
This custom field already has responses from some speakers – please consider
10+
carefully if modifying it would render those answers obsolete. You could also
11+
deactivate this field and create a new one instead.
12+
{% endblocktranslate %}
13+
</div>
14+
{% endif %}
15+
<div class="alert alert-info col-md-9 offset-md-3">
16+
<span>
17+
{% if question.active %}
18+
{% translate "This field is currently active, it will be asked during submission." %}
19+
<a class="btn btn-sm btn-outline-danger"
20+
href="{{ question.urls.toggle }}">{% translate "Hide field" %}</a>
21+
{% else %}
22+
{% translate "This field is currently inactive, and will not be asked during submission." %}
23+
<a class="btn btn-sm btn-success" href="{{ question.urls.toggle }}">{% translate "Activate field" %}</a>
24+
{% endif %}
25+
</span>
26+
</div>
27+
{% endblock warnings %}

app/eventyay/orga/views/cfp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,15 @@ def base_search_url(self):
223223

224224
def get_context_data(self, **kwargs):
225225
result = super().get_context_data(**kwargs)
226+
if 'form' in result:
227+
result['formset'] = self.formset
226228
if not self.object or not self.filter_form.is_valid():
227229
return result
228230
result.update(self.filter_form.get_question_information(self.object))
229231
result['grouped_answers_json'] = json.dumps(list(result['grouped_answers']), cls=I18nStrJSONEncoder)
230232
if self.action == 'detail':
231233
result['base_search_url'] = self.base_search_url
232234
result['filter_form'] = self.filter_form
233-
if 'form' in result:
234-
result['formset'] = self.formset
235235
return result
236236

237237
def form_valid(self, form):

0 commit comments

Comments
 (0)