+def get_attachment_forms(assignment, participant, request):
+ all_valid = True
+ attachment_forms = []
+ for i, (label, ext) in enumerate(assignment.file_descriptions, 1):
+ answer, created = Answer.objects.get_or_create(participant=participant, assignment=assignment)
+ attachment, created = Attachment.objects.get_or_create(answer=answer, file_no=i)
+ form = AttachmentForm(
+ data=request.POST, files=request.FILES,
+ assignment=assignment, file_no=i, label=label, instance=attachment, extensions=ext)
+ if form.is_valid():
+ form.save()
+ else:
+ all_valid = False
+ attachment_forms.append(form)
+ return all_valid, attachment_forms
+
+
+def get_field_forms(assignment, participant, request):
+ all_valid = True
+ field_forms = []
+ for i, (label, options) in enumerate(assignment.field_descriptions, 1):
+ answer = Answer.objects.get(participant=participant, assignment=assignment)
+ form = AssignmentFieldForm(data=request.POST, label=label, field_no=i, options=options, answer=answer)
+ if form.is_valid():
+ form.save()
+ else:
+ all_valid = False
+ field_forms.append(form)
+ return all_valid, field_forms
+
+