diff --git a/config.py.example b/config.py.example index 7dcd0a60639727197f6c2f5bf5b031efb39cb876..d23beb8f7ffb7567deb7c8a8b3ae8f782aa46603 100644 --- a/config.py.example +++ b/config.py.example @@ -172,7 +172,7 @@ LATEX_BULLETPOINTS = [ r"\textperiodcentered" ] -# optional: path to additional jinja-templates +# optional: path to additional jinja-templates, will be need in combination with LATEX_TEMPLATES #LATEX_LOCAL_TEMPLATES = "local-templates" # optional: the template to include at the top of protocol.tex #LATEX_LOGO_TEMPLATE = "asta-logo.tex" @@ -184,6 +184,22 @@ LATEX_BULLETPOINTS = [ #LATEX_ADDITIONAL_PACKAGES = ["[absolute]{textpos}", "{fancyheadings}"] # optional: include header and footer in asta-style, not just a page number on top #LATEX_HEADER_FOOTER = True +# optional: define multiple LaTeX-templates to use with a each protocol type individually overiding the general LATEX options +# the LATEX_LOCAL_TEMPLATES parameter is need to provide the path for the templates +# each template must be placed in an individual folder named by its ID in LATEX_TEMPLATES and must contain the provided template files: e.g. +# - the files for the template "yourtemplate" need to be in the folder named "yourtemplate" +# - the templates provides the files: "protokoll2.cls" (class), "protocol.tex" (protocol), "decision.tex" (decision) and "asta-logo.tex" +#LATEX_TEMPLATES = { +# "yourtemplate": { +# "name": "Dein Template", +# "provides": ["class", "protocol", "decision"], # optional: if this option is set the corresponding files must be provided +# "logo": "asta-logo.tex", # optional: replaces the general template to include at the top of protocol.tex set by LATEX_LOGO_TEMPLATE +# "geometry": "bottom=1.6cm,top=1.6cm,inner=2.5cm,outer=1.0cm,footskip=1.0cm,headsep=0.6cm", # optional: replaces the general protocol page geometry set by LATEX_GEOMETRY +# "pagestyle": "fancy", # optional: replaces the general protocol pagestyle set by LATEX_PAGESTYLE +# "additionalpackages": ["[absolute]{textpos}", "{fancyheadings}"], # optional: replaces the general latex packages set by LATEX_ADDITIONAL_PACKAGES +# "headerfooter": True # optional: replaces the general LATEX_HEADER_FOOTER option +# } +#} HTML_LEVEL_OFFSET = 3 diff --git a/models/database.py b/models/database.py index 8eed90e4384572b330fef722c2174672311bb3d0..5304fbf3c9b72d5e56b094cf42cde3a65f3b6d11 100644 --- a/models/database.py +++ b/models/database.py @@ -71,6 +71,7 @@ class ProtocolType(DatabaseModel): calendar = db.Column(db.String) restrict_networks = db.Column(db.Boolean) allowed_networks = db.Column(db.String) + latex_template = db.Column(db.String) protocols = relationship("Protocol", backref=backref("protocoltype"), cascade="all, delete-orphan", order_by="Protocol.id") default_tops = relationship("DefaultTOP", backref=backref("protocoltype"), cascade="all, delete-orphan", order_by="DefaultTOP.number") diff --git a/tasks.py b/tasks.py index dff6ad92302777ca7117a2c09374c0f15f46fc9c..852c3b48b565e716c1bcf8a44308e9562996abda 100644 --- a/tasks.py +++ b/tasks.py @@ -57,6 +57,48 @@ if latex_pagestyle is not None and latex_pagestyle: texenv.globals["latex_pagestyle"] = latex_pagestyle latex_header_footer = getattr(config, "LATEX_HEADER_FOOTER", False) texenv.globals["latex_header_footer"] = latex_header_footer +latex_templates = getattr(config, "LATEX_TEMPLATES", None) + +def provide_latex_template(template, documenttype): + _latex_template_documenttype_filename = { + "class": "protokoll2.cls", + "protocol": "protocol.tex", + "decision": "decision.tex" + } + _latex_template_filename = _latex_template_documenttype_filename[documenttype] + _latex_template_foldername = "" + if logo_template is not None: + texenv.globals["logo_template"] = logo_template + texenv.globals["latex_geometry"] = latex_geometry + texenv.globals["additional_packages"] = additional_packages + if latex_pagestyle is not None and latex_pagestyle: + texenv.globals["latex_pagestyle"] = latex_pagestyle + elif "latex_pagestyle" in texenv.globals: + del texenv.globals["latex_pagestyle"] + texenv.globals["latex_header_footer"] = latex_header_footer + if (latex_templates is not None) and (template is not ""): + if template in latex_templates: + if "provides" in latex_templates[template]: + _latex_template_foldername = (template + "/") if documenttype in latex_templates[template]["provides"] else "" + if "logo" in latex_templates[template]: + texenv.globals["logo_template"] = template + "/" + latex_templates[template]["logo"] + if "geometry" in latex_templates[template]: + texenv.globals["latex_geometry"] = latex_templates[template]["geometry"] + if "pagestyle" in latex_templates[template]: + if latex_templates[template]["pagestyle"]: + texenv.globals["latex_pagestyle"] = latex_templates[template]["pagestyle"] + if "additionalpackages" in latex_templates[template]: + _raw_additional_packages = latex_templates[template]["additionalpackages"] + _additional_packages = [] + if _raw_additional_packages is not None: + for _package in _raw_additional_packages: + if "{" not in _package: + _package = "{{{}}}".format(_package) + _additional_packages.append(_package) + texenv.globals["additional_packages"] = _additional_packages + if "headerfooter" in latex_templates[template]: + texenv.globals["latex_header_footer"] = latex_templates[template]["headerfooter"] + return _latex_template_foldername + _latex_template_filename mailenv = app.create_jinja_environment() mailenv.trim_blocks = True @@ -370,7 +412,7 @@ def parse_protocol_async_inner(protocol, encoded_kwargs): decisions_to_render.append((decision, decision_tag)) for decision, decision_tag in decisions_to_render: decision_top = decision_tag.fork.get_top() - decision_content = texenv.get_template("decision.tex").render( + decision_content = texenv.get_template(provide_latex_template(protocol.protocoltype.latex_template, "decision")).render( render_type=RenderType.latex, decision=decision, protocol=protocol, top=decision_top, show_private=True) maxdepth = decision_top.get_maxdepth() @@ -458,7 +500,7 @@ def parse_protocol_async_inner(protocol, encoded_kwargs): render_type=RenderType.html, show_private=False, **public_render_kwargs) for show_private in privacy_states: - latex_source = texenv.get_template("protocol.tex").render( + latex_source = texenv.get_template(provide_latex_template(protocol.protocoltype.latex_template, "protocol")).render( render_type=RenderType.latex, show_private=show_private, **render_kwargs[show_private]) @@ -558,7 +600,7 @@ def compile_async(content, protocol_id, show_private=False, use_decision=False, log_filename = "protocol.log" with open(os.path.join(compile_dir, protocol_source_filename), "w") as source_file: source_file.write(content) - protocol2_class_source = texenv.get_template(protocol_class_filename).render(fonts=config.FONTS, maxdepth=maxdepth, bulletpoints=config.LATEX_BULLETPOINTS) + protocol2_class_source = texenv.get_template(provide_latex_template(protocol.protocoltype.latex_template, "class")).render(fonts=config.FONTS, maxdepth=maxdepth, bulletpoints=config.LATEX_BULLETPOINTS) with open(os.path.join(compile_dir, protocol_class_filename), "w") as protocol2_class_file: protocol2_class_file.write(protocol2_class_source) os.chdir(compile_dir) diff --git a/views/forms.py b/views/forms.py index 67b39af1139c3f498e0dd4723830f535e1950063..7ec3a3f63c0b1b677ce025370710b5d36ee9cc4e 100644 --- a/views/forms.py +++ b/views/forms.py @@ -58,6 +58,18 @@ def get_printer_choices(): choices = list(zip(config.PRINTING_PRINTERS, config.PRINTING_PRINTERS)) choices.insert(0, ("", "Nicht drucken")) return choices + +def get_latex_template_choices(): + choices = [] + _latex_templates = getattr(config, "LATEX_TEMPLATES", None) + if _latex_templates is not None: + choices = [ + (key, values['name']) + for key, values + in _latex_templates.items() + ] + choices.insert(0, ("", "Standardvorlage")) + return choices def get_group_choices(): user = current_user() @@ -130,12 +142,14 @@ class ProtocolTypeForm(FlaskForm): calendar = SelectField("Kalender", choices=[]) restrict_networks = BooleanField("Netzwerke einschränken") allowed_networks = IPNetworkField("Erlaubte Netzwerke") + latex_template = SelectField("LaTeX Vorlage", choices=[]) def __init__(self, **kwargs): super().__init__(**kwargs) protocoltype = kwargs["obj"] if "obj" in kwargs else None self.calendar.choices = get_calendar_choices(protocoltype=protocoltype) self.printer.choices = get_printer_choices() + self.latex_template.choices = get_latex_template_choices() group_choices = get_group_choices() self.publish_group.choices = group_choices self.modify_group.choices = group_choices diff --git a/views/tables.py b/views/tables.py index 48842b110223cb969097624173b7363c1c3902e1..8b59ea0fc5de52d255fb5e6d3d5bec63da03771e 100644 --- a/views/tables.py +++ b/views/tables.py @@ -193,12 +193,13 @@ class ProtocolTypeTable(SingleValueTable): network_headers = ["Netzwerke einschränken", "Erlaubte Netzwerke"] action_headers = ["Aktion"] feed_headers = [] + latex_template_headers = ["LaTeX Vorlage"] if getattr(config, "LATEX_TEMPLATES", None) is not None else [] if self.value.has_public_anonymous_view_right(): feed_headers = [Markup("<img height=\"18px\" src=\"{}\" /> Feed".format( url_for("static", filename="images/feed-icon.svg")))] return (general_headers + etherpad_headers + mail_headers + printing_headers + wiki_headers + calendar_headers - + network_headers + feed_headers + action_headers) + + network_headers + latex_template_headers + feed_headers + action_headers) def row(self): user = current_user() @@ -217,7 +218,7 @@ class ProtocolTypeTable(SingleValueTable): Table.bool(self.value.non_reproducible_pad_links) ] if not config.ETHERPAD_ACTIVE: - ethernet_part = [] + etherpad_part = [] mail_part = [ self.value.private_mail, self.value.public_mail, @@ -242,6 +243,11 @@ class ProtocolTypeTable(SingleValueTable): network_part.append(", ".join(map(str.strip, self.value.allowed_networks.split(",")))) else: network_part.append("") + _latex_templates = getattr(config, "LATEX_TEMPLATES", None) + if _latex_templates is not None: + latex_template_part = [_latex_templates[self.value.latex_template]['name'] if self.value.latex_template is not (None or "") else "Standardvorlage"] + else: + latex_template_part = [] feed_part = [] if self.value.has_public_anonymous_view_right(): feed_part = [Markup(", ".join([ @@ -260,7 +266,7 @@ class ProtocolTypeTable(SingleValueTable): if not self.value.has_admin_right(user): action_part = [""] return (general_part + etherpad_part + mail_part + printing_part - + wiki_part + calendar_part + network_part + feed_part + + wiki_part + calendar_part + network_part + latex_template_part + feed_part + action_part) class DefaultTOPsTable(Table):