Commit d019a169 authored by LammLukas's avatar LammLukas

Implemented make_docx_protocol in class protocol

parent 6b91b7f6
......@@ -3,8 +3,6 @@ Class for protocol objects
Author: L. Lamm (lamm@ifam.rwth-aachen.de)
"""
from src.exam import Exam
from src.exceptions import *
from docxtpl import DocxTemplate
import re
......@@ -26,28 +24,44 @@ class Protocol:
def make_docx_protocol(self, file, lang):
"""Export docx protocol from template"""
if lang == 'german':
doc = DocxTemplate("./templates/protocols/protocol_german_written.docx")
template_file = "./templates/protocols/protocol_german_written.docx"
else:
raise ProtocolTemplateDoesNotExist()
for room in self.exam.Rooms:
split_str = re.sub("\.docx$", '', file)
file_str = split_str + '_' + room.Name + '.docx'
if room.SupervisorInCharge is None:
supervisor = ''
else:
supervisor = room.SupervisorInCharge
if room.ExtraSupervisors is None:
ex_supervisor = ''
else:
ex_supervisor = room.SupervisorInCharge
context = {'COURSE': self.exam.Name,
'EXAMINER': self.exam.Examiner,
'DATE': self.exam.Date,
'ROOM': room.Name,
'SUPERVISOR': supervisor,
'EX_SUPERVISORS': ex_supervisor}
doc.render(context)
doc.save(file_str)
\ No newline at end of file
if len(room.AssignedParticipants) > 0:
doc = DocxTemplate(template_file)
split_str = re.sub("\.docx$", '', file)
file_str = split_str + '_' + room.Name + '.docx'
if room.SupervisorInCharge is None:
supervisor = ''
else:
supervisor = room.SupervisorInCharge
if room.ExtraSupervisors is None:
ex_supervisor = ''
else:
ex_supervisor = room.SupervisorInCharge
participant_list = []
for participant in room.AssignedParticipants:
attributes = [str(participant.Matriculation),
str(participant.Lastname),
str(participant.Firstname),
str(participant.NumberOfTrials)]
participant_list.append({'cols': attributes})
context = {'COURSE': self.exam.Name,
'EXAMINER': self.exam.Examiner,
'DATE': self.exam.Date,
'ROOM': room.Name,
'SUPERVISOR': supervisor,
'EX_SUPERVISORS': ex_supervisor,
'NUM_PARTICIPANTS': len(room.AssignedParticipants),
'col_labels': ['Matr.-Nr.', 'Nachname', 'Vorname', 'Versuch'],
'tbl_contents': participant_list
}
doc.render(context)
doc.save(file_str)
del doc
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment