From de60a37ddc37314cd50e9b378968e6f9c96db26b Mon Sep 17 00:00:00 2001 From: Jan Szejko Date: Tue, 16 Jan 2018 10:34:59 +0100 Subject: [PATCH] fields on answer list --- stage2/models.py | 17 +++++++++++++++-- stage2/templates/stage2/answer_list.html | 17 +++++++++++++++-- stage2/views.py | 9 ++++++--- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/stage2/models.py b/stage2/models.py index c21c53a..fb50152 100644 --- a/stage2/models.py +++ b/stage2/models.py @@ -81,9 +81,13 @@ class Assignment(models.Model): return self.title def available_answers(self, expert): - answers = self.answer_set.exclude(mark__expert=expert).filter(participant__complete_set=True) + answers = self.answer_set.exclude(mark__expert=expert) + answers = answers.extra(where=[ + "field_values::text ~ ': *\"[^\"]+\"' " + "OR EXISTS (SELECT id FROM stage2_attachment WHERE answer_id = stage2_answer.id) " + "OR EXISTS (SELECT id FROM stage2_fieldoption WHERE answer_id = stage2_answer.id)"]) if expert not in self.supervisors.all(): - answers = answers.exclude(complete=True) + answers = answers.exclude(complete=True).filter(participant__complete_set=True) if expert in self.arbiters.all(): answers = answers.filter(need_arbiter=True) return answers @@ -103,6 +107,15 @@ class Answer(models.Model): class Meta: unique_together = ['participant', 'assignment'] + def fields(self): + for field_desc in self.assignment.field_descriptions: + field_name, params = field_desc + if params['type'] == 'text': + yield (field_name, self.field_values.get(field_name, '')) + else: # options + option = self.fieldoption_set.filter(set__name=params['option_set']) + yield (field_name, option.get().value if option else '--------') + def update_complete(self): marks = self.mark_set.all() if len(marks) < 2: diff --git a/stage2/templates/stage2/answer_list.html b/stage2/templates/stage2/answer_list.html index 8a3cf3c..c0f7dc8 100644 --- a/stage2/templates/stage2/answer_list.html +++ b/stage2/templates/stage2/answer_list.html @@ -4,8 +4,9 @@ {% block body %}

{% if marked %}Ocenione odpowiedzi{% else %}Odpowiedzi do oceny{% endif %}

{{ assignment.title }} (max {{ assignment.max_points }} pkt)

-

{% if assignment.is_active %}Możliwość oceniania zostanie włączona po terminie wysyłania rozwiązań{% endif %}

- {% if not assignment.is_active %} + {% if assignment.is_active %} +

Możliwość oceniania zostanie włączona po terminie wysyłania rozwiązań

+ {% else %} {% if marked %}

Przejdź do odpowiedzi do oceny

{% else %} @@ -13,8 +14,20 @@ {% endif %} {% endif %}

{% if not marked and not assignment.is_active %}Pozostało {% endif %}{{ answers|length }} odpowiedzi

+ {% if field_counts %} + + {% endif %} {% for answer in answers %}

{{ answer.participant }}

+ {% for label, value in answer.fields %} +

+ {{ label }}: {{ value }} +

+ {% endfor %} {% for label, attachment in answer.attachments %}

{{ label }}: diff --git a/stage2/views.py b/stage2/views.py index 093a824..22eeda4 100644 --- a/stage2/views.py +++ b/stage2/views.py @@ -11,7 +11,7 @@ from django.views.decorators.http import require_POST from unidecode import unidecode from stage2.forms import AttachmentForm, MarkForm, AssignmentFieldForm -from stage2.models import Participant, Assignment, Answer, Attachment, Mark +from stage2.models import Participant, Assignment, Answer, Attachment, Mark, FieldOption def all_assignments(participant, sent_forms): @@ -152,8 +152,11 @@ def answer_list(request, assignment_id): assignment = get_object_or_404(Assignment, id=assignment_id) if request.user not in assignment.experts.all(): return HttpResponseForbidden('Not allowed') - return render(request, 'stage2/answer_list.html', - {'answers': available_answers(assignment, request.user), 'assignment': assignment}) + answers = available_answers(assignment, request.user) + return render(request, 'stage2/answer_list.html', { + 'answers': answers, + 'assignment': assignment, + }) @login_required -- 2.20.1