Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assign contributor questionnaires per course type #2373

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
general and contributor questionnaires per course type
added the option to specify course types, where speific contributor questionaires should be added to all such courses
  • Loading branch information
jooooosef committed Jan 14, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit da496cb4f9c4a1f3cda89b42a3037b3080a7853b
26 changes: 17 additions & 9 deletions evap/staff/forms.py
Original file line number Diff line number Diff line change
@@ -917,19 +917,27 @@ class QuestionnairesAssignForm(forms.Form):
def __init__(self, *args, course_types, **kwargs):
super().__init__(*args, **kwargs)

for course_type in course_types:
self.fields[course_type.name] = forms.ModelMultipleChoiceField(
required=False,
queryset=Questionnaire.objects.general_questionnaires().exclude(
visibility=Questionnaire.Visibility.HIDDEN
),
)
contributor_questionnaires = Questionnaire.objects.contributor_questionnaires().exclude(
visibility=Questionnaire.Visibility.HIDDEN
)
self.fields["all-contributors"] = forms.ModelMultipleChoiceField(
label=_("All contributors"), required=False, queryset=contributor_questionnaires
general_questionnaires = Questionnaire.objects.general_questionnaires().exclude(
visibility=Questionnaire.Visibility.HIDDEN
)

for course_type in course_types:
self.fields["general-" + course_type.name] = forms.ModelMultipleChoiceField(
jooooosef marked this conversation as resolved.
Show resolved Hide resolved
label=_(course_type.name),
jooooosef marked this conversation as resolved.
Show resolved Hide resolved
required=False,
queryset=general_questionnaires,
)
self.fields["contributor-" + course_type.name] = forms.ModelMultipleChoiceField(
label=_(course_type.name),
required=False,
queryset=contributor_questionnaires
)
#self.fields["all-contributors"] = forms.ModelMultipleChoiceField(
# label=_("All contributors"), required=False, queryset=contributor_questionnaires
#)


class UserForm(forms.ModelForm):
30 changes: 27 additions & 3 deletions evap/staff/templates/staff_semester_questionnaire_assign_form.html
Original file line number Diff line number Diff line change
@@ -14,9 +14,33 @@ <h3>{% translate 'Assign questionnaires' %}</h3>
<div class="card mb-3">
<div class="card-body">
<p>{% translate 'Select the questionnaires which shall be assigned each of these course types and the contributors. This will only change evaluations in preparation. If you do select nothing, the currently applied questionnaires for the corresponding course type or contributor will not be changed.' %}</p>
<fieldset>
{% include 'bootstrap_form.html' with form=form %}
</fieldset>
{% include 'bootstrap_form_errors.html' with errors=form.non_field_errors %}
<div class="row">
<div class="col-md-6">
<div class="card">
<div class="card-body">
<h4 class="card-title">{% translate 'General' %}</h4>
<fieldset>
{% for field in general_fields %}
{% include 'bootstrap_form_field.html' with field=field %}
{% endfor %}
</fieldset>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card">
<div class="card-body">
<h4 class="card-title">{% translate 'Contributors' %}</h4>
<fieldset>
{% for field in contributor_fields %}
{% include 'bootstrap_form_field.html' with field=field %}
{% endfor %}
</fieldset>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="card card-submit-area text-center mb-3">
15 changes: 9 additions & 6 deletions evap/staff/views.py
Original file line number Diff line number Diff line change
@@ -901,21 +901,24 @@ def semester_questionnaire_assign(request, semester_id):
raise PermissionDenied
evaluations = semester.evaluations.filter(state=Evaluation.State.NEW)
course_types = CourseType.objects.filter(courses__evaluations__in=evaluations)
form = QuestionnairesAssignForm(request.POST or None, course_types=course_types)
form = QuestionnairesAssignForm(request.POST or None, course_types=course_types) # das erste is inital data, damit bei fehler die alten sachen da sind

general_fields = [field for field in form if field.name.startswith("general-")]
contributor_fields = [field for field in form if field.name.startswith("contributor-")]

if form.is_valid():
for evaluation in evaluations:
if form.cleaned_data[evaluation.course.type.name]:
evaluation.general_contribution.questionnaires.set(form.cleaned_data[evaluation.course.type.name])
if form.cleaned_data["all-contributors"]:
if form.cleaned_data["general-" + evaluation.course.type.name]:
evaluation.general_contribution.questionnaires.set(form.cleaned_data["general-" + evaluation.course.type.name])
if form.cleaned_data["contributor-" + evaluation.course.type.name]:
for contribution in evaluation.contributions.exclude(contributor=None):
contribution.questionnaires.set(form.cleaned_data["all-contributors"])
contribution.questionnaires.set(form.cleaned_data["contributor-" + evaluation.course.type.name])
evaluation.save()

messages.success(request, _("Successfully assigned questionnaires."))
return redirect("staff:semester_view", semester_id)

return render(request, "staff_semester_questionnaire_assign_form.html", {"semester": semester, "form": form})
return render(request, "staff_semester_questionnaire_assign_form.html", {"semester": semester, "form": form, "general_fields": general_fields, "contributor_fields": contributor_fields})


@manager_required