Skip to content
Snippets Groups Projects
Commit 74811e3d authored by Robin Sonnabend's avatar Robin Sonnabend
Browse files

Generate infobox-template for mediawiki

parent e918b00e
Branches
No related tags found
No related merge requests found
...@@ -115,6 +115,12 @@ class ProtocolType(db.Model): ...@@ -115,6 +115,12 @@ class ProtocolType(db.Model):
if protocoltype.has_private_view_right(user) if protocoltype.has_private_view_right(user)
] ]
def get_wiki_infobox(self):
return "Infobox {}".format(self.short_name)
def get_wiki_infobox_title(self):
return "Vorlage:{}".format(self.get_wiki_infobox())
class Protocol(db.Model): class Protocol(db.Model):
__tablename__ = "protocols" __tablename__ = "protocols"
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
......
...@@ -45,6 +45,23 @@ mailenv.filters["url_complete"] = url_manager.complete ...@@ -45,6 +45,23 @@ mailenv.filters["url_complete"] = url_manager.complete
mailenv.filters["datify"] = date_filter mailenv.filters["datify"] = date_filter
mailenv.filters["datetimify"] = datetime_filter mailenv.filters["datetimify"] = datetime_filter
wikienv = app.create_jinja_environment()
wikienv.trim_blocks = True
wikienv.lstrip_blocks = True
wikienv.block_start_string = "<env>"
wikienv.block_end_string = "</env>"
wikienv.variable_start_string = "<var>"
wikienv.variable_end_string = "</var>"
wikienv.comment_start_string = "<comment>"
wikienv.comment_end_string = "</comment>"
wikienv.filters["datify"] = date_filter
wikienv.filters["datify_long"] = date_filter_long
wikienv.filters["datify_short"] = date_filter_short
wikienv.filters["datetimify"] = datetime_filter
wikienv.filters["timify"] = time_filter
wikienv.filters["class"] = class_filter
ID_FIELD_BEGINNING = "id " ID_FIELD_BEGINNING = "id "
def parse_protocol(protocol, **kwargs): def parse_protocol(protocol, **kwargs):
...@@ -285,19 +302,24 @@ def parse_protocol_async_inner(protocol, encoded_kwargs): ...@@ -285,19 +302,24 @@ def parse_protocol_async_inner(protocol, encoded_kwargs):
compile(latex_source, protocol, show_private=show_private, maxdepth=maxdepth) compile(latex_source, protocol, show_private=show_private, maxdepth=maxdepth)
if protocol.protocoltype.use_wiki: if protocol.protocoltype.use_wiki:
wiki_source = render_template("protocol.wiki", render_type=RenderType.wikitext, show_private=not protocol.protocoltype.wiki_only_public, **render_kwargs).replace("\n\n\n", "\n\n") wiki_source = wikienv.get_template("protocol.wiki").render(render_type=RenderType.wikitext, show_private=not protocol.protocoltype.wiki_only_public, **render_kwargs).replace("\n\n\n", "\n\n")
push_to_wiki(protocol, wiki_source, "Automatisch generiert vom Protokollsystem 3.0") wiki_infobox_source = wikienv.get_template("infobox.wiki").render(protocoltype=protocol.protocoltype)
push_to_wiki(protocol, wiki_source, wiki_infobox_source, "Automatisch generiert vom Protokollsystem 3.0")
protocol.done = True protocol.done = True
db.session.commit() db.session.commit()
def push_to_wiki(protocol, content, summary): def push_to_wiki(protocol, content, infobox_content, summary):
push_to_wiki_async.delay(protocol.id, content, summary) push_to_wiki_async.delay(protocol.id, content, infobox_content, summary)
@celery.task @celery.task
def push_to_wiki_async(protocol_id, content, summary): def push_to_wiki_async(protocol_id, content, infobox_content, summary):
with WikiClient() as wiki_client, app.app_context(): with WikiClient() as wiki_client, app.app_context():
protocol = Protocol.query.filter_by(id=protocol_id).first() protocol = Protocol.query.filter_by(id=protocol_id).first()
try: try:
wiki_client.edit_page(
title=protocol.protocoltype.get_wiki_infobox_title(),
content=infobox_content,
summary="Automatisch generiert vom Protokollsystem 3.")
wiki_client.edit_page( wiki_client.edit_page(
title=protocol.get_wiki_title(), title=protocol.get_wiki_title(),
content=content, content=content,
......
{{Infobox
| Titel = {{{name|<includeonly>{{PAGENAMEBASE}}</includeonly>}}}
| Feldname1 = Datum
| Daten1 = {{{datum|}}}
| Feldname2 = Zeit
| Daten2 = {{{zeit|}}}
<env> for meta in protocoltype.metas </env>
| Feldname<var>loop.index + 2</var> = <var>meta.name</var>
| Daten<var>loop.index + 2</var> = {{{<var>meta.name|lower</var>|}}}
<env> endfor </env>
}}
{# {{<var>protocol.protocoltype.get_wiki_infobox()</var>
{{'{{'}}Infobox Protokoll | name = <var>protocol.protocoltype.name</var>
| name = {{protocol.protocoltype.name}} <env> if protocol.date is not none </env>
{% if protocol.date is not none %} | datum = <var>protocol.date|datify_long</var>
| datum = {{protocol.date|datify_long}} <env> endif </env>
{% endif %} <env> if protocol.start_time is not none and protocol.end_time is not none </env>
{% if protocol.start_time is not none and protocol.end_time is not none %} | zeit = von <var>protocol.start_time|timify</var> bis <var>protocol.end_time|timify</var>
| zeit = von {{protocol.start_time|timify}} bis {{protocol.end_time|timify}} <env> endif </env>
{% endif %} <env> for meta in protocol.metas </env>
{% if protocol.author is not none %} | <var>meta.name|lower</var> = <var>meta.value</var>
| protokollant = {{protocol.author}} <env> endfor </env>
{% endif %} }}
{% if protocol.participants is not none %}
| anwesende = {{protocol.participants}}
{% endif %}
{{'}}'}}
#}
'''{{protocol.protocoltype.name}}'''
{% if protocol.date is not none %}
Datum: '''{{protocol.date|datify_long}}'''
{% endif %}
{% if protocol.start_time is not none and protocol.end_time is not none %}
Zeit: '''von {{protocol.start_time|timify}} bis {{protocol.end_time|timify}}'''
{% endif %}
{% for meta in protocol.metas %}
{{meta.name}}: '''{{meta.value}}'''
{% endfor %}
== Beschlüsse == == Beschlüsse ==
{% if protocol.decisions|length > 0 %} <env> if protocol.decisions|length > 0 </env>
{% for decision in protocol.decisions %} <env> for decision in protocol.decisions </env>
* {{decision.content}} * <var>decision.content</var>
{% endfor %} <env> endfor </env>
{% else %} <env> else </env>
* keine Beschlüsse * keine Beschlüsse
{% endif %} <env> endif </env>
{% for top in tree.children %} <env> for top in tree.children </env>
{% if top|class == "Fork" %} <env> if top|class == "Fork" </env>
{{top.render(render_type=render_type, level=0, show_private=show_private, protocol=protocol)}} <var>top.render(render_type=render_type, level=0, show_private=show_private, protocol=protocol)</var>
{% endif %} <env> endif </env>
{% endfor %} <env> endfor </env>
[[Kategorie:{{protocol.protocoltype.wiki_category}}]] [[Kategorie:<var>protocol.protocoltype.wiki_category</var>]]
...@@ -95,7 +95,7 @@ class WikiClient: ...@@ -95,7 +95,7 @@ class WikiClient:
req = requests.post(self.endpoint, cookies=self.cookies, data=data, params=params) req = requests.post(self.endpoint, cookies=self.cookies, data=data, params=params)
if req.status_code != HTTP_STATUS_OK: if req.status_code != HTTP_STATUS_OK:
raise WikiException("HTTP status code {} on action {}.".format(req.status_code, action)) raise WikiException("HTTP status code {} on action {}.".format(req.status_code, action))
self.cookies = req.cookies self.cookies.update(req.cookies)
return req.json() return req.json()
def main(): def main():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment