Commit 74811e3d authored by Robin Sonnabend's avatar Robin Sonnabend

Generate infobox-template for mediawiki

parent e918b00e
......@@ -115,6 +115,12 @@ class ProtocolType(db.Model):
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):
__tablename__ = "protocols"
id = db.Column(db.Integer, primary_key=True)
......
......@@ -45,6 +45,23 @@ mailenv.filters["url_complete"] = url_manager.complete
mailenv.filters["datify"] = date_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 "
def parse_protocol(protocol, **kwargs):
......@@ -285,19 +302,24 @@ def parse_protocol_async_inner(protocol, encoded_kwargs):
compile(latex_source, protocol, show_private=show_private, maxdepth=maxdepth)
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")
push_to_wiki(protocol, wiki_source, "Automatisch generiert vom Protokollsystem 3.0")
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")
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
db.session.commit()
def push_to_wiki(protocol, content, summary):
push_to_wiki_async.delay(protocol.id, content, summary)
def push_to_wiki(protocol, content, infobox_content, summary):
push_to_wiki_async.delay(protocol.id, content, infobox_content, summary)
@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():
protocol = Protocol.query.filter_by(id=protocol_id).first()
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(
title=protocol.get_wiki_title(),
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>
}}
{#
{{'{{'}}Infobox Protokoll
| name = {{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 %}
{% if protocol.author is not none %}
| protokollant = {{protocol.author}}
{% 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 %}
{{<var>protocol.protocoltype.get_wiki_infobox()</var>
| name = <var>protocol.protocoltype.name</var>
<env> if protocol.date is not none </env>
| datum = <var>protocol.date|datify_long</var>
<env> endif </env>
<env> if protocol.start_time is not none and protocol.end_time is not none </env>
| zeit = von <var>protocol.start_time|timify</var> bis <var>protocol.end_time|timify</var>
<env> endif </env>
<env> for meta in protocol.metas </env>
| <var>meta.name|lower</var> = <var>meta.value</var>
<env> endfor </env>
}}
== Beschlüsse ==
{% if protocol.decisions|length > 0 %}
{% for decision in protocol.decisions %}
* {{decision.content}}
{% endfor %}
{% else %}
<env> if protocol.decisions|length > 0 </env>
<env> for decision in protocol.decisions </env>
* <var>decision.content</var>
<env> endfor </env>
<env> else </env>
* keine Beschlüsse
{% endif %}
<env> endif </env>
{% for top in tree.children %}
{% if top|class == "Fork" %}
{{top.render(render_type=render_type, level=0, show_private=show_private, protocol=protocol)}}
{% endif %}
{% endfor %}
<env> for top in tree.children </env>
<env> if top|class == "Fork" </env>
<var>top.render(render_type=render_type, level=0, show_private=show_private, protocol=protocol)</var>
<env> endif </env>
<env> endfor </env>
[[Kategorie:{{protocol.protocoltype.wiki_category}}]]
[[Kategorie:<var>protocol.protocoltype.wiki_category</var>]]
......@@ -95,7 +95,7 @@ class WikiClient:
req = requests.post(self.endpoint, cookies=self.cookies, data=data, params=params)
if req.status_code != HTTP_STATUS_OK:
raise WikiException("HTTP status code {} on action {}.".format(req.status_code, action))
self.cookies = req.cookies
self.cookies.update(req.cookies)
return req.json()
def main():
......
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