We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Wrong grade document edit form title
When editing a grade document that holds final grades, the title of the form wrongly shows "Upload midterm grades" (should be "Upload final grades" instead) because the parameter `final_grades` is not correctly set for the template.
This can for example be seen at the course "Operating Systems I (Summer term 2014)" in the test data.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `evap/grades/views.py`
Content:
```
1 from django.conf import settings
2 from django.contrib import messages
3 from django.core.exceptions import PermissionDenied
4 from django.http import HttpResponse
5 from django.shortcuts import get_object_or_404, redirect, render
6 from django.utils.translation import gettext as _
7 from django.views.decorators.http import require_GET, require_POST
8 from django_sendfile import sendfile
9 
10 from evap.evaluation.auth import (
11     grade_downloader_required,
12     grade_publisher_or_manager_required,
13     grade_publisher_required,
14 )
15 from evap.evaluation.models import Course, EmailTemplate, Evaluation, Semester
16 from evap.grades.forms import GradeDocumentForm
17 from evap.grades.models import GradeDocument
18 
19 
20 @grade_publisher_required
21 def index(request):
22     template_data = dict(
23         semesters=Semester.objects.filter(grade_documents_are_deleted=False),
24         disable_breadcrumb_grades=True,
25     )
26     return render(request, "grades_index.html", template_data)
27 
28 
29 def prefetch_data(courses):
30     courses = courses.prefetch_related("degrees", "responsibles")
31 
32     course_data = []
33     for course in courses:
34         course_data.append((course, course.midterm_grade_documents.count(), course.final_grade_documents.count()))
35 
36     return course_data
37 
38 
39 @grade_publisher_required
40 def semester_view(request, semester_id):
41     semester = get_object_or_404(Semester, id=semester_id)
42     if semester.grade_documents_are_deleted:
43         raise PermissionDenied
44 
45     courses = (
46         semester.courses.filter(evaluations__wait_for_grade_upload_before_publishing=True)
47         .exclude(evaluations__state=Evaluation.State.NEW)
48         .distinct()
49     )
50     courses = prefetch_data(courses)
51 
52     template_data = dict(
53         semester=semester,
54         courses=courses,
55         disable_if_archived="disabled" if semester.grade_documents_are_deleted else "",
56         disable_breadcrumb_semester=True,
57     )
58     return render(request, "grades_semester_view.html", template_data)
59 
60 
61 @grade_publisher_or_manager_required
62 def course_view(request, semester_id, course_id):
63     semester = get_object_or_404(Semester, id=semester_id)
64     if semester.grade_documents_are_deleted:
65         raise PermissionDenied
66     course = get_object_or_404(Course, id=course_id, semester=semester)
67 
68     template_data = dict(
69         semester=semester,
70         course=course,
71         grade_documents=course.grade_documents.all(),
72         disable_if_archived="disabled" if semester.grade_documents_are_deleted else "",
73         disable_breadcrumb_course=True,
74     )
75     return render(request, "grades_course_view.html", template_data)
76 
77 
78 def on_grading_process_finished(course):
79     evaluations = course.evaluations.all()
80     if all(evaluation.state == Evaluation.State.REVIEWED for evaluation in evaluations):
81         for evaluation in evaluations:
82             assert evaluation.grading_process_is_finished
83         for evaluation in evaluations:
84             evaluation.publish()
85             evaluation.save()
86 
87         EmailTemplate.send_participant_publish_notifications(evaluations)
88         EmailTemplate.send_contributor_publish_notifications(evaluations)
89 
90 
91 @grade_publisher_required
92 def upload_grades(request, semester_id, course_id):
93     semester = get_object_or_404(Semester, id=semester_id)
94     if semester.grade_documents_are_deleted:
95         raise PermissionDenied
96     course = get_object_or_404(Course, id=course_id, semester=semester)
97 
98     final_grades = request.GET.get("final") == "true"  # if parameter is not given, assume midterm grades
99 
100     grade_document = GradeDocument(course=course)
101     if final_grades:
102         grade_document.type = GradeDocument.Type.FINAL_GRADES
103         grade_document.description_en = settings.DEFAULT_FINAL_GRADES_DESCRIPTION_EN
104         grade_document.description_de = settings.DEFAULT_FINAL_GRADES_DESCRIPTION_DE
105     else:
106         grade_document.type = GradeDocument.Type.MIDTERM_GRADES
107         grade_document.description_en = settings.DEFAULT_MIDTERM_GRADES_DESCRIPTION_EN
108         grade_document.description_de = settings.DEFAULT_MIDTERM_GRADES_DESCRIPTION_DE
109 
110     form = GradeDocumentForm(request.POST or None, request.FILES or None, instance=grade_document)
111 
112     if form.is_valid():
113         form.save(modifying_user=request.user)
114 
115         if final_grades:
116             on_grading_process_finished(course)
117 
118         messages.success(request, _("Successfully uploaded grades."))
119         return redirect("grades:course_view", semester.id, course.id)
120 
121     template_data = dict(
122         semester=semester,
123         course=course,
124         form=form,
125         final_grades=final_grades,
126         show_automated_publishing_info=final_grades,
127     )
128     return render(request, "grades_upload_form.html", template_data)
129 
130 
131 @require_POST
132 @grade_publisher_required
133 def toggle_no_grades(request):
134     course_id = request.POST.get("course_id")
135     course = get_object_or_404(Course, id=course_id)
136     if course.semester.grade_documents_are_deleted:
137         raise PermissionDenied
138 
139     course.gets_no_grade_documents = not course.gets_no_grade_documents
140     course.save()
141 
142     if course.gets_no_grade_documents:
143         on_grading_process_finished(course)
144 
145     return HttpResponse()  # 200 OK
146 
147 
148 @require_GET
149 @grade_downloader_required
150 def download_grades(request, grade_document_id):
151     grade_document = get_object_or_404(GradeDocument, id=grade_document_id)
152     if grade_document.course.semester.grade_documents_are_deleted:
153         raise PermissionDenied
154 
155     return sendfile(request, grade_document.file.path, attachment=True, attachment_filename=grade_document.filename())
156 
157 
158 @grade_publisher_required
159 def edit_grades(request, semester_id, course_id, grade_document_id):
160     semester = get_object_or_404(Semester, id=semester_id)
161     if semester.grade_documents_are_deleted:
162         raise PermissionDenied
163     course = get_object_or_404(Course, id=course_id, semester=semester)
164     grade_document = get_object_or_404(GradeDocument, id=grade_document_id, course=course)
165 
166     form = GradeDocumentForm(request.POST or None, request.FILES or None, instance=grade_document)
167 
168     if form.is_valid():
169         form.save(modifying_user=request.user)
170         messages.success(request, _("Successfully updated grades."))
171         return redirect("grades:course_view", semester.id, course.id)
172 
173     template_data = dict(
174         semester=semester,
175         course=course,
176         form=form,
177         show_automated_publishing_info=False,
178     )
179     return render(request, "grades_upload_form.html", template_data)
180 
181 
182 @require_POST
183 @grade_publisher_required
184 def delete_grades(request):
185     grade_document_id = request.POST.get("grade_document_id")
186     grade_document = get_object_or_404(GradeDocument, id=grade_document_id)
187 
188     grade_document.delete()
189     return HttpResponse()  # 200 OK
190
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/evap/grades/views.py b/evap/grades/views.py
--- a/evap/grades/views.py
+++ b/evap/grades/views.py
@@ -165,6 +165,10 @@
 
     form = GradeDocumentForm(request.POST or None, request.FILES or None, instance=grade_document)
 
+    final_grades = (
+        grade_document.type == GradeDocument.Type.FINAL_GRADES
+    )  # if parameter is not given, assume midterm grades
+
     if form.is_valid():
         form.save(modifying_user=request.user)
         messages.success(request, _("Successfully updated grades."))
@@ -175,6 +179,7 @@
         course=course,
         form=form,
         show_automated_publishing_info=False,
+        final_grades=final_grades,
     )
     return render(request, "grades_upload_form.html", template_data)

{"golden_diff": "diff --git a/evap/grades/views.py b/evap/grades/views.py\n--- a/evap/grades/views.py\n+++ b/evap/grades/views.py\n@@ -165,6 +165,10 @@\n \n     form = GradeDocumentForm(request.POST or None, request.FILES or None, instance=grade_document)\n \n+    final_grades = (\n+        grade_document.type == GradeDocument.Type.FINAL_GRADES\n+    )  # if parameter is not given, assume midterm grades\n+\n     if form.is_valid():\n         form.save(modifying_user=request.user)\n         messages.success(request, _(\"Successfully updated grades.\"))\n@@ -175,6 +179,7 @@\n         course=course,\n         form=form,\n         show_automated_publishing_info=False,\n+        final_grades=final_grades,\n     )\n     return render(request, \"grades_upload_form.html\", template_data)\n", "issue": "Wrong grade document edit form title\nWhen editing a grade document that holds final grades, the title of the form wrongly shows \"Upload midterm grades\" (should be \"Upload final grades\" instead) because the parameter `final_grades` is not correctly set for the template.\r\nThis can for example be seen at the course \"Operating Systems I (Summer term 2014)\" in the test data.\n", "before_files": [{"content": "from django.conf import settings\nfrom django.contrib import messages\nfrom django.core.exceptions import PermissionDenied\nfrom django.http import HttpResponse\nfrom django.shortcuts import get_object_or_404, redirect, render\nfrom django.utils.translation import gettext as _\nfrom django.views.decorators.http import require_GET, require_POST\nfrom django_sendfile import sendfile\n\nfrom evap.evaluation.auth import (\n    grade_downloader_required,\n    grade_publisher_or_manager_required,\n    grade_publisher_required,\n)\nfrom evap.evaluation.models import Course, EmailTemplate, Evaluation, Semester\nfrom evap.grades.forms import GradeDocumentForm\nfrom evap.grades.models import GradeDocument\n\n\n@grade_publisher_required\ndef index(request):\n    template_data = dict(\n        semesters=Semester.objects.filter(grade_documents_are_deleted=False),\n        disable_breadcrumb_grades=True,\n    )\n    return render(request, \"grades_index.html\", template_data)\n\n\ndef prefetch_data(courses):\n    courses = courses.prefetch_related(\"degrees\", \"responsibles\")\n\n    course_data = []\n    for course in courses:\n        course_data.append((course, course.midterm_grade_documents.count(), course.final_grade_documents.count()))\n\n    return course_data\n\n\n@grade_publisher_required\ndef semester_view(request, semester_id):\n    semester = get_object_or_404(Semester, id=semester_id)\n    if semester.grade_documents_are_deleted:\n        raise PermissionDenied\n\n    courses = (\n        semester.courses.filter(evaluations__wait_for_grade_upload_before_publishing=True)\n        .exclude(evaluations__state=Evaluation.State.NEW)\n        .distinct()\n    )\n    courses = prefetch_data(courses)\n\n    template_data = dict(\n        semester=semester,\n        courses=courses,\n        disable_if_archived=\"disabled\" if semester.grade_documents_are_deleted else \"\",\n        disable_breadcrumb_semester=True,\n    )\n    return render(request, \"grades_semester_view.html\", template_data)\n\n\n@grade_publisher_or_manager_required\ndef course_view(request, semester_id, course_id):\n    semester = get_object_or_404(Semester, id=semester_id)\n    if semester.grade_documents_are_deleted:\n        raise PermissionDenied\n    course = get_object_or_404(Course, id=course_id, semester=semester)\n\n    template_data = dict(\n        semester=semester,\n        course=course,\n        grade_documents=course.grade_documents.all(),\n        disable_if_archived=\"disabled\" if semester.grade_documents_are_deleted else \"\",\n        disable_breadcrumb_course=True,\n    )\n    return render(request, \"grades_course_view.html\", template_data)\n\n\ndef on_grading_process_finished(course):\n    evaluations = course.evaluations.all()\n    if all(evaluation.state == Evaluation.State.REVIEWED for evaluation in evaluations):\n        for evaluation in evaluations:\n            assert evaluation.grading_process_is_finished\n        for evaluation in evaluations:\n            evaluation.publish()\n            evaluation.save()\n\n        EmailTemplate.send_participant_publish_notifications(evaluations)\n        EmailTemplate.send_contributor_publish_notifications(evaluations)\n\n\n@grade_publisher_required\ndef upload_grades(request, semester_id, course_id):\n    semester = get_object_or_404(Semester, id=semester_id)\n    if semester.grade_documents_are_deleted:\n        raise PermissionDenied\n    course = get_object_or_404(Course, id=course_id, semester=semester)\n\n    final_grades = request.GET.get(\"final\") == \"true\"  # if parameter is not given, assume midterm grades\n\n    grade_document = GradeDocument(course=course)\n    if final_grades:\n        grade_document.type = GradeDocument.Type.FINAL_GRADES\n        grade_document.description_en = settings.DEFAULT_FINAL_GRADES_DESCRIPTION_EN\n        grade_document.description_de = settings.DEFAULT_FINAL_GRADES_DESCRIPTION_DE\n    else:\n        grade_document.type = GradeDocument.Type.MIDTERM_GRADES\n        grade_document.description_en = settings.DEFAULT_MIDTERM_GRADES_DESCRIPTION_EN\n        grade_document.description_de = settings.DEFAULT_MIDTERM_GRADES_DESCRIPTION_DE\n\n    form = GradeDocumentForm(request.POST or None, request.FILES or None, instance=grade_document)\n\n    if form.is_valid():\n        form.save(modifying_user=request.user)\n\n        if final_grades:\n            on_grading_process_finished(course)\n\n        messages.success(request, _(\"Successfully uploaded grades.\"))\n        return redirect(\"grades:course_view\", semester.id, course.id)\n\n    template_data = dict(\n        semester=semester,\n        course=course,\n        form=form,\n        final_grades=final_grades,\n        show_automated_publishing_info=final_grades,\n    )\n    return render(request, \"grades_upload_form.html\", template_data)\n\n\n@require_POST\n@grade_publisher_required\ndef toggle_no_grades(request):\n    course_id = request.POST.get(\"course_id\")\n    course = get_object_or_404(Course, id=course_id)\n    if course.semester.grade_documents_are_deleted:\n        raise PermissionDenied\n\n    course.gets_no_grade_documents = not course.gets_no_grade_documents\n    course.save()\n\n    if course.gets_no_grade_documents:\n        on_grading_process_finished(course)\n\n    return HttpResponse()  # 200 OK\n\n\n@require_GET\n@grade_downloader_required\ndef download_grades(request, grade_document_id):\n    grade_document = get_object_or_404(GradeDocument, id=grade_document_id)\n    if grade_document.course.semester.grade_documents_are_deleted:\n        raise PermissionDenied\n\n    return sendfile(request, grade_document.file.path, attachment=True, attachment_filename=grade_document.filename())\n\n\n@grade_publisher_required\ndef edit_grades(request, semester_id, course_id, grade_document_id):\n    semester = get_object_or_404(Semester, id=semester_id)\n    if semester.grade_documents_are_deleted:\n        raise PermissionDenied\n    course = get_object_or_404(Course, id=course_id, semester=semester)\n    grade_document = get_object_or_404(GradeDocument, id=grade_document_id, course=course)\n\n    form = GradeDocumentForm(request.POST or None, request.FILES or None, instance=grade_document)\n\n    if form.is_valid():\n        form.save(modifying_user=request.user)\n        messages.success(request, _(\"Successfully updated grades.\"))\n        return redirect(\"grades:course_view\", semester.id, course.id)\n\n    template_data = dict(\n        semester=semester,\n        course=course,\n        form=form,\n        show_automated_publishing_info=False,\n    )\n    return render(request, \"grades_upload_form.html\", template_data)\n\n\n@require_POST\n@grade_publisher_required\ndef delete_grades(request):\n    grade_document_id = request.POST.get(\"grade_document_id\")\n    grade_document = get_object_or_404(GradeDocument, id=grade_document_id)\n\n    grade_document.delete()\n    return HttpResponse()  # 200 OK\n", "path": "evap/grades/views.py"}], "after_files": [{"content": "from django.conf import settings\nfrom django.contrib import messages\nfrom django.core.exceptions import PermissionDenied\nfrom django.http import HttpResponse\nfrom django.shortcuts import get_object_or_404, redirect, render\nfrom django.utils.translation import gettext as _\nfrom django.views.decorators.http import require_GET, require_POST\nfrom django_sendfile import sendfile\n\nfrom evap.evaluation.auth import (\n    grade_downloader_required,\n    grade_publisher_or_manager_required,\n    grade_publisher_required,\n)\nfrom evap.evaluation.models import Course, EmailTemplate, Evaluation, Semester\nfrom evap.grades.forms import GradeDocumentForm\nfrom evap.grades.models import GradeDocument\n\n\n@grade_publisher_required\ndef index(request):\n    template_data = dict(\n        semesters=Semester.objects.filter(grade_documents_are_deleted=False),\n        disable_breadcrumb_grades=True,\n    )\n    return render(request, \"grades_index.html\", template_data)\n\n\ndef prefetch_data(courses):\n    courses = courses.prefetch_related(\"degrees\", \"responsibles\")\n\n    course_data = []\n    for course in courses:\n        course_data.append((course, course.midterm_grade_documents.count(), course.final_grade_documents.count()))\n\n    return course_data\n\n\n@grade_publisher_required\ndef semester_view(request, semester_id):\n    semester = get_object_or_404(Semester, id=semester_id)\n    if semester.grade_documents_are_deleted:\n        raise PermissionDenied\n\n    courses = (\n        semester.courses.filter(evaluations__wait_for_grade_upload_before_publishing=True)\n        .exclude(evaluations__state=Evaluation.State.NEW)\n        .distinct()\n    )\n    courses = prefetch_data(courses)\n\n    template_data = dict(\n        semester=semester,\n        courses=courses,\n        disable_if_archived=\"disabled\" if semester.grade_documents_are_deleted else \"\",\n        disable_breadcrumb_semester=True,\n    )\n    return render(request, \"grades_semester_view.html\", template_data)\n\n\n@grade_publisher_or_manager_required\ndef course_view(request, semester_id, course_id):\n    semester = get_object_or_404(Semester, id=semester_id)\n    if semester.grade_documents_are_deleted:\n        raise PermissionDenied\n    course = get_object_or_404(Course, id=course_id, semester=semester)\n\n    template_data = dict(\n        semester=semester,\n        course=course,\n        grade_documents=course.grade_documents.all(),\n        disable_if_archived=\"disabled\" if semester.grade_documents_are_deleted else \"\",\n        disable_breadcrumb_course=True,\n    )\n    return render(request, \"grades_course_view.html\", template_data)\n\n\ndef on_grading_process_finished(course):\n    evaluations = course.evaluations.all()\n    if all(evaluation.state == Evaluation.State.REVIEWED for evaluation in evaluations):\n        for evaluation in evaluations:\n            assert evaluation.grading_process_is_finished\n        for evaluation in evaluations:\n            evaluation.publish()\n            evaluation.save()\n\n        EmailTemplate.send_participant_publish_notifications(evaluations)\n        EmailTemplate.send_contributor_publish_notifications(evaluations)\n\n\n@grade_publisher_required\ndef upload_grades(request, semester_id, course_id):\n    semester = get_object_or_404(Semester, id=semester_id)\n    if semester.grade_documents_are_deleted:\n        raise PermissionDenied\n    course = get_object_or_404(Course, id=course_id, semester=semester)\n\n    final_grades = request.GET.get(\"final\") == \"true\"  # if parameter is not given, assume midterm grades\n\n    grade_document = GradeDocument(course=course)\n    if final_grades:\n        grade_document.type = GradeDocument.Type.FINAL_GRADES\n        grade_document.description_en = settings.DEFAULT_FINAL_GRADES_DESCRIPTION_EN\n        grade_document.description_de = settings.DEFAULT_FINAL_GRADES_DESCRIPTION_DE\n    else:\n        grade_document.type = GradeDocument.Type.MIDTERM_GRADES\n        grade_document.description_en = settings.DEFAULT_MIDTERM_GRADES_DESCRIPTION_EN\n        grade_document.description_de = settings.DEFAULT_MIDTERM_GRADES_DESCRIPTION_DE\n\n    form = GradeDocumentForm(request.POST or None, request.FILES or None, instance=grade_document)\n\n    if form.is_valid():\n        form.save(modifying_user=request.user)\n\n        if final_grades:\n            on_grading_process_finished(course)\n\n        messages.success(request, _(\"Successfully uploaded grades.\"))\n        return redirect(\"grades:course_view\", semester.id, course.id)\n\n    template_data = dict(\n        semester=semester,\n        course=course,\n        form=form,\n        final_grades=final_grades,\n        show_automated_publishing_info=final_grades,\n    )\n    return render(request, \"grades_upload_form.html\", template_data)\n\n\n@require_POST\n@grade_publisher_required\ndef toggle_no_grades(request):\n    course_id = request.POST.get(\"course_id\")\n    course = get_object_or_404(Course, id=course_id)\n    if course.semester.grade_documents_are_deleted:\n        raise PermissionDenied\n\n    course.gets_no_grade_documents = not course.gets_no_grade_documents\n    course.save()\n\n    if course.gets_no_grade_documents:\n        on_grading_process_finished(course)\n\n    return HttpResponse()  # 200 OK\n\n\n@require_GET\n@grade_downloader_required\ndef download_grades(request, grade_document_id):\n    grade_document = get_object_or_404(GradeDocument, id=grade_document_id)\n    if grade_document.course.semester.grade_documents_are_deleted:\n        raise PermissionDenied\n\n    return sendfile(request, grade_document.file.path, attachment=True, attachment_filename=grade_document.filename())\n\n\n@grade_publisher_required\ndef edit_grades(request, semester_id, course_id, grade_document_id):\n    semester = get_object_or_404(Semester, id=semester_id)\n    if semester.grade_documents_are_deleted:\n        raise PermissionDenied\n    course = get_object_or_404(Course, id=course_id, semester=semester)\n    grade_document = get_object_or_404(GradeDocument, id=grade_document_id, course=course)\n\n    form = GradeDocumentForm(request.POST or None, request.FILES or None, instance=grade_document)\n\n    final_grades = (\n        grade_document.type == GradeDocument.Type.FINAL_GRADES\n    )  # if parameter is not given, assume midterm grades\n\n    if form.is_valid():\n        form.save(modifying_user=request.user)\n        messages.success(request, _(\"Successfully updated grades.\"))\n        return redirect(\"grades:course_view\", semester.id, course.id)\n\n    template_data = dict(\n        semester=semester,\n        course=course,\n        form=form,\n        show_automated_publishing_info=False,\n        final_grades=final_grades,\n    )\n    return render(request, \"grades_upload_form.html\", template_data)\n\n\n@require_POST\n@grade_publisher_required\ndef delete_grades(request):\n    grade_document_id = request.POST.get(\"grade_document_id\")\n    grade_document = get_object_or_404(GradeDocument, id=grade_document_id)\n\n    grade_document.delete()\n    return HttpResponse()  # 200 OK\n", "path": "evap/grades/views.py"}]}