Repository: e-valuation/EvaP

Issue:
Export contains unpublished results even if option is not checked
The excel export of results contains columns for unpublished courses and shows a total grade even if the export option "Include courses where not enough answers where given in the export" is not selected.

In this situation, the course should not be contained in the export.



Discussion:

Resolving patch:
diff --git a/evap/results/exporters.py b/evap/results/exporters.py
--- a/evap/results/exporters.py
+++ b/evap/results/exporters.py
@@ -77,7 +77,7 @@ def deviation_to_style(self, deviation, total=False):
             style_name += "_total"
         return style_name
 
-    def export(self, response, course_types_list, ignore_not_enough_answers=False, include_unpublished=False):
+    def export(self, response, course_types_list, include_not_enough_answers=False, include_unpublished=False):
         self.workbook = xlwt.Workbook()
         self.init_styles(self.workbook)
         counter = 1
@@ -97,6 +97,8 @@ def export(self, response, course_types_list, ignore_not_enough_answers=False, i
             for course in self.semester.course_set.filter(state__in=course_states, type__in=course_types).all():
                 if course.is_single_result:
                     continue
+                if not course.can_publish_grades and not include_not_enough_answers:
+                    continue
                 results = OrderedDict()
                 for questionnaire, contributor, __, data, __ in calculate_results(course):
                     if has_no_rating_answers(course, contributor, questionnaire):
@@ -146,7 +148,8 @@ def export(self, response, course_types_list, ignore_not_enough_answers=False, i
                                     deviations.append(grade_result.deviation * grade_result.total_count)
                                     total_count += grade_result.total_count
                         enough_answers = course.can_publish_grades
-                        if values and (enough_answers or ignore_not_enough_answers):
+                        if values and enough_answers:
+                            print(course.name)
                             avg = sum(values) / total_count
                             writec(self, avg, self.grade_to_style(avg))
 
diff --git a/evap/staff/views.py b/evap/staff/views.py
--- a/evap/staff/views.py
+++ b/evap/staff/views.py
@@ -341,7 +341,7 @@ def semester_export(request, semester_id):
     formset = ExportSheetFormset(request.POST or None, form_kwargs={'semester': semester})
 
     if formset.is_valid():
-        ignore_not_enough_answers = request.POST.get('ignore_not_enough_answers') == 'on'
+        include_not_enough_answers = request.POST.get('include_not_enough_answers') == 'on'
         include_unpublished = request.POST.get('include_unpublished') == 'on'
         course_types_list = []
         for form in formset:
@@ -351,7 +351,7 @@ def semester_export(request, semester_id):
         filename = "Evaluation-{}-{}.xls".format(semester.name, get_language())
         response = HttpResponse(content_type="application/vnd.ms-excel")
         response["Content-Disposition"] = "attachment; filename=\"{}\"".format(filename)
-        ExcelExporter(semester).export(response, course_types_list, ignore_not_enough_answers, include_unpublished)
+        ExcelExporter(semester).export(response, course_types_list, include_not_enough_answers, include_unpublished)
         return response
     else:
         return render(request, "staff_semester_export.html", dict(semester=semester, formset=formset))


Test patch: