From 98e5a26514268552564b51d3ff2f3823b3b079e1 Mon Sep 17 00:00:00 2001 From: SouthFox Date: Thu, 1 Dec 2022 11:55:23 +0800 Subject: [PATCH] feat/render file --- BDSM/commands.py | 82 ++++++++++++++++++++++++++++++++++++++++ BDSM/templates/toot.html | 80 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 BDSM/templates/toot.html diff --git a/BDSM/commands.py b/BDSM/commands.py index 447bee1..1f6dbcb 100644 --- a/BDSM/commands.py +++ b/BDSM/commands.py @@ -16,6 +16,88 @@ def initdb(drop): db.create_all() click.echo('Initialized database.') +@app.cli.command() +def renderfile(): + """render toot""" + from BDSM.models import Toot + from BDSM.views import process_toot + from jinja2 import Environment, FileSystemLoader + + head = ''' + + + + + + ''' + def render_toot(toot_id): + _toot = [] + toot = Toot.query.get(toot_id) + + if toot == None: + return "None" + + _toot.append(toot) + _toot = process_toot(_toot) + env = Environment(loader=FileSystemLoader("./BDSM/templates")) + jinja_template = env.get_template("toot.html") + template_string = jinja_template.render(toots=_toot) + return template_string + + def _render(input_file): + env = Environment(loader=FileSystemLoader("./")) + jinja_template = env.get_template(input_file) + jinja_template.globals.update(render_toot=render_toot) + template_string = jinja_template.render() + + with open('./output.html', 'w') as f: + f.write(head + template_string + '') + + _render("input.txt") + print("Done?") + @app.cli.command() def graball(): """Grab all toots context""" diff --git a/BDSM/templates/toot.html b/BDSM/templates/toot.html new file mode 100644 index 0000000..07be636 --- /dev/null +++ b/BDSM/templates/toot.html @@ -0,0 +1,80 @@ +{% for toot in toots recursive%} +
+
+ +
+ {% if toot.spoiler_text != "" %} + CW: {{toot.spoiler_text|safe}} + {% endif %} + {{ toot.content|safe }} +
+ +
+
+ {% if toot.medias %} + + {% for media in toot.medias%} + {% if media.type == 'image' %} +
+ + {{ media.description }} +
+ {% endif %} + {% endfor%} + {% endif %} +
+
+
+
+ {% if toot.replies_count %} + ↩️ {{ toot.replies_count }} + {% else %} + ↩️ {{ toot.replies_count }} + {% endif %} + + {% if toot.reblogged %} + πŸ”„ {{ toot.reblogs_count}} + {% else %} + πŸ”„ {{ toot.reblogs_count}} + {% endif %} + + {% if toot.favourited %} + ⭐ {{ toot.favourites_count }} + {% else %} + ⭐ {{ toot.favourites_count }} + {% endif %} + + {% if toot.bookmarked %} + πŸ”– + {% endif %} +
+
+
+
+ {%- if toot.reply -%} +
{{ loop(toot.reply) }}
+ {%- endif %} +{% endfor %}