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
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:
{% block body %}
<h1>{% if marked %}Ocenione odpowiedzi{% else %}Odpowiedzi do oceny{% endif %}</h1>
<h2>{{ assignment.title }} (max {{ assignment.max_points }} pkt)</h2>
- <p><strong>{% if assignment.is_active %}Możliwość oceniania zostanie włączona po terminie wysyłania rozwiązań</strong>{% endif %}</p>
- {% if not assignment.is_active %}
+ {% if assignment.is_active %}
+ <p><strong>Możliwość oceniania zostanie włączona po terminie wysyłania rozwiązań</strong></p>
+ {% else %}
{% if marked %}
<p><a href="{% url 'stage2_answer_list' assignment.id %}">Przejdź do odpowiedzi do oceny</a></p>
{% else %}
{% endif %}
{% endif %}
<p>{% if not marked and not assignment.is_active %}Pozostało {% endif %}{{ answers|length }} odpowiedzi</p>
+ {% if field_counts %}
+ <ul>
+ {% for field_name, count in field_counts %}
+ <li>{{ field_name }}: {{ count }} odpowiedzi</li>
+ {% endfor %}
+ </ul>
+ {% endif %}
{% for answer in answers %}
<h3>{{ answer.participant }}</h3>
+ {% for label, value in answer.fields %}
+ <p>
+ <strong>{{ label }}</strong>: {{ value }}
+ </p>
+ {% endfor %}
{% for label, attachment in answer.attachments %}
<p>
<strong>{{ label }}</strong>:
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):
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