From ba3ed04b44898ef632b8dbda5dfa5fc77db678d9 Mon Sep 17 00:00:00 2001 From: Mattia Succurro Date: Wed, 17 May 2023 20:52:33 +0200 Subject: [PATCH] Improved calendar month view --- app.py | 14 +++++++++++++- static/style.css | 1 + templates/home.jinja2 | 3 ++- templates/month.jinja2 | 14 ++++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index e358abf..2464df6 100644 --- a/app.py +++ b/app.py @@ -950,6 +950,18 @@ def contributions(username): min=min ) +def _advance_calendar(date, offset=0): + if offset == -2: + return datetime.date(date.year - 1, date.month, 1) + elif offset == -1: + return datetime.date(date.year, date.month - 1, 1) if date.month > 1 else datetime.date(date.year - 1, 12, 1) + elif offset == 1: + return datetime.date(date.year, date.month + 1, 1) if date.month < 12 else datetime.date(date.year + 1, 1, 1) + elif offset == 2: + return datetime.date(date.year + 1, date.month, 1) + else: + return date + @app.route('/calendar/') def calendar_view(): now = datetime.datetime.now() @@ -967,7 +979,7 @@ def calendar_month(y, m): page = int(request.args.get('page', 1)) return render_template('month.jinja2', d=datetime.date(y, m, 1), notes=notes.paginate(page), - page_n=page, total_count=notes.count(), min=min) + page_n=page, total_count=notes.count(), min=min, advance_calendar=_advance_calendar) @app.route('/history/revision//') def view_old(revisionid): diff --git a/static/style.css b/static/style.css index c2daa20..b5df299 100644 --- a/static/style.css +++ b/static/style.css @@ -28,6 +28,7 @@ body{font-family:sans-serif;background-color:var(--bg-main); color: var(--fg-mai /* header styles */ .header{padding:1em;display:flex;flex-direction:row;justify-content:space-between;position:sticky;top:0;background-color:var(--bg-alt); z-index: 99} +.header-app-name{font-size: 1.5em; font-weight: bold} .header .header-blank {flex: 1; margin: 0 .5em} .header ul{list-style:none;padding:0;margin:0;font-size:0.9em;border-left:var(--border) 1px solid} .header ul > li{display:inline-block;padding-right:1em} diff --git a/templates/home.jinja2 b/templates/home.jinja2 index ab01ddc..90dc091 100644 --- a/templates/home.jinja2 +++ b/templates/home.jinja2 @@ -40,8 +40,9 @@ {% endif %} {% endfor %} -
  • {{ T('show-all') }}
  • +
  • {{ T('show-all') }}
  • + {% endblock %} diff --git a/templates/month.jinja2 b/templates/month.jinja2 index 3e9cd31..6f1b369 100644 --- a/templates/month.jinja2 +++ b/templates/month.jinja2 @@ -43,6 +43,20 @@

    {{ T('notes-month-empty') }}

    {% endif %} + {% set past_year = advance_calendar(d, -2) %} + {% set past_month = advance_calendar(d, -1) %} + {% set next_month = advance_calendar(d, 1) %} + {% set next_year = advance_calendar(d, 2) %} + +

    {{ T('back-to') }} {{ T('calendar') }}