Repository: e-valuation/EvaP

Issue:
Fix results view for courses where results can't be published
The results page for a course where the results can't be published because it didn't get enough votes is not displayed correctly:
- Contributors can't see any non-text answers (that's correct) - but not all contributor cards are collapsed accordingly. If at least one vote exists, the respective contributor card is open, the warning text is not shown and no useful information is shown inside the card (see screenshot 1). The card should be closed in this case.
- Staff users initially see the "public" view and can change the view to `Myself`. On results pages of courses that didn't get enough votes, the `Public` button is missing (that was by design, because a public view does not exist for these courses) - now it's confusing because the initial view is something that's not accessible via the buttons.

Screenshot 1 (Contributor):
![cardopen](https://user-images.githubusercontent.com/1781719/34488419-c82cd8d0-efd8-11e7-8f09-0c4ff0f06739.PNG)

Screenshot 2 (Staff):
![viewbtn](https://user-images.githubusercontent.com/1781719/34488426-cd684118-efd8-11e7-80ba-c05e1ff34f93.PNG)



Discussion:

Resolving patch:
diff --git a/evap/results/views.py b/evap/results/views.py
--- a/evap/results/views.py
+++ b/evap/results/views.py
@@ -6,7 +6,8 @@
 
 from evap.evaluation.models import Semester, Degree, Contribution
 from evap.evaluation.auth import internal_required
-from evap.results.tools import calculate_results, calculate_average_grades_and_deviation, TextResult, RatingResult, HeadingResult, COMMENT_STATES_REQUIRED_FOR_VISIBILITY
+from evap.results.tools import calculate_results, calculate_average_grades_and_deviation, TextResult, RatingResult, \
+    HeadingResult, COMMENT_STATES_REQUIRED_FOR_VISIBILITY, YesNoResult
 
 
 @internal_required
@@ -64,9 +65,15 @@ def course_detail(request, semester_id, course_id):
     else:
         public_view = request.GET.get('public_view') == 'true'  # if parameter is not given, show own view.
 
+    # If grades are not published, there is no public view
+    if not course.can_publish_grades:
+        public_view = False
+
     represented_users = list(request.user.represented_users.all())
     represented_users.append(request.user)
 
+    show_grades = request.user.is_reviewer or course.can_publish_grades
+
     # filter text answers
     for section in sections:
         results = []
@@ -106,11 +113,13 @@ def course_detail(request, semester_id, course_id):
             contributor_sections.setdefault(section.contributor,
                                             {'total_votes': 0, 'sections': []})['sections'].append(section)
 
-            # Sum up all Sections for this contributor.
-            # If section is not a RatingResult:
-            # Add 1 as we assume it is a TextResult or something similar that should be displayed.
-            contributor_sections[section.contributor]['total_votes'] +=\
-                sum([s.total_count if isinstance(s, RatingResult) else 1 for s in section.results])
+            for result in section.results:
+                if isinstance(result, TextResult):
+                    contributor_sections[section.contributor]['total_votes'] += 1
+                elif isinstance(result, RatingResult) or isinstance(result, YesNoResult):
+                    # Only count rating results if we show the grades.
+                    if show_grades:
+                        contributor_sections[section.contributor]['total_votes'] += result.total_count
 
     # Show a warning if course is still in evaluation (for reviewer preview).
     evaluation_warning = course.state != 'published'
@@ -120,8 +129,6 @@ def course_detail(request, semester_id, course_id):
     # Users who can open the results page see a warning message in this case.
     sufficient_votes_warning = not course.can_publish_grades
 
-    show_grades = request.user.is_reviewer or course.can_publish_grades
-
     course.avg_grade, course.avg_deviation = calculate_average_grades_and_deviation(course)
 
     template_data = dict(


Test patch: