Skip to content

Commit

Permalink
set initial via initial=
Browse files Browse the repository at this point in the history
  • Loading branch information
fekoch committed Nov 11, 2024
1 parent 7c27940 commit 96e9dc7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ <h4 class="{% if not forloop.first %} mt-3 {% elif contributor %} me-auto {% end
<div class="col-answer col-lg-8 col-xl-7 my-auto d-flex">
<div class="vote-inputs tab-row {{ field.field.widget.attrs.choices.css_class }} btn-group" data-bs-toggle="buttons">
{% for choice, color in field|zip:field.field.widget.attrs.choices.colors %}
<input id="{{ choice.id_for_label }}" class="tab-selectable num-selectable btn-check" name="{{ choice.data.name }}" type="radio" value="{{ choice.data.value }}" autocomplete="off"{% if field.field.value.0 == choice.data.value %} checked="checked"{% endif %}{% if preview %} disabled{% endif %}/>
<input id="{{ choice.id_for_label }}" class="tab-selectable num-selectable btn-check" name="{{ choice.data.name }}" type="radio" value="{{ choice.data.value }}" autocomplete="off"{% if field.initial == choice.data.value %} checked="checked"{% endif %}{% if preview %} disabled{% endif %}/>
<label for="{{ choice.id_for_label }}" class="btn btn-sm btn-light vote-btn vote-btn-{{ color }} d-flex{% if field.value == choice.data.value %} active{% endif %}{% if field.errors %} choice-error{% endif %}">
<span class="m-auto vote-btn-text">{{ choice.choice_label|linebreaksbr }} {{ choice.id }}</span>
</label>
Expand Down
17 changes: 9 additions & 8 deletions evap/student/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def sorter(evaluation):


def get_vote_page_form_groups(
request: HttpRequest, evaluation: Evaluation, preview: bool
request: HttpRequest, evaluation: Evaluation, preview: bool, show_dropout_questionnaire=False
) -> OrderedDict[Contribution, list[QuestionnaireVotingForm]]:
contributions_to_vote_on = evaluation.contributions.all()
# prevent a user from voting on themselves
Expand All @@ -208,7 +208,12 @@ def get_vote_page_form_groups(
if not questionnaires.exists():
continue
form_groups[contribution] = [
QuestionnaireVotingForm(request.POST or None, contribution=contribution, questionnaire=questionnaire)
QuestionnaireVotingForm(request.POST or None, contribution=contribution, questionnaire=questionnaire,
initial={
answer_field_id(contribution, questionnaire, question): NO_ANSWER for question
in questionnaire.rating_questions
} if show_dropout_questionnaire else None
)
for questionnaire in questionnaires
]
return form_groups
Expand All @@ -221,8 +226,9 @@ def render_vote_page(
for_rendering_in_modal: bool = False,
show_dropout_questionnaire: bool = False,
):
form_groups = get_vote_page_form_groups(request, evaluation, preview)
form_groups = get_vote_page_form_groups(request, evaluation, preview, show_dropout_questionnaire)

# TODO@Felix: why does this assert throw
assert preview or not all(form.is_valid() for form_group in form_groups.values() for form in form_group)

evaluation_form_group = form_groups.pop(evaluation.general_contribution, default=[])
Expand Down Expand Up @@ -264,11 +270,6 @@ def render_vote_page(
questionnaire=dropout_questionnaire,
),
)
# TODO@felix: also set contributor questionnaires to default
for form in evaluation_form_group_top + evaluation_form_group_bottom:
for name, field in form.fields.items():
if hasattr(field, "choices"):
field.value = field.choices[-1] # TODO@Felix: tried doing this with NO_ANSWER, but that didnt work

template_data = {
"contributor_errors_exist": contributor_errors_exist,
Expand Down

0 comments on commit 96e9dc7

Please sign in to comment.