We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Result detail pages need to show total grades and participation
The `results/course_detail` pages should again show the information that is already given on the overview page (average and medium grades and participation).


--- 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/results/views.py`
Content:
```
1 from django.conf import settings
2 from django.http import HttpResponse
3 from django.shortcuts import get_object_or_404, render_to_response
4 from django.template import RequestContext
5 from django.utils.translation import get_language
6 
7 from evap.evaluation.auth import login_required, fsr_required
8 from evap.evaluation.models import Semester
9 from evap.evaluation.tools import calculate_results, calculate_average_and_medium_grades, TextResult, can_publish_grades
10 
11 from evap.results.exporters import ExcelExporter
12 
13 
14 @login_required
15 def index(request):
16     semesters = Semester.get_all_with_published_courses()
17 
18     return render_to_response(
19         "results_index.html",
20         dict(semesters=semesters),
21         context_instance=RequestContext(request))
22 
23 
24 @login_required
25 def semester_detail(request, semester_id):
26     semester = get_object_or_404(Semester, id=semester_id)
27     courses = list(semester.course_set.filter(state="published"))
28 
29     # annotate each course object with its grades
30     for course in courses:
31         # first, make sure that there are no preexisting grade attributes
32         course.avg_grade, course.med_grade = calculate_average_and_medium_grades(course)
33         course.can_publish_grades = can_publish_grades(course, request.user.is_staff)
34 
35     return render_to_response(
36         "results_semester_detail.html",
37         dict(
38             semester=semester,
39             courses=courses
40         ),
41         context_instance=RequestContext(request))
42 
43 
44 @fsr_required
45 def semester_export(request, semester_id):
46     semester = get_object_or_404(Semester, id=semester_id)
47 
48     filename = "Evaluation-%s-%s.xls" % (semester.name, get_language())
49 
50     response = HttpResponse(mimetype="application/vnd.ms-excel")
51     response["Content-Disposition"] = "attachment; filename=\"%s\"" % filename
52 
53     exporter = ExcelExporter(semester)
54 
55     if 'all' in request.GET:
56         exporter.export(response, True)
57     else:
58         exporter.export(response)
59 
60     return response
61 
62 
63 @login_required
64 def course_detail(request, semester_id, course_id):
65     semester = get_object_or_404(Semester, id=semester_id)
66     
67     # staff can see preview of results even when course is not published
68     if request.user.is_staff:
69         course = get_object_or_404(semester.course_set.filter(state__in=['inEvaluation', 'evaluated', 'reviewed', 'published']), id=course_id)
70     # everyone else can only see published results
71     else:
72         course = get_object_or_404(semester.course_set.filter(state="published"), id=course_id)
73 
74     sections = calculate_results(course, request.user.is_staff)
75 
76     if (request.user.is_staff == False): # if user is not a student representative
77     # remove TextResults if user is neither the evaluated person (or a delegate) nor responsible for the course (or a delegate)
78         for section in sections:
79             if not user_can_see_textresults(request.user, course, section):
80                 for index, result in list(enumerate(section.results))[::-1]:
81                     if isinstance(section.results[index], TextResult):
82                         del section.results[index]
83 
84         # remove empty sections
85         sections = [section for section in sections if section.results]
86 
87     # show a warning if course is still in evaluation (for staff preview)
88     evaluation_warning = course.state != 'published'
89 
90     # check whether course has a sufficient number of votes for publishing it
91     sufficient_votes = course.num_voters >= settings.MIN_ANSWER_COUNT and float(course.num_voters) / course.num_participants >= settings.MIN_ANSWER_PERCENTAGE
92 
93     # results for a course might not be visible because there are not enough answers
94     # but it can still be "published" e.g. to show the comment results to lecturers
95     # the FSR can still see all results but gets a warning message
96     sufficient_votes_warning = (not sufficient_votes) and request.user.is_staff
97 
98     return render_to_response(
99         "results_course_detail.html",
100         dict(
101             course=course,
102             sections=sections,
103             evaluation_warning=evaluation_warning,
104             sufficient_votes_warning=sufficient_votes_warning
105         ),
106         context_instance=RequestContext(request))
107 
108 
109 def user_can_see_textresults(user, course, section):
110     if section.contributor == user:
111         return True
112     if course.is_user_responsible_or_delegate(user):
113         return True
114 
115     represented_userprofiles = user.represented_users.all()
116     represented_users = [profile.user for profile in represented_userprofiles]
117     if section.contributor in represented_users:
118         return True
119 
120     return False
121
```
--- 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/results/views.py b/evap/results/views.py
--- a/evap/results/views.py
+++ b/evap/results/views.py
@@ -95,6 +95,9 @@
     # the FSR can still see all results but gets a warning message
     sufficient_votes_warning = (not sufficient_votes) and request.user.is_staff
 
+    course.avg_grade, course.med_grade = calculate_average_and_medium_grades(course)
+    course.can_publish_grades = can_publish_grades(course, request.user.is_staff)
+
     return render_to_response(
         "results_course_detail.html",
         dict(

{"golden_diff": "diff --git a/evap/results/views.py b/evap/results/views.py\n--- a/evap/results/views.py\n+++ b/evap/results/views.py\n@@ -95,6 +95,9 @@\n     # the FSR can still see all results but gets a warning message\n     sufficient_votes_warning = (not sufficient_votes) and request.user.is_staff\n \n+    course.avg_grade, course.med_grade = calculate_average_and_medium_grades(course)\n+    course.can_publish_grades = can_publish_grades(course, request.user.is_staff)\n+\n     return render_to_response(\n         \"results_course_detail.html\",\n         dict(\n", "issue": "Result detail pages need to show total grades and participation\nThe `results/course_detail` pages should again show the information that is already given on the overview page (average and medium grades and participation).\n\n", "before_files": [{"content": "from django.conf import settings\nfrom django.http import HttpResponse\nfrom django.shortcuts import get_object_or_404, render_to_response\nfrom django.template import RequestContext\nfrom django.utils.translation import get_language\n\nfrom evap.evaluation.auth import login_required, fsr_required\nfrom evap.evaluation.models import Semester\nfrom evap.evaluation.tools import calculate_results, calculate_average_and_medium_grades, TextResult, can_publish_grades\n\nfrom evap.results.exporters import ExcelExporter\n\n\n@login_required\ndef index(request):\n    semesters = Semester.get_all_with_published_courses()\n\n    return render_to_response(\n        \"results_index.html\",\n        dict(semesters=semesters),\n        context_instance=RequestContext(request))\n\n\n@login_required\ndef semester_detail(request, semester_id):\n    semester = get_object_or_404(Semester, id=semester_id)\n    courses = list(semester.course_set.filter(state=\"published\"))\n\n    # annotate each course object with its grades\n    for course in courses:\n        # first, make sure that there are no preexisting grade attributes\n        course.avg_grade, course.med_grade = calculate_average_and_medium_grades(course)\n        course.can_publish_grades = can_publish_grades(course, request.user.is_staff)\n\n    return render_to_response(\n        \"results_semester_detail.html\",\n        dict(\n            semester=semester,\n            courses=courses\n        ),\n        context_instance=RequestContext(request))\n\n\n@fsr_required\ndef semester_export(request, semester_id):\n    semester = get_object_or_404(Semester, id=semester_id)\n\n    filename = \"Evaluation-%s-%s.xls\" % (semester.name, get_language())\n\n    response = HttpResponse(mimetype=\"application/vnd.ms-excel\")\n    response[\"Content-Disposition\"] = \"attachment; filename=\\\"%s\\\"\" % filename\n\n    exporter = ExcelExporter(semester)\n\n    if 'all' in request.GET:\n        exporter.export(response, True)\n    else:\n        exporter.export(response)\n\n    return response\n\n\n@login_required\ndef course_detail(request, semester_id, course_id):\n    semester = get_object_or_404(Semester, id=semester_id)\n    \n    # staff can see preview of results even when course is not published\n    if request.user.is_staff:\n        course = get_object_or_404(semester.course_set.filter(state__in=['inEvaluation', 'evaluated', 'reviewed', 'published']), id=course_id)\n    # everyone else can only see published results\n    else:\n        course = get_object_or_404(semester.course_set.filter(state=\"published\"), id=course_id)\n\n    sections = calculate_results(course, request.user.is_staff)\n\n    if (request.user.is_staff == False): # if user is not a student representative\n    # remove TextResults if user is neither the evaluated person (or a delegate) nor responsible for the course (or a delegate)\n        for section in sections:\n            if not user_can_see_textresults(request.user, course, section):\n                for index, result in list(enumerate(section.results))[::-1]:\n                    if isinstance(section.results[index], TextResult):\n                        del section.results[index]\n\n        # remove empty sections\n        sections = [section for section in sections if section.results]\n\n    # show a warning if course is still in evaluation (for staff preview)\n    evaluation_warning = course.state != 'published'\n\n    # check whether course has a sufficient number of votes for publishing it\n    sufficient_votes = course.num_voters >= settings.MIN_ANSWER_COUNT and float(course.num_voters) / course.num_participants >= settings.MIN_ANSWER_PERCENTAGE\n\n    # results for a course might not be visible because there are not enough answers\n    # but it can still be \"published\" e.g. to show the comment results to lecturers\n    # the FSR can still see all results but gets a warning message\n    sufficient_votes_warning = (not sufficient_votes) and request.user.is_staff\n\n    return render_to_response(\n        \"results_course_detail.html\",\n        dict(\n            course=course,\n            sections=sections,\n            evaluation_warning=evaluation_warning,\n            sufficient_votes_warning=sufficient_votes_warning\n        ),\n        context_instance=RequestContext(request))\n\n\ndef user_can_see_textresults(user, course, section):\n    if section.contributor == user:\n        return True\n    if course.is_user_responsible_or_delegate(user):\n        return True\n\n    represented_userprofiles = user.represented_users.all()\n    represented_users = [profile.user for profile in represented_userprofiles]\n    if section.contributor in represented_users:\n        return True\n\n    return False\n", "path": "evap/results/views.py"}], "after_files": [{"content": "from django.conf import settings\nfrom django.http import HttpResponse\nfrom django.shortcuts import get_object_or_404, render_to_response\nfrom django.template import RequestContext\nfrom django.utils.translation import get_language\n\nfrom evap.evaluation.auth import login_required, fsr_required\nfrom evap.evaluation.models import Semester\nfrom evap.evaluation.tools import calculate_results, calculate_average_and_medium_grades, TextResult, can_publish_grades\n\nfrom evap.results.exporters import ExcelExporter\n\n\n@login_required\ndef index(request):\n    semesters = Semester.get_all_with_published_courses()\n\n    return render_to_response(\n        \"results_index.html\",\n        dict(semesters=semesters),\n        context_instance=RequestContext(request))\n\n\n@login_required\ndef semester_detail(request, semester_id):\n    semester = get_object_or_404(Semester, id=semester_id)\n    courses = list(semester.course_set.filter(state=\"published\"))\n\n    # annotate each course object with its grades\n    for course in courses:\n        # first, make sure that there are no preexisting grade attributes\n        course.avg_grade, course.med_grade = calculate_average_and_medium_grades(course)\n        course.can_publish_grades = can_publish_grades(course, request.user.is_staff)\n\n    return render_to_response(\n        \"results_semester_detail.html\",\n        dict(\n            semester=semester,\n            courses=courses\n        ),\n        context_instance=RequestContext(request))\n\n\n@fsr_required\ndef semester_export(request, semester_id):\n    semester = get_object_or_404(Semester, id=semester_id)\n\n    filename = \"Evaluation-%s-%s.xls\" % (semester.name, get_language())\n\n    response = HttpResponse(mimetype=\"application/vnd.ms-excel\")\n    response[\"Content-Disposition\"] = \"attachment; filename=\\\"%s\\\"\" % filename\n\n    exporter = ExcelExporter(semester)\n\n    if 'all' in request.GET:\n        exporter.export(response, True)\n    else:\n        exporter.export(response)\n\n    return response\n\n\n@login_required\ndef course_detail(request, semester_id, course_id):\n    semester = get_object_or_404(Semester, id=semester_id)\n    \n    # staff can see preview of results even when course is not published\n    if request.user.is_staff:\n        course = get_object_or_404(semester.course_set.filter(state__in=['inEvaluation', 'evaluated', 'reviewed', 'published']), id=course_id)\n    # everyone else can only see published results\n    else:\n        course = get_object_or_404(semester.course_set.filter(state=\"published\"), id=course_id)\n\n    sections = calculate_results(course, request.user.is_staff)\n\n    if (request.user.is_staff == False): # if user is not a student representative\n    # remove TextResults if user is neither the evaluated person (or a delegate) nor responsible for the course (or a delegate)\n        for section in sections:\n            if not user_can_see_textresults(request.user, course, section):\n                for index, result in list(enumerate(section.results))[::-1]:\n                    if isinstance(section.results[index], TextResult):\n                        del section.results[index]\n\n        # remove empty sections\n        sections = [section for section in sections if section.results]\n\n    # show a warning if course is still in evaluation (for staff preview)\n    evaluation_warning = course.state != 'published'\n\n    # check whether course has a sufficient number of votes for publishing it\n    sufficient_votes = course.num_voters >= settings.MIN_ANSWER_COUNT and float(course.num_voters) / course.num_participants >= settings.MIN_ANSWER_PERCENTAGE\n\n    # results for a course might not be visible because there are not enough answers\n    # but it can still be \"published\" e.g. to show the comment results to lecturers\n    # the FSR can still see all results but gets a warning message\n    sufficient_votes_warning = (not sufficient_votes) and request.user.is_staff\n\n    course.avg_grade, course.med_grade = calculate_average_and_medium_grades(course)\n    course.can_publish_grades = can_publish_grades(course, request.user.is_staff)\n\n    return render_to_response(\n        \"results_course_detail.html\",\n        dict(\n            course=course,\n            sections=sections,\n            evaluation_warning=evaluation_warning,\n            sufficient_votes_warning=sufficient_votes_warning\n        ),\n        context_instance=RequestContext(request))\n\n\ndef user_can_see_textresults(user, course, section):\n    if section.contributor == user:\n        return True\n    if course.is_user_responsible_or_delegate(user):\n        return True\n\n    represented_userprofiles = user.represented_users.all()\n    represented_users = [profile.user for profile in represented_userprofiles]\n    if section.contributor in represented_users:\n        return True\n\n    return False\n", "path": "evap/results/views.py"}]}