Commit 0e8054d8 authored by LammLukas's avatar LammLukas
Browse files

Added protocol class with docx export

parent bff94528
Class for protocol objects
Author: L. Lamm (
from src.exam import Exam
from src.exceptions import *
from docxtpl import DocxTemplate
import re
class Protocol:
"""Class for objects of type protocol"""
def __init__(self, exam):
"""Constructor of protocol object"""
self.exam = exam
def make_protocol(self, file, doc_format='docx', lang='german'):
"""Exports protocol"""
if doc_format == 'docx':
self.make_docx_protocol(file, lang)
raise FormatNotDefined()
def make_docx_protocol(self, file, lang):
"""Export docx protocol from template"""
if lang == 'german':
doc = DocxTemplate("./templates/protocols/protocol_german_written.docx")
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 = ''
supervisor = room.SupervisorInCharge
if room.ExtraSupervisors is None:
ex_supervisor = ''
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}
\ No newline at end of file
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