From f6663a7227626b85b7e0ba11e72a285e6543d16a Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 6 Jan 2019 21:04:03 +0100 Subject: [PATCH] Finito il tabellone delle quest (closes #20) --- db.py | 14 +++++++++ static/nryg.less | 45 ++++++++++++++++++++++++++++ templates/components/eventlist.html | 2 -- templates/components/quest.html | 14 +++++++++ templates/components/questboard.html | 10 +++++-- templates/main.html | 12 +++++--- webserver.py | 25 +++++++++++++++- 7 files changed, 112 insertions(+), 10 deletions(-) create mode 100644 templates/components/quest.html diff --git a/db.py b/db.py index 7c326dba..8263cf84 100644 --- a/db.py +++ b/db.py @@ -1036,6 +1036,20 @@ class ActivityReport(Base): return f"" +class Quest(Base): + __tablename__ = "quests" + + id = Column(Integer, primary_key=True) + + title = Column(String) + description = Column(Text) + reward = Column(Integer) + expiration_date = Column(DateTime) + + def __repr__(self): + return f"" + + # If run as script, create all the tables in the db if __name__ == "__main__": print("Creating new tables...") diff --git a/static/nryg.less b/static/nryg.less index 49f7f6de..e613976c 100644 --- a/static/nryg.less +++ b/static/nryg.less @@ -974,6 +974,51 @@ ul { } } + +.quest { + padding: 8px; + color: @accent-color; + font-family: "Verdana", sans-serif; + background-image: url("/static/plank.jpg"); + display: grid; + grid-template-columns: auto 64px; + grid-row-gap: 2px; + margin-bottom: 1px; + margin-top: 1px; + + .title { + grid-row: 1; + grid-column: 1; + font-weight: bold; + } + + .description { + grid-row: 2; + grid-column: 1; + + p { + margin: 0; + } + } + + .reward { + grid-row-start: 1; + grid-row-end: 3; + grid-column: 2; + text-align: center; + display: flex; + flex-direction: column; + + .number { + font-size: xx-large; + } + + .subtext { + font-size: smaller; + } + } +} + #debug-mode { color: red; font-weight: bold; diff --git a/templates/components/eventlist.html b/templates/components/eventlist.html index 8a3269c8..e8f2d779 100644 --- a/templates/components/eventlist.html +++ b/templates/components/eventlist.html @@ -1,5 +1,4 @@
- {% if next_events %}
Prossimi eventi
@@ -8,5 +7,4 @@ {% include "components/event.html" %} {% endfor %}
- {% endif %} \ No newline at end of file diff --git a/templates/components/quest.html b/templates/components/quest.html new file mode 100644 index 00000000..60769068 --- /dev/null +++ b/templates/components/quest.html @@ -0,0 +1,14 @@ +
+
+ {{ quest.title }} +
+
+ {{ quest.description | markdown }} +
+
+ {% if quest.reward %} +
{{ quest.reward }}
+
fioryg{% if quest.reward != 1 %}i{% endif %}
+ {% endif %} +
+
\ No newline at end of file diff --git a/templates/components/questboard.html b/templates/components/questboard.html index 49b097bb..8ff19329 100644 --- a/templates/components/questboard.html +++ b/templates/components/questboard.html @@ -3,8 +3,12 @@ Tabellone delle quest
-
- -
+ {% if quests %} + {% for quest in quests %} + {% include "components/quest.html" %} + {% endfor %} + {% else %} + Non ci sono quest al momento. + {% endif %}
\ No newline at end of file diff --git a/templates/main.html b/templates/main.html index a008a6bc..a867931b 100644 --- a/templates/main.html +++ b/templates/main.html @@ -18,10 +18,14 @@ {% include "components/welcome.html" %} {% endif %} {% if g.logged_in %} - {% include "components/eventlist.html" %} - {% include "components/diariooftheday.html" %} + {% if events %} + {% include "components/eventlist.html" %} + {% endif %} {% endif %} {% include "components/memberbox.html" %} + {% if g.logged_in %} + {% include "components/wikibox.html" %} + {% endif %}
{% if not g.logged_in %} @@ -29,11 +33,11 @@ {% endif %} {% if g.logged_in %} {% include "components/questboard.html" %} - {% include "components/links.html" %} {% endif %} {% include "components/gamestatsbox.html" %} {% if g.logged_in %} - {% include "components/wikibox.html" %} + {% include "components/links.html" %} + {% include "components/diariooftheday.html" %} {% endif %}
diff --git a/webserver.py b/webserver.py index f8e11ee7..4400bb7b 100644 --- a/webserver.py +++ b/webserver.py @@ -29,6 +29,28 @@ telegram_bot = telegram.Bot(config["Telegram"]["bot_token"]) sentry = Sentry(app, dsn=config["Sentry"]["token"]) +@app.template_filter() +def markdown(text): + """Convert a string to markdown.""" + converted_md = markdown2.markdown(text.replace("<", "<"), + extras=["spoiler", "tables", "smarty-pants", "fenced-code-blocks"]) + converted_md = re.sub(r"{https?://(?:www\.)?(?:youtube\.com/watch\?.*?&?v=|youtu.be/)([0-9A-Za-z-]+).*?}", + r'
' + r' ' + r'
', converted_md) + converted_md = re.sub(r"{https?://clyp.it/([a-z0-9]+)}", + r'
' + r' ' + r'
', converted_md) + return Markup(converted_md) + @app.errorhandler(400) def error_400(_=None): return render_template("400.html", g=fl_g) @@ -68,9 +90,10 @@ def page_main(): next_events = db_session.query(db.Event).filter(db.Event.time > datetime.datetime.now()).order_by( db.Event.time).all() halloween = db.Halloween.puzzle_status()[1] + quests = db_session.query(db.Quest).all() db_session.close() return render_template("main.html", royals=royals, wiki_pages=wiki_pages, entry=random_diario, - events=next_events, g=fl_g, escape=escape, halloween=enumerate(halloween)) + events=next_events, g=fl_g, escape=escape, quests=quests, halloween=enumerate(halloween)) @app.route("/profile/")