From acf918f6567232b25f9fbfb8b4cd7b6224e7bc1c Mon Sep 17 00:00:00 2001
From: Mattia Succurro
Date: Tue, 12 Dec 2023 10:10:20 +0100
Subject: [PATCH] Introduce flask_arrest, fix dotenv loading (Apache), and new
template macro "nl.jinja2"
---
.gitignore | 4 +--
README.md | 2 +-
app.py | 22 ++++++++--------
requirements.txt | 4 ++-
templates/base.jinja2 | 5 +++-
templates/home.jinja2 | 30 +++-------------------
templates/listrecent.jinja2 | 36 ++------------------------
templates/listtag.jinja2 | 38 ++--------------------------
templates/macros/nl.jinja2 | 50 +++++++++++++++++++++++++++++++++++++
templates/search.jinja2 | 7 ++----
10 files changed, 80 insertions(+), 118 deletions(-)
create mode 100644 templates/macros/nl.jinja2
diff --git a/.gitignore b/.gitignore
index bdac4f8..9c35e69 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,8 +7,8 @@ site-*.conf
run_8180.py
.env
alembic.ini
-venv/
-venv-*/
+venv
+venv-*
.venv
env
diff --git a/README.md b/README.md
index b9d20e8..941565a 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@ suitable as a community or team knowledge base.
## Requirements
+ **Python** 3.6+.
-+ **Flask** web framework (and Flask-Login / Flask-WTF extensions).
++ **Flask** web framework (and Flask-Login / Flask-WTF / Flask-Arrest extensions).
+ **Peewee** ORM.
+ **Markdown** for page rendering.
+ **Python-I18n**.
diff --git a/app.py b/app.py
index eec7bd5..ac847bb 100644
--- a/app.py
+++ b/app.py
@@ -17,6 +17,7 @@ from flask import (
render_template, send_from_directory)
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
from werkzeug.security import generate_password_hash, check_password_hash
from werkzeug.routing import BaseConverter
from peewee import *
@@ -46,9 +47,9 @@ PING_RE = r'(?{0}').format(x),
'app_version': __version__,
- 'material_icons_url': _getconf('site', 'material_icons_url')
+ 'material_icons_url': _getconf('site', 'material_icons_url'),
+ 'min': min
}
@login_manager.user_loader
diff --git a/requirements.txt b/requirements.txt
index 18bfb00..b498231 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -3,4 +3,6 @@ peewee
markdown
flask-login
flask-wtf
-python-i18n
\ No newline at end of file
+python-i18n
+flask-arrest
+python-dotenv
diff --git a/templates/base.jinja2 b/templates/base.jinja2
index 512e33b..18890f4 100644
--- a/templates/base.jinja2
+++ b/templates/base.jinja2
@@ -13,8 +13,11 @@
{% endif %}
{% block json_info %}{% endblock %}
+ {% block ldjson %}{% endblock %}
-
+
-
- {% endfor %}
- {% if page_n < total_count // 20 %}
- Next page »
- {% endif %}
-
+ {% 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 %}
diff --git a/templates/macros/nl.jinja2 b/templates/macros/nl.jinja2
new file mode 100644
index 0000000..c34f963
--- /dev/null
+++ b/templates/macros/nl.jinja2
@@ -0,0 +1,50 @@
+
+
+{% macro nl_list(l, page_n=None, total_count=None, hl_tags=(), other_url='p/most_recent') %}
+{% if page_n and total_count %}
+
+{% endif %}
+
+
+ {% if page_n and page_n > 1 %}
+ - « Previous page
+ {% 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 }}
+ {% endif %}
+ {% endfor %}
+
+ {% endif %}
+ {% if n.calendar %}
+
+ calendar_today
+
+
+
+
+ {% endif %}
+
+ {% endfor %}
+
+ {% if page_n is none %}
+ - {{ T('show-all') }}
+ {% elif page_n <= total_count // 20 %}
+ - Next page »
+ {% endif %}
+
+{% endmacro %}
+
diff --git a/templates/search.jinja2 b/templates/search.jinja2
index ddbf029..b883186 100644
--- a/templates/search.jinja2
+++ b/templates/search.jinja2
@@ -21,11 +21,8 @@
{% if results %}
Search results for {{ q }}
-
- {% for n in results %}
- - {% include "includes/nl_item.jinja2" %}
- {% endfor %}
-
+ {% from "macros/nl.jinja2" import nl_list with context %}
+ {{ nl_list(l, other_url=None) }}
{% elif q %}
{{ T('search-no-results') }} {{ q }}
{% else %}