diff --git a/app.py b/app.py index ac847bb..2bdec0d 100644 --- a/app.py +++ b/app.py @@ -13,8 +13,9 @@ Application is kept compact, with all its core in a single file. #### IMPORTS #### from flask import ( - Flask, Markup, abort, flash, g, jsonify, make_response, redirect, request, + Flask, abort, flash, g, jsonify, make_response, redirect, request, render_template, send_from_directory) +from markupsafe import Markup from flask_login import LoginManager, login_user, logout_user, current_user, login_required from flask_wtf import CSRFProtect #from flask_arrest import RestBlueprint, serialize_response @@ -1005,7 +1006,15 @@ def calendar_month(y, m): (Page.calendar < datetime.date(y+1 if m==12 else y, 1 if m==12 else m+1, 1)) ).order_by(Page.calendar) - return render_paginated_template('month.jinja2', "notes", d=datetime.date(y, m, 1), notes=notes, advance_calendar=_advance_calendar) + #toc_q = Page.select(fn.Month(Page.calendar).alias('month'), fn.Count(Page.id).alias('n_notes')).where( + # (datetime.date(y, 1, 1) <= Page.calendar) & + # (Page.calendar < datetime.date(y+1, 1, 1)) + #).group_by() + toc = {} + #for i in toc_q: + # toc[i.month] = i.n_notes + + return render_paginated_template('month.jinja2', "notes", d=datetime.date(y, m, 1), notes=notes, advance_calendar=_advance_calendar, toc=toc) @app.route('/history/revision//') def view_old(revisionid): diff --git a/i18n/salvi.fr.json b/i18n/salvi.fr.json index 439b6a4..9a63a86 100644 --- a/i18n/salvi.fr.json +++ b/i18n/salvi.fr.json @@ -5,6 +5,9 @@ "latest-notes": "Dernières notes", "latest-uploads": "Derniers téléchargements", "new-note": "Créer un note", - "upload-file": "Télécharger une image" + "upload-file": "Télécharger une image", + "easter-date-calc": "Calculer la date de Pâques", + "easter": "Pâques", + "other-dates": "Autres dates" } } \ No newline at end of file diff --git a/static/style.css b/static/style.css index 0562303..6734259 100644 --- a/static/style.css +++ b/static/style.css @@ -69,6 +69,7 @@ body{font-family:sans-serif;background-color:var(--bg-main); color: var(--fg-mai .nl-prev,.nl-next{text-align:center} .nl-placeholder {font-style: italic; text-align: center;} .nl-pagination {text-align: center; color: var(--fg-alt)} +.nl-item {padding: 12px; border: 1px solid gray; border-radius: 12px; box-shadow: 2px 2px 2px gray; background-color: var(--bg-alt);} input{border:0;border-bottom:3px solid var(--border);font:inherit;color:var(--fg-main);background-color:transparent} input:focus{color:var(--fg-sharp);border-bottom-color:var(--border-sharp)} input.error{border-bottom-color:var(--btn-error)} diff --git a/templates/administration.jinja2 b/templates/administration.jinja2 index 535e175..2e86d73 100644 --- a/templates/administration.jinja2 +++ b/templates/administration.jinja2 @@ -3,23 +3,25 @@ {% block title %}Administrative tools — {{ app_name }}{% endblock %} {% block content %} -

Administrative tools

+
+

Administrative tools

-
- {% if current_user and current_user.is_admin %} - - {% else %} -

Administrative tools can be accessed by administrator users only.

- {% endif %} -
+
+ {% if current_user and current_user.is_admin %} + + {% else %} +

Administrative tools can be accessed by administrator users only.

+ {% endif %} +
+
{% endblock %} \ No newline at end of file diff --git a/templates/backlinks.jinja2 b/templates/backlinks.jinja2 index e22ab81..12189d5 100644 --- a/templates/backlinks.jinja2 +++ b/templates/backlinks.jinja2 @@ -7,24 +7,26 @@ {% endblock %} {% block content %} -

{{ p.title }}

-
{{ T('backlinks') }}
+
+

{{ p.title }}

+
{{ T('backlinks') }}
-
- {% if backlinks %} - - {% else %} -

{{ T("backlinks-empty") }}

- {% endif %} -
+
+ {% if backlinks %} + + {% else %} +

{{ T("backlinks-empty") }}

+ {% endif %} +
-

{{ T("back-to") }} {{ p.title }}.

+

{{ T("back-to") }} {{ p.title }}.

+
{% endblock %} diff --git a/templates/badrequest.jinja2 b/templates/badrequest.jinja2 index 3759000..380edba 100644 --- a/templates/badrequest.jinja2 +++ b/templates/badrequest.jinja2 @@ -3,9 +3,11 @@ {% block title %}Bad Request - {{ app_name }}{% endblock %} {% block content %} -

Bad request

+
+

Bad request

-
-

You sent a request the server can’t understand. If you entered the URL manually please check your spelling and try again.

-
+
+

You sent a request the server can’t understand. If you entered the URL manually please check your spelling and try again.

+
+
{% endblock %} diff --git a/templates/calendar.jinja2 b/templates/calendar.jinja2 index 85c3afa..85c44a5 100644 --- a/templates/calendar.jinja2 +++ b/templates/calendar.jinja2 @@ -3,7 +3,7 @@ {% block title %}Calendar – {{ app_name }}{% endblock %} {% block content %} -
+

{{ T('calendar') }}

@@ -32,5 +32,5 @@

-
+ {% endblock %} \ No newline at end of file diff --git a/templates/contributions.jinja2 b/templates/contributions.jinja2 index ec13a94..59986a9 100644 --- a/templates/contributions.jinja2 +++ b/templates/contributions.jinja2 @@ -7,37 +7,40 @@ {% endblock %} {% block content %} -

Contributions of {{ u.username }}

+
+

{{ u.username }}

+

Contributions

-
-

Showing results {{ page_n * 20 - 19 }} to {{ min(page_n * 20, total_count) }} of {{ total_count }} total.

+
+

Showing results {{ page_n * 20 - 19 }} to {{ min(page_n * 20, total_count) }} of {{ total_count }} total.

-
+ {% if page_n < total_count // 20 %} +
  • Next page »
  • + {% endif %} + +
    +
    {% endblock %} diff --git a/templates/forbidden.jinja2 b/templates/forbidden.jinja2 index ab97d1d..2f039df 100644 --- a/templates/forbidden.jinja2 +++ b/templates/forbidden.jinja2 @@ -3,9 +3,11 @@ {% block title %}Access Denied - {{ app_name }}{% endblock %} {% block content %} -

    Forbidden

    +
    +

    Forbidden

    -
    -

    You don’t have permission to access this resource.

    -
    +
    +

    You don’t have permission to access this resource.

    +
    +
    {% endblock %} diff --git a/templates/history.jinja2 b/templates/history.jinja2 index c671e1f..e7e9914 100644 --- a/templates/history.jinja2 +++ b/templates/history.jinja2 @@ -7,33 +7,35 @@ {% endblock %} {% block content %} -

    {{ p.title }}

    -
    Page history
    +
    +

    {{ p.title }}

    +
    Page history
    - -

    {{ T("back-to") }} {{ p.title }}.

    +

    {{ T("back-to") }} {{ p.title }}.

    +
    {% endblock %} diff --git a/templates/home.jinja2 b/templates/home.jinja2 index 44abd83..e0d69c0 100644 --- a/templates/home.jinja2 +++ b/templates/home.jinja2 @@ -3,22 +3,24 @@ {% block title %}{{ T('homepage') }} - {{ app_name }}{% endblock %} {% block content %} -
    +

    {{ T('welcome').format(app_name) }}

    -
    - - - +
    + + +

    {{ T('latest-notes') }}

    + +
    + + {% from "macros/nl.jinja2" import nl_list with context %} + {{ nl_list(new_notes) }}
    -

    {{ T('latest-notes') }}

    - -
    - - {% from "macros/nl.jinja2" import nl_list with context %} - {{ nl_list(new_notes) }} - -
    + {% endblock %} diff --git a/templates/includes/nl_item.jinja2 b/templates/includes/nl_item.jinja2 index c898901..f372285 100644 --- a/templates/includes/nl_item.jinja2 +++ b/templates/includes/nl_item.jinja2 @@ -1,3 +1,8 @@ +{# DEPRECATED #} +{# Use "macros/nl.jinja2" instead. #} + + +
    DEPRECATED

    {{ n.title }}

    diff --git a/templates/internalservererror.jinja2 b/templates/internalservererror.jinja2 index 8c24e60..01d6143 100644 --- a/templates/internalservererror.jinja2 +++ b/templates/internalservererror.jinja2 @@ -3,9 +3,11 @@ {% block title %}% _ % - {{ app_name }}{% endblock %} {% block content %} -

    Internal Server Error

    +
    +

    Internal Server Error

    -
    -

    We’re sorry, an unexpected error occurred. Try refreshing the page.

    -
    +
    +

    We’re sorry, an unexpected error occurred. Try refreshing the page.

    +
    +
    {% endblock %} diff --git a/templates/listrecent.jinja2 b/templates/listrecent.jinja2 index 3f19545..1da0196 100644 --- a/templates/listrecent.jinja2 +++ b/templates/listrecent.jinja2 @@ -1,10 +1,12 @@ {% extends "base.jinja2" %} {% block content %} -
    +

    Notes by date

    - {% from "macros/nl.jinja2" import nl_list with context %} - {{ nl_list(notes, page_n=page_n, total_count=total_count) }} -
    +
    + {% from "macros/nl.jinja2" import nl_list with context %} + {{ nl_list(notes, page_n=page_n, total_count=total_count) }} +
    + {% endblock %} diff --git a/templates/listtag.jinja2 b/templates/listtag.jinja2 index c33b6ca..2f6b6c5 100644 --- a/templates/listtag.jinja2 +++ b/templates/listtag.jinja2 @@ -3,17 +3,19 @@ {% block title %}Notes tagged #{{ tagname }} - {{ app_name }}{% endblock %} {% block content %} -
    +

    #{{ tagname }}

    {{ T('notes-tagged') }}
    - {% if total_count > 0 %} - {% from "macros/nl.jinja2" import nl_list with context %} - {{ nl_list(l, page_n=page_n, total_count=total_count, hl_tags=(tagname,)) }} - {% else %} -

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

    - {% endif %} +
    + {% if total_count > 0 %} + {% from "macros/nl.jinja2" import nl_list with context %} + {{ nl_list(tagged_notes, page_n=page_n, total_count=total_count, hl_tags=(tagname,), other_url='tags/' + tagname) }} + {% else %} +

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

    + {% endif %} +
    -
    + {% endblock %} diff --git a/templates/macros/nl.jinja2 b/templates/macros/nl.jinja2 index c34f963..5956fc8 100644 --- a/templates/macros/nl.jinja2 +++ b/templates/macros/nl.jinja2 @@ -1,6 +1,10 @@ +{# + Recommendations: Always import this macro with context, + otherwise it fails. It depends on a couple context-defined functions. +#} -{% macro nl_list(l, page_n=None, total_count=None, hl_tags=(), other_url='p/most_recent') %} +{% macro nl_list(l, page_n=None, total_count=None, hl_tags=(), hl_calendar=None, other_url='p/most_recent') %} {% if page_n and total_count %}

    Showing results {{ page_n * 20 - 19 }} to {{ min(page_n * 20, total_count) }} @@ -13,36 +17,44 @@ {% endif %} {% for n in l %}

  • - {{ n.title }} -

    {{ n.short_desc() }}

    - {% if n.tags %} -

    - tag - {{ T('tags') }}: - {% for tag in n.tags %} - {% set tn = tag.name %} - {% if tn in hl_tags %} - #{{ tn }} - {% else %} - #{{ tn }} +

    + {{ n.title }} +

    {{ n.short_desc() }}

    + {% if n.tags %} +

    + tag + {{ T('tags') }}: + {% for tag in n.tags %} + {% set tn = tag.name %} + {% if tn in hl_tags %} + #{{ tn }} + {% else %} + #{{ tn }} + {% endif %} + {% endfor %} +

    {% endif %} - {% endfor %} -

    - {% endif %} - {% if n.calendar %} -

    - calendar_today - - - -

    - {% endif %} + {% if n.calendar %} +

    + calendar_today + {% if hl_calendar and hl_calendar.y == n.calendar.y and hl_calendar.m == n.calendar.m %} + + + + {% else %} + + + + {% endif %} +

    + {% endif %} +
  • {% endfor %} {% if page_n is none %}
  • {{ T('show-all') }}
  • - {% elif page_n <= total_count // 20 %} + {% elif page_n <= (total_count - 1) // 20 %}
  • Next page »
  • {% endif %} diff --git a/templates/month.jinja2 b/templates/month.jinja2 index 6f1b369..3b28a70 100644 --- a/templates/month.jinja2 +++ b/templates/month.jinja2 @@ -3,61 +3,48 @@ {% block title %}{{ d.strftime("%B %Y") }} – {{ app_name }}{% endblock %} {% block content %} -
    +

    {{ d.strftime("%B %Y") }}

    - {% if total_count > 0 %} -

    Showing results {{ page_n * 20 - 19 }} to {{ min(page_n * 20, total_count) }} of {{ total_count }} total.

    +
    + {% if total_count > 0 %} + {% from "macros/nl.jinja2" import nl_list with context %} + {{ nl_list(notes, total_count=total_count, page_n=page_n, hl_calendar=d) }} + + {% else %} +

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

    + {% endif %} -
      - {% for n in notes %} -
    • - {{ n.title }} -

      {{ n.short_desc() }}

      - {% if n.tags %} -

      {{ T('tags') }}: - {% for tag in n.tags %} - {% set tn = tag.name %} - #{{ tn }} - {% endfor %} -

      - {% endif %} - {% if n.calendar %} -

      - calendar_today - {% if n.calendar.year == d.year and n.calendar.month == d.month %} - - - - {% else %} - - - - {% endif %} -

      - {% endif %} -
    • - {% endfor %} -
    - {% else %} -

    {{ 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) %} + - {% 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) %} - +
    +{% endblock %} -

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

    -
    +{% block toc %} + {% endblock %} \ No newline at end of file diff --git a/templates/notfound.jinja2 b/templates/notfound.jinja2 index e79d893..93c5af7 100644 --- a/templates/notfound.jinja2 +++ b/templates/notfound.jinja2 @@ -3,9 +3,11 @@ {% block title %}{{ T('not-found') }} - {{ app_name }}{% endblock %} {% block content %} -

    {{ T('not-found') }}

    +
    +

    {{ T('not-found') }}

    -
    -

    {{ T('not-found-text-1') }} {{ request.path }} {{ T('not-found-text-2') }}.

    -
    +
    +

    {{ T('not-found-text-1') }} {{ request.path }} {{ T('not-found-text-2') }}.

    +
    +
    {% endblock %} diff --git a/templates/search.jinja2 b/templates/search.jinja2 index b883186..29059d2 100644 --- a/templates/search.jinja2 +++ b/templates/search.jinja2 @@ -3,31 +3,33 @@ {% block title %}{% if q %}Search results for "{{ q }}"{% else %}Search{% endif %} - {{ app_name }}{% endblock %} {% block content %} -

    Search

    +
    +

    Search

    -
    -
    - -
    - - -
    -
    - - -
    -
    +
    +
    + +
    + + +
    +
    + + +
    +
    - {% if results %} -

    Search results for {{ q }}

    + {% if results %} +

    Search results for {{ q }}

    - {% from "macros/nl.jinja2" import nl_list with context %} - {{ nl_list(l, other_url=None) }} - {% elif q %} -

    {{ T('search-no-results') }} {{ q }}

    - {% else %} -

    Please note that search queries do not search for page text.

    - {% endif %} -
    + {% from "macros/nl.jinja2" import nl_list with context %} + {{ nl_list(results, other_url=None) }} + {% elif q %} +

    {{ T('search-no-results') }} {{ q }}

    + {% else %} +

    Please note that search queries do not search for page text.

    + {% endif %} +
    +
    {% endblock %} diff --git a/templates/upload.jinja2 b/templates/upload.jinja2 index 6c044b5..12bf89b 100644 --- a/templates/upload.jinja2 +++ b/templates/upload.jinja2 @@ -1,21 +1,23 @@ {% extends "base.jinja2" %} {% block content %} -

    Upload new file

    +
    +

    Upload new file

    -

    Uploads are no more supported. Please use this syntax instead for external images: ![alt text](https://www.example.com/path/to/image.jpg).

    +

    Uploads are no more supported. Please use this syntax instead for external images: ![alt text](https://www.example.com/path/to/image.jpg).

    -
    -
    - - -
    -
    - - -
    -
    - -
    -
    +
    +
    + + +
    +
    + + +
    +
    + +
    +
    +
    {% endblock %}