From b09d32d5e87c4094f5e153ce83c04133572c1711 Mon Sep 17 00:00:00 2001
From: Mattia Succurro
Date: Wed, 9 Nov 2022 14:56:41 +0100
Subject: [PATCH 01/44] version advance + i18n change
---
CHANGELOG.md | 5 +++++
README.md | 2 ++
app.py | 46 +++++++++++-----------------------------------
i18n/salvi.en.json | 33 +++++++++++++++++++++++++++++++++
i18n/salvi.it.json | 33 +++++++++++++++++++++++++++++++++
requirements.txt | 6 ++++++
6 files changed, 90 insertions(+), 35 deletions(-)
create mode 100644 i18n/salvi.en.json
create mode 100644 i18n/salvi.it.json
create mode 100644 requirements.txt
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cc6e95d..df122c7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,10 @@
# What’s New
+## 0.7
+
++ Added `python-i18n` as a dependency. Therefore, i18n changed format, using JSON files now.
++ Like it or not, now gzip library is required.
+
## 0.6
+ Added support for database URLs: you can now specify the URL of the database
diff --git a/README.md b/README.md
index 3864c25..152761c 100644
--- a/README.md
+++ b/README.md
@@ -21,6 +21,8 @@ suitable as a community or team knowledge base.
+ **Python** 3.6+.
+ **Flask** web framework (and Flask-Login / Flask-WTF extensions).
+ **Peewee** ORM.
++ **Markdown** for page rendering.
++ **Python-I18n**.
### Optional requirements
diff --git a/app.py b/app.py
index b2a35e2..489bd62 100644
--- a/app.py
+++ b/app.py
@@ -24,16 +24,10 @@ import csv, datetime, hashlib, html, importlib, json, markdown, os, random, \
from functools import lru_cache, partial
from urllib.parse import quote
from configparser import ConfigParser
-try:
- import gzip
-except ImportError:
- gzip = None
-try:
- from slugify import slugify
-except ImportError:
- slugify = None
+import i18n
+import gzip
-__version__ = '0.6'
+__version__ = '0.7-dev'
#### CONSTANTS ####
@@ -428,26 +422,12 @@ def remove_tags(text, convert=True, headings=True):
#### I18N ####
-lang_poses = {'en': 1, 'en-US': 1, 'it': 2, 'it-IT': 2}
-
-def read_strings():
- with open(APP_BASE_DIR + '/strings.csv', encoding='utf-8') as f:
- return csv.reader(f)
-
-@lru_cache(maxsize=1000)
-def get_string(lang, name):
- with open(APP_BASE_DIR + '/strings.csv', encoding='utf-8') as f:
- for line in csv.reader(f):
- if not line[0] or line[0].startswith('#'):
- continue
- if line[0] == name:
- ln = lang_poses[lang]
- if len(line) > ln and line[ln]:
- return line[ln]
- elif len(line) > 1:
- return line[1]
- return '(' + name + ')'
+i18n.load_path.append(os.path.join(APP_BASE_DIR, 'i18n'))
+i18n.set('file_format', 'json')
+def get_string(loc, s):
+ i18n.set('locale', loc)
+ return i18n.t('salvi.' + s)
#### APPLICATION CONFIG ####
@@ -479,9 +459,8 @@ def _before_request():
for l in request.headers.get('accept-language', 'it,en').split(','):
if ';' in l:
l, _ = l.split(';')
- if l in lang_poses:
- lang = l
- break
+ lang = l
+ break
else:
lang = 'en'
g.lang = lang
@@ -797,9 +776,6 @@ def listtag(tag, page=1):
return render_template('listtag.html', tagname=tag, tagged_notes=page_query,
page_n=page, total_count=general_query.count(), min=min)
-@app.route('/media/')
-def media(fp):
- return send_from_directory(UPLOAD_DIR, fp)
# symbolic route as of v0.5
@app.route('/upload/', methods=['GET'])
@@ -811,7 +787,7 @@ def stats():
return render_template('stats.html',
notes_count=Page.select().count(),
notes_with_url=Page.select().where(Page.url != None).count(),
- upload_count=Upload.select().count(),
+ #upload_count=Upload.select().count(),
revision_count=PageRevision.select().count()
)
diff --git a/i18n/salvi.en.json b/i18n/salvi.en.json
new file mode 100644
index 0000000..7f81eec
--- /dev/null
+++ b/i18n/salvi.en.json
@@ -0,0 +1,33 @@
+{
+ "en": {
+ "welcome": "Welcome to {0}!",
+ "homepage": "Homepage",
+ "latest-notes": "Latest notes",
+ "latest-uploads": "Latest uploads",
+ "new-note": "New note",
+ "upload-file": "Upload file",
+ "easter-date-calc": "Easter date calculation",
+ "easter": "Easter",
+ "other-dates": "Other dates",
+ "jump-to-actions": "Jump to actions",
+ "last-changed": "Last changed",
+ "page-id": "Page ID",
+ "action-edit": "Edit",
+ "action-history": "History",
+ "tags": "Tags",
+ "old-revision-notice": "Showing an old revision of the page as of",
+ "notes-tagged": "Notes tagged",
+ "include-tags": "Include tags",
+ "notes-tagged-empty": "None found :(",
+ "search-no-results": "No results for",
+ "random-page": "Random page",
+ "search": "Search",
+ "year": "Year",
+ "calculate": "Calculate",
+ "show-all": "Show all",
+ "just-now": "just now",
+ "n-minutes-ago": "{0} minutes ago",
+ "n-hours-ago": "{0} hours ago",
+ "n-days-ago": "{0} days ago"
+ }
+}
\ No newline at end of file
diff --git a/i18n/salvi.it.json b/i18n/salvi.it.json
new file mode 100644
index 0000000..224d179
--- /dev/null
+++ b/i18n/salvi.it.json
@@ -0,0 +1,33 @@
+{
+ "it": {
+ "welcome": "Benvenuti in {0}!",
+ "homepage": "Pagina iniziale",
+ "latest-notes": "Note pi\u00f9 recenti",
+ "latest-uploads": "Caricamenti pi\u00f9 recenti",
+ "new-note": "Crea nota",
+ "upload-file": "Carica immagine",
+ "easter-date-calc": "Calcolo della data di Pasqua",
+ "easter": "Pasqua",
+ "other-dates": "Altre date",
+ "jump-to-actions": "Salta alle azioni",
+ "last-changed": "Ultima modifica",
+ "page-id": "ID pagina",
+ "action-edit": "Modifica",
+ "action-history": "Cronologia",
+ "tags": "Etichette",
+ "old-revision-notice": "\u00c8 mostrata una revisione vecchia della pagina, risalente al",
+ "notes-tagged": "Note con etichetta",
+ "include-tags": "Includi etichette",
+ "notes-tagged-empty": "Non c\u2019\u00e8 nulla :(",
+ "search-no-results": "Nessun risultato per",
+ "random-page": "Pagina casuale",
+ "search": "Cerca",
+ "year": "Anno",
+ "calculate": "Calcola",
+ "show-all": "Mostra tutto",
+ "just-now": "poco fa",
+ "n-minutes-ago": "{0} minuti fa",
+ "n-hours-ago": "{0} ore fa",
+ "n-days-ago": "{0} giorni fa"
+ }
+}
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..18bfb00
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,6 @@
+flask
+peewee
+markdown
+flask-login
+flask-wtf
+python-i18n
\ No newline at end of file
From e449e06b5d3c2e7f96076bb473eb92e54e257829 Mon Sep 17 00:00:00 2001
From: Mattia Succurro
Date: Thu, 10 Nov 2022 16:37:30 +0100
Subject: [PATCH 02/44] Introduce migrations folder + improve README.md + add
custom CDN for Material Icons
---
CHANGELOG.md | 2 ++
README.md | 18 ++++++++++++++++++
app.py | 6 +++---
migrations/0_6to0_7.py | 17 +++++++++++++++++
templates/base.html | 5 ++++-
5 files changed, 44 insertions(+), 4 deletions(-)
create mode 100644 migrations/0_6to0_7.py
diff --git a/CHANGELOG.md b/CHANGELOG.md
index df122c7..e20c9c9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -32,9 +32,11 @@
## 0.4
+
## 0.3
+
## 0.2
+ Some code refactoring.
diff --git a/README.md b/README.md
index 152761c..7fabd29 100644
--- a/README.md
+++ b/README.md
@@ -23,11 +23,29 @@ suitable as a community or team knowledge base.
+ **Peewee** ORM.
+ **Markdown** for page rendering.
+ **Python-I18n**.
++ The database drivers needed for the type of database.
### Optional requirements
* **Markdown-KaTeX** if you want to display math inside pages.
+## Usage
+
++ Clone this repository: `git clone https://github.com/sakuragasaki46/salvi`
++ Edit site.conf with the needed parameters. An example site.conf:
+
+```
+[site]
+name = Salvi
+
+[database]
+directory = /path/to/database/
+```
+
++ Run `flask run`.
++ You can now access Salvi in your browser at port 5000.
+
+
## Caveats
+ All pages created are, as of now, viewable and editable by anyone, with no
diff --git a/app.py b/app.py
index 489bd62..195fb4c 100644
--- a/app.py
+++ b/app.py
@@ -4,11 +4,10 @@
'''
A simple wiki-like note webapp.
-Pages are stored in SQLite databases.
+Pages are stored in SQLite/MySQL databases.
Markdown is used for text formatting.
Application is kept compact, with all its core in a single file.
-Extensions are supported (?), kept in extensions/ folder.
'''
#### IMPORTS ####
@@ -472,7 +471,8 @@ def _inject_variables():
'app_name': _getconf('site', 'title'),
'strong': lambda x:Markup('{0} ').format(x),
'app_version': __version__,
- 'math_version': markdown_katex.__version__ if markdown_katex else None
+ 'math_version': markdown_katex.__version__ if markdown_katex else None,
+ 'material_icons_url': _getconf('site', 'material_icons_url')
}
@app.template_filter()
diff --git a/migrations/0_6to0_7.py b/migrations/0_6to0_7.py
new file mode 100644
index 0000000..f039bb6
--- /dev/null
+++ b/migrations/0_6to0_7.py
@@ -0,0 +1,17 @@
+from playhouse.migrate import migrate, SqliteMigrator, MySQLMigrator
+from peewee import MySQLDatabase, SqliteDatabase
+from app import database
+
+if type(database) == MySQLDatabase:
+ migrator = MySQLMigrator(database)
+elif type(database) == SqliteDatabase:
+ migrator = SqliteMigrator(database)
+else:
+ print("Unsupported database")
+ exit()
+
+with database.atomic():
+ migrate(
+
+ )
+
diff --git a/templates/base.html b/templates/base.html
index b546223..945f45f 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -7,8 +7,11 @@
{% block meta %}{% endblock %}
-
+ {% if material_icons_url %}
+
+ {% else %}
+ {% endif %}
{% block json_info %}{% endblock %}
From 0b5286fb8a417071f738ed72b0749654472721ce Mon Sep 17 00:00:00 2001
From: Mattia Succurro
Date: Thu, 10 Nov 2022 18:13:08 +0100
Subject: [PATCH 03/44] Schema changes + introducing CSRF. You have to run
python3 -m migrations.0_6to0_7 to continue using
---
CHANGELOG.md | 5 +++
app.py | 85 ++++++++++++++----------------------------
migrations/0_6to0_7.py | 9 +++--
3 files changed, 40 insertions(+), 59 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e20c9c9..60e4372 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,11 @@
## 0.7
++ Schema changes:
+ + Removed `PagePolicy` and `PagePolicyKey` tables altogether. They were never useful.
+ + Added `calendar` field to `Page`.
+ + Added `User` table.
++ Added `Flask-Login` and `Flask-WTF` dependencies in order to implement user logins.
+ Added `python-i18n` as a dependency. Therefore, i18n changed format, using JSON files now.
+ Like it or not, now gzip library is required.
diff --git a/app.py b/app.py
index 195fb4c..c0083ec 100644
--- a/app.py
+++ b/app.py
@@ -15,6 +15,8 @@ Application is kept compact, with all its core in a single file.
from flask import (
Flask, Markup, abort, flash, g, jsonify, make_response, redirect, request,
render_template, send_from_directory)
+from flask_login import LoginManager
+from flask_wtf import CSRFProtect
from werkzeug.routing import BaseConverter
from peewee import *
from playhouse.db_url import connect as dbconnect
@@ -130,14 +132,27 @@ def _passphrase_hash(pp):
h = str(len(pp_bin)) + ':' + hashlib.sha256(pp_bin).hexdigest()
return h
+class User(BaseModel):
+ username = CharField(32, unique=True)
+ email = CharField(256, null=True)
+ password = CharField()
+ join_date = DateTimeField(default=datetime.datetime.now)
+ karma = IntegerField(default=1)
+ privileges = BitField()
+ is_admin = privileges.flag(1)
+
+
class Page(BaseModel):
url = CharField(64, unique=True, null=True)
title = CharField(256, index=True)
touched = DateTimeField(index=True)
+ calendar = DateTimeField(index=True, null=True)
+ owner = ForeignKeyField(User, null=True)
flags = BitField()
is_redirect = flags.flag(1)
is_sync = flags.flag(2)
is_math_enabled = flags.flag(4)
+ is_locked = flags.flag(8)
@property
def latest(self):
if self.revisions:
@@ -174,22 +189,6 @@ class Page(BaseModel):
@property
def prop(self):
return PagePropertyDict(self)
- def unlock(self, perm, pp, sec):
- ## XX complete later!
- policies = self.policies.where(PagePolicy.type << _makelist(perm))
- if not policies.exists():
- return True
- for policy in policies:
- if policy.verify(pp, sec):
- return True
- return False
- def is_locked(self, perm):
- policies = self.policies.where(PagePolicy.type << _makelist(perm))
- return policies.exists()
- def is_classified(self):
- return self.is_locked(POLICY_CLASSIFY)
- def is_editable(self):
- return not self.is_locked(POLICY_EDIT)
class PageText(BaseModel):
@@ -223,7 +222,7 @@ class PageText(BaseModel):
class PageRevision(BaseModel):
page = FK(Page, backref='revisions', index=True)
- user_id = IntegerField(default=0)
+ user = ForeignKeyField(User, null=True)
comment = CharField(1024, default='')
textref = FK(PageText)
pub_date = DateTimeField(index=True)
@@ -310,42 +309,6 @@ class PagePropertyDict(object):
return PageProperty.select().where((PageProperty.page == self._page) &
(PageProperty.key == key)).exists()
-# Store keys for PagePolicy.
-# Experimental.
-class PagePolicyKey(BaseModel):
- passphrase = CharField()
- sec_code = IntegerField()
- class Meta:
- indexes = (
- (('passphrase','sec_code'), True),
- )
-
- @classmethod
- def create_from_plain(cls, pp, sec):
- PagePolicyKey.create(passphrase=_passphrase_hash(pp), sec_code=sec)
- def verify(self, pp, sec):
- h = _passphrase_hash(pp)
- return self.passphrase == h and self.sec_code == sec
-
-POLICY_ADMIN = 1
-POLICY_READ = 2
-POLICY_EDIT = 3
-POLICY_META = 4
-POLICY_CLASSIFY = 5
-
-# Manage policies for pages (e.g., reading or editing).
-# Experimental.
-class PagePolicy(BaseModel):
- page = FK(Page, backref='policies', index=True, null=True)
- type = IntegerField()
- key = FK(PagePolicyKey, backref='applied_to')
- sitewide = IntegerField(default=0)
-
- class Meta:
- indexes = (
- (('page', 'key'), True),
- )
-
# Link table for caching purposes.
class PageLink(BaseModel):
@@ -389,7 +352,9 @@ class PageLink(BaseModel):
def init_db():
- database.create_tables([Page, PageText, PageRevision, PageTag, PageProperty, PagePolicyKey, PagePolicy, PageLink])
+ database.create_tables([
+ Page, PageText, PageRevision, PageTag, PageProperty, PageLink
+ ])
#### WIKI SYNTAX ####
@@ -447,9 +412,12 @@ forbidden_urls = [
]
app = Flask(__name__)
-app.secret_key = 'qrdldCcvamtdcnidmtasegasdsedrdqvtautar'
+app.secret_key = b'\xf3\xa9?\xbee$L\xabA\xd3\r\xa2\x08\xf6\x00%0b\xa9\xfe\x11\x04\xa6\xd8=\xd3\xa2\x00\xb3\xd5;9'
app.url_map.converters['slug'] = SlugConverter
+csrf = CSRFProtect(app)
+login_manager = LoginManager(app)
+
#### ROUTES ####
@@ -475,6 +443,11 @@ def _inject_variables():
'material_icons_url': _getconf('site', 'material_icons_url')
}
+@login_manager.user_loader
+def _inject_user(userid):
+ return User[userid]
+
+
@app.template_filter()
def linebreaks(text):
text = html.escape(text)
@@ -713,7 +686,7 @@ def page_leaderboard():
pages.append((p, score, p.back_links.count(), p.forward_links.count(), p.latest.length))
pages.sort(key = lambda x: (x[1], x[2], x[4], x[3]), reverse = True)
- return render_template('leaderboard.html', pages=pages)
+ return render_template('leaderboard.html', pages=pages), headers
@app.route('//')
def view_named(name):
diff --git a/migrations/0_6to0_7.py b/migrations/0_6to0_7.py
index f039bb6..ef1d488 100644
--- a/migrations/0_6to0_7.py
+++ b/migrations/0_6to0_7.py
@@ -1,6 +1,7 @@
from playhouse.migrate import migrate, SqliteMigrator, MySQLMigrator
-from peewee import MySQLDatabase, SqliteDatabase
-from app import database
+from peewee import MySQLDatabase, SqliteDatabase, \
+ IntegerField, DateTimeField, ForeignKeyField
+from app import database, User
if type(database) == MySQLDatabase:
migrator = MySQLMigrator(database)
@@ -11,7 +12,9 @@ else:
exit()
with database.atomic():
+ database.create_tables([User])
migrate(
-
+ migrator.add_column('page', 'calendar', DateTimeField(index=True, null=True)),
+ migrator.add_column('page', 'owner_id', IntegerField(null=True))
)
From 891fe36a8389d49959f94f73d213c683783daf82 Mon Sep 17 00:00:00 2001
From: Mattia Succurro
Date: Thu, 10 Nov 2022 21:53:10 +0100
Subject: [PATCH 04/44] add csrf_token to forms
---
templates/search.html | 1 +
1 file changed, 1 insertion(+)
diff --git a/templates/search.html b/templates/search.html
index bd0aa8a..c332983 100644
--- a/templates/search.html
+++ b/templates/search.html
@@ -6,6 +6,7 @@
Search
diff --git a/templates/home.html b/templates/home.html
index c0d4691..f776700 100644
--- a/templates/home.html
+++ b/templates/home.html
@@ -25,6 +25,12 @@
{% endfor %}
{% endif %}
+ {% if n.calendar %}
+
+ calendar_today
+ {{ n.calendar.strftime('%B %-d, %Y') }}
+
+ {% endif %}
{% endfor %}
{{ T('show-all') }}
diff --git a/templates/includes/nl_item.html b/templates/includes/nl_item.html
index a9f01c6..c898901 100644
--- a/templates/includes/nl_item.html
+++ b/templates/includes/nl_item.html
@@ -12,3 +12,9 @@
{% endif %}
{% endfor %}
+{% if n.calendar %}
+
+ calendar_today
+ {{ n.calendar.strftime('%B %-d, %Y') }}
+
+{% endif %}
diff --git a/templates/listrecent.html b/templates/listrecent.html
index f8b7188..01bb1ff 100644
--- a/templates/listrecent.html
+++ b/templates/listrecent.html
@@ -13,11 +13,20 @@
{{ n.title }}
{{ n.short_desc() }}
- Tags:
+ {% if n.tags %}
+
{{ T('tags') }}:
{% for tag in n.tags %}
- #{{ tag.name }}
+ {% set tn = tag.name %}
+ #{{ tn }}
{% endfor %}
+ {% endif %}
+ {% if n.calendar %}
+
+ calendar_today
+ {{ n.calendar.strftime('%B %-d, %Y') }}
+
+ {% endif %}
{% endfor %}
{% if page_n <= total_count // 20 %}
diff --git a/templates/listtag.html b/templates/listtag.html
index 5742b86..68ef780 100644
--- a/templates/listtag.html
+++ b/templates/listtag.html
@@ -25,6 +25,12 @@
#{{ tn }}
{% endif %}
{% endfor %}
+ {% if n.calendar %}
+
+ calendar_today
+ {{ n.calendar.strftime('%B %-d, %Y') }}
+
+ {% endif %}
{% endfor %}
diff --git a/templates/month.html b/templates/month.html
new file mode 100644
index 0000000..9211ade
--- /dev/null
+++ b/templates/month.html
@@ -0,0 +1,32 @@
+{% extends "base.html" %}
+
+{% block title %}{{ d.strftime("%B %Y") }} – {{ app_name }}{% endblock %}
+
+{% block content %}
+{{ d.strftime("%B %Y") }}
+
+
+ {% 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
+ {{ n.calendar.strftime('%B %-d, %Y') }}
+
+ {% endif %}
+
+ {% endfor %}
+
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/templates/search.html b/templates/search.html
index c332983..df1aaea 100644
--- a/templates/search.html
+++ b/templates/search.html
@@ -27,6 +27,8 @@
{% 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/view.html b/templates/view.html
index 696ebc1..b66fb00 100644
--- a/templates/view.html
+++ b/templates/view.html
@@ -7,6 +7,10 @@
{% block content %}
{{ p.title }}
+
+ {% if p.calendar %}
+ calendar_today {{ p.calendar.strftime('%B %-d, %Y') }}
+ {% endif %}
{{ T('last-changed') }} {{ rev.human_pub_date() }} ·
From 5f4370f9539a1e55d1fffeab3894b3076b9ee9f5 Mon Sep 17 00:00:00 2001
From: Mattia Succurro
Date: Sun, 12 Mar 2023 10:03:01 +0100
Subject: [PATCH 14/44] =?UTF-8?q?Extensions=20don=E2=80=99t=20work=20anymo?=
=?UTF-8?q?re=20on=20Python=203.10=20(Markdown=203.4.1),=20adding=20a=20wa?=
=?UTF-8?q?y=20to=20disable=20them.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
CHANGELOG.md | 2 ++
app.py | 9 ++++++---
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 17b4aa3..78205c2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
## 0.7
++ XXX Custom Markdown extensions are broken with Markdown 3.4.1. While we find a workaround to it,
+ use the config `[markdown]disable_custom_extensions` set to 1.
+ Schema changes:
+ Removed `PagePolicy` and `PagePolicyKey` tables altogether. They were never useful.
+ Added `calendar` field to `Page`.
diff --git a/app.py b/app.py
index 9460d11..7d41b12 100644
--- a/app.py
+++ b/app.py
@@ -95,7 +95,7 @@ def _makelist(l):
#### MARKDOWN EXTENSIONS ####
class StrikethroughExtension(markdown.extensions.Extension):
- def extendMarkdown(self, md, md_globals):
+ def extendMarkdown(self, md, md_globals=None):
postprocessor = StrikethroughPostprocessor(md)
md.postprocessors.add('strikethrough', postprocessor, '>raw_html')
@@ -114,7 +114,7 @@ BlockQuoteProcessor.RE = re.compile(r'(^|\n)[ ]{0,3}>(?!!)[ ]?(.*)')
### XXX it currently only detects spoilers that are not at the beginning of the line. To be fixed.
class SpoilerExtension(markdown.extensions.Extension):
- def extendMarkdown(self, md, md_globals):
+ def extendMarkdown(self, md, md_globals=None):
md.inlinePatterns.register(markdown.inlinepatterns.SimpleTagInlineProcessor(r'()>!(.*?)!<', 'span class="spoiler"'), 'spoiler', 14)
@@ -390,8 +390,11 @@ def md(text, expand_magic=False, toc=True, math=True):
if expand_magic:
# DEPRECATED seeking for a better solution.
warnings.warn('Magic words are no more supported.', DeprecationWarning)
- extensions = ['tables', 'footnotes', 'fenced_code', 'sane_lists', StrikethroughExtension(), SpoilerExtension()]
+ extensions = ['tables', 'footnotes', 'fenced_code', 'sane_lists']
extension_configs = {}
+ if not _getconf('markdown', 'disable_custom_extensions'):
+ extensions.append(StrikethroughExtension())
+ extensions.append(SpoilerExtension())
if toc:
extensions.append('toc')
if math and markdown_katex and ('$`' in text or '```math' in text):
From 7f050afb8bfde30e75d2f647cff20f2b3df737f7 Mon Sep 17 00:00:00 2001
From: Mattia Succurro
Date: Thu, 16 Mar 2023 14:08:40 +0100
Subject: [PATCH 15/44] fixed markdown extensions
---
CHANGELOG.md | 3 +--
app.py | 2 +-
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 78205c2..d0fc778 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,8 +2,6 @@
## 0.7
-+ XXX Custom Markdown extensions are broken with Markdown 3.4.1. While we find a workaround to it,
- use the config `[markdown]disable_custom_extensions` set to 1.
+ Schema changes:
+ Removed `PagePolicy` and `PagePolicyKey` tables altogether. They were never useful.
+ Added `calendar` field to `Page`.
@@ -16,6 +14,7 @@
+ Now a page can be dated in the calendar.
+ Now you can export and import pages in a JSON format. Importing can be done by admin users only.
+ Improved page history view, and added user contributions page.
++ Updated Markdown extensions to work under latest version.
+ Like it or not, now gzip library is required.
+ Added CSS variables in the site style.
diff --git a/app.py b/app.py
index 7d41b12..cb89d2f 100644
--- a/app.py
+++ b/app.py
@@ -97,7 +97,7 @@ def _makelist(l):
class StrikethroughExtension(markdown.extensions.Extension):
def extendMarkdown(self, md, md_globals=None):
postprocessor = StrikethroughPostprocessor(md)
- md.postprocessors.add('strikethrough', postprocessor, '>raw_html')
+ md.postprocessors.register(postprocessor, 'strikethrough', 0)
class StrikethroughPostprocessor(markdown.postprocessors.Postprocessor):
pattern = re.compile(r"~~(((?!~~).)+)~~", re.DOTALL)
From 2887d94a8c4ecfc819647b4cdbb4d372171369d3 Mon Sep 17 00:00:00 2001
From: Mattia Succurro
Date: Thu, 16 Mar 2023 14:17:50 +0100
Subject: [PATCH 16/44] rename .html templates to .jinja2 for more consistency
---
CHANGELOG.md | 1 +
app.py | 66 +++++++++----------
.../{backlinks.html => backlinks.jinja2} | 0
.../{badrequest.html => badrequest.jinja2} | 0
templates/{base.html => base.jinja2} | 0
templates/{calendar.html => calendar.jinja2} | 0
templates/circles/{add.html => add.jinja2} | 0
templates/circles/{csv.html => csv.jinja2} | 0
templates/circles/{list.html => list.jinja2} | 0
.../circles/{stats.html => stats.jinja2} | 0
.../contactnova/{list.html => list.jinja2} | 0
.../contactnova/{new.html => new.jinja2} | 0
.../{single.html => single.jinja2} | 0
...ontributions.html => contributions.jinja2} | 0
templates/{easter.html => easter.jinja2} | 0
templates/{edit.html => edit.jinja2} | 0
.../{exportpages.html => exportpages.jinja2} | 0
.../{forbidden.html => forbidden.jinja2} | 0
templates/{history.html => history.jinja2} | 0
templates/{home.html => home.jinja2} | 0
.../{importpages.html => importpages.jinja2} | 0
.../includes/{nl_item.html => nl_item.jinja2} | 0
...rerror.html => internalservererror.jinja2} | 0
.../{leaderboard.html => leaderboard.jinja2} | 0
.../{listrecent.html => listrecent.jinja2} | 0
templates/{listtag.html => listtag.jinja2} | 0
templates/{login.html => login.jinja2} | 0
templates/{month.html => month.jinja2} | 0
templates/{notfound.html => notfound.jinja2} | 0
templates/{register.html => register.jinja2} | 0
templates/{search.html => search.jinja2} | 0
templates/{stats.html => stats.jinja2} | 0
templates/{upload.html => upload.jinja2} | 0
.../{uploadinfo.html => uploadinfo.jinja2} | 0
templates/{view.html => view.jinja2} | 0
templates/{viewold.html => viewold.jinja2} | 0
36 files changed, 34 insertions(+), 33 deletions(-)
rename templates/{backlinks.html => backlinks.jinja2} (100%)
rename templates/{badrequest.html => badrequest.jinja2} (100%)
rename templates/{base.html => base.jinja2} (100%)
rename templates/{calendar.html => calendar.jinja2} (100%)
rename templates/circles/{add.html => add.jinja2} (100%)
rename templates/circles/{csv.html => csv.jinja2} (100%)
rename templates/circles/{list.html => list.jinja2} (100%)
rename templates/circles/{stats.html => stats.jinja2} (100%)
rename templates/contactnova/{list.html => list.jinja2} (100%)
rename templates/contactnova/{new.html => new.jinja2} (100%)
rename templates/contactnova/{single.html => single.jinja2} (100%)
rename templates/{contributions.html => contributions.jinja2} (100%)
rename templates/{easter.html => easter.jinja2} (100%)
rename templates/{edit.html => edit.jinja2} (100%)
rename templates/{exportpages.html => exportpages.jinja2} (100%)
rename templates/{forbidden.html => forbidden.jinja2} (100%)
rename templates/{history.html => history.jinja2} (100%)
rename templates/{home.html => home.jinja2} (100%)
rename templates/{importpages.html => importpages.jinja2} (100%)
rename templates/includes/{nl_item.html => nl_item.jinja2} (100%)
rename templates/{internalservererror.html => internalservererror.jinja2} (100%)
rename templates/{leaderboard.html => leaderboard.jinja2} (100%)
rename templates/{listrecent.html => listrecent.jinja2} (100%)
rename templates/{listtag.html => listtag.jinja2} (100%)
rename templates/{login.html => login.jinja2} (100%)
rename templates/{month.html => month.jinja2} (100%)
rename templates/{notfound.html => notfound.jinja2} (100%)
rename templates/{register.html => register.jinja2} (100%)
rename templates/{search.html => search.jinja2} (100%)
rename templates/{stats.html => stats.jinja2} (100%)
rename templates/{upload.html => upload.jinja2} (100%)
rename templates/{uploadinfo.html => uploadinfo.jinja2} (100%)
rename templates/{view.html => view.jinja2} (100%)
rename templates/{viewold.html => viewold.jinja2} (100%)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d0fc778..af38890 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,6 +17,7 @@
+ Updated Markdown extensions to work under latest version.
+ Like it or not, now gzip library is required.
+ Added CSS variables in the site style.
++ Templates are now with `.jinja2` extension.
## 0.6
diff --git a/app.py b/app.py
index cb89d2f..26375bb 100644
--- a/app.py
+++ b/app.py
@@ -75,7 +75,7 @@ else:
markdown_katex = None
try:
if _getconf('appearance', 'math') != 'off':
- import markdown_katex
+ import markdown_katex #pragma: no cover
except ImportError:
pass
@@ -497,7 +497,7 @@ def linebreaks(text):
@app.route('/')
def homepage():
page_limit = _getconf("appearance","items_per_page",20,cast=int)
- return render_template('home.html', new_notes=Page.select()
+ return render_template('home.jinja2', new_notes=Page.select()
.order_by(Page.touched.desc()).limit(page_limit))
@app.route('/robots.txt')
@@ -512,19 +512,19 @@ def favicon():
@app.errorhandler(404)
def error_404(body):
- return render_template('notfound.html'), 404
+ return render_template('notfound.jinja2'), 404
@app.errorhandler(403)
def error_403(body):
- return render_template('forbidden.html'), 403
+ return render_template('forbidden.jinja2'), 403
@app.errorhandler(400)
def error_400(body):
- return render_template('badrequest.html'), 400
+ return render_template('badrequest.jinja2'), 400
@app.errorhandler(500)
def error_500(body):
- return render_template('internalservererror.html'), 500
+ return render_template('internalservererror.jinja2'), 500
# Middle point during page editing.
def savepoint(form, is_preview=False, pageobj=None):
@@ -539,7 +539,7 @@ def savepoint(form, is_preview=False, pageobj=None):
page_id = pageobj.id if pageobj else None
)
return render_template(
- 'edit.html',
+ 'edit.jinja2',
pl_url=form['url'],
pl_title=form['title'],
pl_text=form['text'],
@@ -714,7 +714,7 @@ def view_unnamed(id):
return redirect(p.get_url())
else:
flash('The URL of this page is a reserved URL. Please change it.')
- return render_template('view.html', p=p, rev=p.latest)
+ return render_template('view.jinja2', p=p, rev=p.latest)
@app.route('/embed//')
def embed_view(id):
@@ -730,7 +730,7 @@ def embed_view(id):
@app.route('/p/most_recent//')
def view_most_recent(page=1):
general_query = Page.select().order_by(Page.touched.desc())
- return render_template('listrecent.html', notes=general_query.paginate(page),
+ return render_template('listrecent.jinja2', notes=general_query.paginate(page),
page_n=page, total_count=general_query.count(), min=min)
@app.route('/p/random/')
@@ -758,7 +758,7 @@ def page_leaderboard():
pages.append((p, score, p.back_links.count(), p.forward_links.count(), p.latest.length))
pages.sort(key = lambda x: (x[1], x[2], x[4], x[3]), reverse = True)
- return render_template('leaderboard.html', pages=pages), headers
+ return render_template('leaderboard.jinja2', pages=pages), headers
@app.route('//')
def view_named(name):
@@ -766,7 +766,7 @@ def view_named(name):
p = Page.get(Page.url == name)
except Page.DoesNotExist:
abort(404)
- return render_template('view.html', p=p, rev=p.latest)
+ return render_template('view.jinja2', p=p, rev=p.latest)
@app.route('/init-config/tables/')
def init_config_tables():
@@ -780,7 +780,7 @@ def history(id):
p = Page[id]
except Page.DoesNotExist:
abort(404)
- return render_template('history.html', p=p, history=p.revisions.order_by(PageRevision.pub_date.desc()))
+ return render_template('history.jinja2', p=p, history=p.revisions.order_by(PageRevision.pub_date.desc()))
@app.route('/u//')
def contributions(username):
@@ -788,11 +788,11 @@ def contributions(username):
user = User.get(User.username == username)
except User.DoesNotExist:
abort(404)
- return render_template('contributions.html', u=user, contributions=user.contributions.order_by(PageRevision.pub_date.desc()))
+ return render_template('contributions.jinja2', u=user, contributions=user.contributions.order_by(PageRevision.pub_date.desc()))
@app.route('/calendar/')
def calendar_view():
- return render_template('calendar.html')
+ return render_template('calendar.jinja2')
@app.route('/calendar//')
def calendar_month(y, m):
@@ -801,7 +801,7 @@ 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_template('month.html', d=datetime.date(y, m, 1), notes=notes)
+ return render_template('month.jinja2', d=datetime.date(y, m, 1), notes=notes)
@app.route('/history/revision//')
def view_old(revisionid):
@@ -810,7 +810,7 @@ def view_old(revisionid):
except PageRevision.DoesNotExist:
abort(404)
p = rev.page
- return render_template('viewold.html', p=p, rev=rev)
+ return render_template('viewold.jinja2', p=p, rev=rev)
@app.route('/backlinks//')
def backlinks(id):
@@ -818,7 +818,7 @@ def backlinks(id):
p = Page[id]
except Page.DoesNotExist:
abort(404)
- return render_template('backlinks.html', p=p, backlinks=Page.select().join(PageLink, on=PageLink.to_page).where(PageLink.from_page == p))
+ return render_template('backlinks.jinja2', p=p, backlinks=Page.select().join(PageLink, on=PageLink.to_page).where(PageLink.from_page == p))
@app.route('/search/', methods=['GET', 'POST'])
def search():
@@ -830,27 +830,27 @@ def search():
query |= Page.select().join(PageTag, on=PageTag.page
).where(PageTag.name ** ('%' + q + '%'))
query = query.order_by(Page.touched.desc())
- return render_template('search.html', q=q, pl_include_tags=include_tags,
+ return render_template('search.jinja2', q=q, pl_include_tags=include_tags,
results=query.paginate(1))
- return render_template('search.html', pl_include_tags=True)
+ return render_template('search.jinja2', pl_include_tags=True)
@app.route('/tags//')
@app.route('/tags///')
def listtag(tag, page=1):
general_query = Page.select().join(PageTag, on=PageTag.page).where(PageTag.name == tag).order_by(Page.touched.desc())
page_query = general_query.paginate(page)
- return render_template('listtag.html', tagname=tag, tagged_notes=page_query,
+ return render_template('listtag.jinja2', tagname=tag, tagged_notes=page_query,
page_n=page, total_count=general_query.count(), min=min)
# symbolic route as of v0.5
@app.route('/upload/', methods=['GET'])
def upload():
- return render_template('upload.html')
+ return render_template('upload.jinja2')
@app.route('/stats/')
def stats():
- return render_template('stats.html',
+ return render_template('stats.jinja2',
notes_count=Page.select().count(),
notes_with_url=Page.select().where(Page.url != None).count(),
revision_count=PageRevision.select().count(),
@@ -876,7 +876,7 @@ def accounts_login():
user = User.get(User.username == username)
if not check_password_hash(user.password, request.form['password']):
flash('Invalid username or password.')
- return render_template('login.html')
+ return render_template('login.jinja2')
except User.DoesNotExist:
flash('Invalid username or password.')
else:
@@ -887,7 +887,7 @@ def accounts_login():
else:
login_user(user)
return redirect(request.args.get('next', '/'))
- return render_template('login.html')
+ return render_template('login.jinja2')
@app.route('/accounts/register/', methods=['GET','POST'])
def accounts_register():
@@ -896,10 +896,10 @@ def accounts_register():
password = request.form['password']
if not is_username(username):
flash('Invalid username: usernames can contain only letters, numbers, underscores and hyphens.')
- return render_template('register.html')
+ return render_template('register.jinja2')
if request.form['password'] != request.form['confirm_password']:
flash('Passwords do not match.')
- return render_template('register.html')
+ return render_template('register.jinja2')
if not request.form['legal']:
flash('You must accept Terms in order to register.')
try:
@@ -915,7 +915,7 @@ def accounts_register():
return redirect(request.args.get('next', '/'))
except IntegrityError:
flash('Username taken')
- return render_template('register.html')
+ return render_template('register.jinja2')
@app.route('/accounts/logout/')
def accounts_logout():
@@ -963,10 +963,10 @@ def easter_y(y=None):
if y:
if y > 2499:
flash('Years above 2500 A.D. are currently not supported.')
- return render_template('easter.html')
- return render_template('easter.html', y=y, easter_dates=stash_easter(y))
+ return render_template('easter.jinja2')
+ return render_template('easter.jinja2', y=y, easter_dates=stash_easter(y))
else:
- return render_template('easter.html')
+ return render_template('easter.jinja2')
## import / export ##
@@ -1075,7 +1075,7 @@ def exportpages():
q_list.append(Page.select().where(Page.title == item))
if not q_list:
flash('Failed to export pages: The list is empty!')
- return render_template('exportpages.html')
+ return render_template('exportpages.jinja2')
query = q_list.pop(0)
while q_list:
query |= q_list.pop(0)
@@ -1083,7 +1083,7 @@ def exportpages():
e.add_page_list(query, include_history='history' in request.form)
return e.export(), {'Content-Type': 'application/json', 'Content-Disposition': 'attachment; ' +
'filename=export-{}.json'.format(datetime.datetime.now().strftime('%Y%m%d-%H%M%S'))}
- return render_template('exportpages.html')
+ return render_template('exportpages.jinja2')
@app.route('/manage/import/', methods=['GET', 'POST'])
@login_required
@@ -1098,7 +1098,7 @@ def importpages():
flash('Imported successfully {} pages and {} revisions'.format(*res))
else:
flash('Pages can be imported by Administrators only!')
- return render_template('importpages.html')
+ return render_template('importpages.jinja2')
#### EXTENSIONS ####
diff --git a/templates/backlinks.html b/templates/backlinks.jinja2
similarity index 100%
rename from templates/backlinks.html
rename to templates/backlinks.jinja2
diff --git a/templates/badrequest.html b/templates/badrequest.jinja2
similarity index 100%
rename from templates/badrequest.html
rename to templates/badrequest.jinja2
diff --git a/templates/base.html b/templates/base.jinja2
similarity index 100%
rename from templates/base.html
rename to templates/base.jinja2
diff --git a/templates/calendar.html b/templates/calendar.jinja2
similarity index 100%
rename from templates/calendar.html
rename to templates/calendar.jinja2
diff --git a/templates/circles/add.html b/templates/circles/add.jinja2
similarity index 100%
rename from templates/circles/add.html
rename to templates/circles/add.jinja2
diff --git a/templates/circles/csv.html b/templates/circles/csv.jinja2
similarity index 100%
rename from templates/circles/csv.html
rename to templates/circles/csv.jinja2
diff --git a/templates/circles/list.html b/templates/circles/list.jinja2
similarity index 100%
rename from templates/circles/list.html
rename to templates/circles/list.jinja2
diff --git a/templates/circles/stats.html b/templates/circles/stats.jinja2
similarity index 100%
rename from templates/circles/stats.html
rename to templates/circles/stats.jinja2
diff --git a/templates/contactnova/list.html b/templates/contactnova/list.jinja2
similarity index 100%
rename from templates/contactnova/list.html
rename to templates/contactnova/list.jinja2
diff --git a/templates/contactnova/new.html b/templates/contactnova/new.jinja2
similarity index 100%
rename from templates/contactnova/new.html
rename to templates/contactnova/new.jinja2
diff --git a/templates/contactnova/single.html b/templates/contactnova/single.jinja2
similarity index 100%
rename from templates/contactnova/single.html
rename to templates/contactnova/single.jinja2
diff --git a/templates/contributions.html b/templates/contributions.jinja2
similarity index 100%
rename from templates/contributions.html
rename to templates/contributions.jinja2
diff --git a/templates/easter.html b/templates/easter.jinja2
similarity index 100%
rename from templates/easter.html
rename to templates/easter.jinja2
diff --git a/templates/edit.html b/templates/edit.jinja2
similarity index 100%
rename from templates/edit.html
rename to templates/edit.jinja2
diff --git a/templates/exportpages.html b/templates/exportpages.jinja2
similarity index 100%
rename from templates/exportpages.html
rename to templates/exportpages.jinja2
diff --git a/templates/forbidden.html b/templates/forbidden.jinja2
similarity index 100%
rename from templates/forbidden.html
rename to templates/forbidden.jinja2
diff --git a/templates/history.html b/templates/history.jinja2
similarity index 100%
rename from templates/history.html
rename to templates/history.jinja2
diff --git a/templates/home.html b/templates/home.jinja2
similarity index 100%
rename from templates/home.html
rename to templates/home.jinja2
diff --git a/templates/importpages.html b/templates/importpages.jinja2
similarity index 100%
rename from templates/importpages.html
rename to templates/importpages.jinja2
diff --git a/templates/includes/nl_item.html b/templates/includes/nl_item.jinja2
similarity index 100%
rename from templates/includes/nl_item.html
rename to templates/includes/nl_item.jinja2
diff --git a/templates/internalservererror.html b/templates/internalservererror.jinja2
similarity index 100%
rename from templates/internalservererror.html
rename to templates/internalservererror.jinja2
diff --git a/templates/leaderboard.html b/templates/leaderboard.jinja2
similarity index 100%
rename from templates/leaderboard.html
rename to templates/leaderboard.jinja2
diff --git a/templates/listrecent.html b/templates/listrecent.jinja2
similarity index 100%
rename from templates/listrecent.html
rename to templates/listrecent.jinja2
diff --git a/templates/listtag.html b/templates/listtag.jinja2
similarity index 100%
rename from templates/listtag.html
rename to templates/listtag.jinja2
diff --git a/templates/login.html b/templates/login.jinja2
similarity index 100%
rename from templates/login.html
rename to templates/login.jinja2
diff --git a/templates/month.html b/templates/month.jinja2
similarity index 100%
rename from templates/month.html
rename to templates/month.jinja2
diff --git a/templates/notfound.html b/templates/notfound.jinja2
similarity index 100%
rename from templates/notfound.html
rename to templates/notfound.jinja2
diff --git a/templates/register.html b/templates/register.jinja2
similarity index 100%
rename from templates/register.html
rename to templates/register.jinja2
diff --git a/templates/search.html b/templates/search.jinja2
similarity index 100%
rename from templates/search.html
rename to templates/search.jinja2
diff --git a/templates/stats.html b/templates/stats.jinja2
similarity index 100%
rename from templates/stats.html
rename to templates/stats.jinja2
diff --git a/templates/upload.html b/templates/upload.jinja2
similarity index 100%
rename from templates/upload.html
rename to templates/upload.jinja2
diff --git a/templates/uploadinfo.html b/templates/uploadinfo.jinja2
similarity index 100%
rename from templates/uploadinfo.html
rename to templates/uploadinfo.jinja2
diff --git a/templates/view.html b/templates/view.jinja2
similarity index 100%
rename from templates/view.html
rename to templates/view.jinja2
diff --git a/templates/viewold.html b/templates/viewold.jinja2
similarity index 100%
rename from templates/viewold.html
rename to templates/viewold.jinja2
From 722ceb4724ad7f25c27400e8e048ac71d3894376 Mon Sep 17 00:00:00 2001
From: Mattia Succurro
Date: Thu, 16 Mar 2023 14:24:29 +0100
Subject: [PATCH 17/44] rename .html to .jinja2, part 2
---
templates/backlinks.jinja2 | 2 +-
templates/badrequest.jinja2 | 2 +-
templates/calendar.jinja2 | 2 +-
templates/circles/add.jinja2 | 2 +-
templates/circles/csv.jinja2 | 2 +-
templates/circles/list.jinja2 | 2 +-
templates/circles/stats.jinja2 | 2 +-
templates/contactnova/list.jinja2 | 2 +-
templates/contactnova/new.jinja2 | 2 +-
templates/contactnova/single.jinja2 | 2 +-
templates/contributions.jinja2 | 2 +-
templates/easter.jinja2 | 2 +-
templates/edit.jinja2 | 2 +-
templates/exportpages.jinja2 | 2 +-
templates/forbidden.jinja2 | 2 +-
templates/history.jinja2 | 2 +-
templates/home.jinja2 | 2 +-
templates/importpages.jinja2 | 2 +-
templates/internalservererror.jinja2 | 2 +-
templates/leaderboard.jinja2 | 2 +-
templates/listrecent.jinja2 | 2 +-
templates/listtag.jinja2 | 2 +-
templates/login.jinja2 | 2 +-
templates/month.jinja2 | 2 +-
templates/notfound.jinja2 | 2 +-
templates/register.jinja2 | 2 +-
templates/search.jinja2 | 4 ++--
templates/stats.jinja2 | 2 +-
templates/upload.jinja2 | 2 +-
templates/uploadinfo.jinja2 | 2 +-
templates/view.jinja2 | 2 +-
templates/viewold.jinja2 | 2 +-
32 files changed, 33 insertions(+), 33 deletions(-)
diff --git a/templates/backlinks.jinja2 b/templates/backlinks.jinja2
index 9cf9f7c..aa6bbff 100644
--- a/templates/backlinks.jinja2
+++ b/templates/backlinks.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}Pages linking to “{{ p.title }}” - {{ app_name }}{% endblock %}
diff --git a/templates/badrequest.jinja2 b/templates/badrequest.jinja2
index df7c777..ba04376 100644
--- a/templates/badrequest.jinja2
+++ b/templates/badrequest.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}Bad Request - {{ app_name }}{% endblock %}
diff --git a/templates/calendar.jinja2 b/templates/calendar.jinja2
index f3e5c23..d4272f7 100644
--- a/templates/calendar.jinja2
+++ b/templates/calendar.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}Calendar – {{ app_name }}{% endblock %}
diff --git a/templates/circles/add.jinja2 b/templates/circles/add.jinja2
index eb2a937..90e76cc 100644
--- a/templates/circles/add.jinja2
+++ b/templates/circles/add.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}Circles – {{ app_name }}{% endblock %}
diff --git a/templates/circles/csv.jinja2 b/templates/circles/csv.jinja2
index e50404c..b1b3e49 100644
--- a/templates/circles/csv.jinja2
+++ b/templates/circles/csv.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}Circles – {{ app_name }}{% endblock %}
diff --git a/templates/circles/list.jinja2 b/templates/circles/list.jinja2
index 8b03b4a..4f9884e 100644
--- a/templates/circles/list.jinja2
+++ b/templates/circles/list.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}Circles – {{ app_name }}{% endblock %}
diff --git a/templates/circles/stats.jinja2 b/templates/circles/stats.jinja2
index f1617b0..4fdff58 100644
--- a/templates/circles/stats.jinja2
+++ b/templates/circles/stats.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}Circles – {{ app_name }}{% endblock %}
diff --git a/templates/contactnova/list.jinja2 b/templates/contactnova/list.jinja2
index 276370b..5289f64 100644
--- a/templates/contactnova/list.jinja2
+++ b/templates/contactnova/list.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}List of contacts – {{ app_name }}{% endblock %}
diff --git a/templates/contactnova/new.jinja2 b/templates/contactnova/new.jinja2
index 89e17c8..5608dc1 100644
--- a/templates/contactnova/new.jinja2
+++ b/templates/contactnova/new.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}Create new contact – {{ app_name }}{% endblock %}
diff --git a/templates/contactnova/single.jinja2 b/templates/contactnova/single.jinja2
index 3e77462..ff7a1df 100644
--- a/templates/contactnova/single.jinja2
+++ b/templates/contactnova/single.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}Contact {{ p.code }} – {{ app_name }}{% endblock %}
diff --git a/templates/contributions.jinja2 b/templates/contributions.jinja2
index f94509f..69cc4db 100644
--- a/templates/contributions.jinja2
+++ b/templates/contributions.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}Contributions of {{ u.username }} - {{ app_name }}{% endblock %}
diff --git a/templates/easter.jinja2 b/templates/easter.jinja2
index 4a8ebc8..dd81ef8 100644
--- a/templates/easter.jinja2
+++ b/templates/easter.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}{{ T('easter-date-calc') }} - {{ app_name }}{% endblock %}
diff --git a/templates/edit.jinja2 b/templates/edit.jinja2
index bceabbc..45374c9 100644
--- a/templates/edit.jinja2
+++ b/templates/edit.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}
diff --git a/templates/exportpages.jinja2 b/templates/exportpages.jinja2
index 574c644..136a739 100644
--- a/templates/exportpages.jinja2
+++ b/templates/exportpages.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}Export pages - {{ app_name }}{% endblock %}
diff --git a/templates/forbidden.jinja2 b/templates/forbidden.jinja2
index 8ac8560..83b57b4 100644
--- a/templates/forbidden.jinja2
+++ b/templates/forbidden.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}Access Denied - {{ app_name }}{% endblock %}
diff --git a/templates/history.jinja2 b/templates/history.jinja2
index 8760ec4..3f38d0c 100644
--- a/templates/history.jinja2
+++ b/templates/history.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}Page history - {{ app_name }}{% endblock %}
diff --git a/templates/home.jinja2 b/templates/home.jinja2
index f776700..2c02af0 100644
--- a/templates/home.jinja2
+++ b/templates/home.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}{{ T('homepage') }} - {{ app_name }}{% endblock %}
diff --git a/templates/importpages.jinja2 b/templates/importpages.jinja2
index 67b3a64..e0f54c7 100644
--- a/templates/importpages.jinja2
+++ b/templates/importpages.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}Import pages - {{ app_name }}{% endblock %}
diff --git a/templates/internalservererror.jinja2 b/templates/internalservererror.jinja2
index 53ae91f..050f4c2 100644
--- a/templates/internalservererror.jinja2
+++ b/templates/internalservererror.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}Internal Server Error - {{ app_name }}{% endblock %}
diff --git a/templates/leaderboard.jinja2 b/templates/leaderboard.jinja2
index 3cc88d2..b8966c7 100644
--- a/templates/leaderboard.jinja2
+++ b/templates/leaderboard.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}Best pages - {{ app_name }}{% endblock %}
diff --git a/templates/listrecent.jinja2 b/templates/listrecent.jinja2
index 01bb1ff..deebe66 100644
--- a/templates/listrecent.jinja2
+++ b/templates/listrecent.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block content %}
Notes by date
diff --git a/templates/listtag.jinja2 b/templates/listtag.jinja2
index 68ef780..4249bfe 100644
--- a/templates/listtag.jinja2
+++ b/templates/listtag.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}Notes tagged #{{ tagname }} - {{ app_name }}{% endblock %}
diff --git a/templates/login.jinja2 b/templates/login.jinja2
index 384a652..40c7c0d 100644
--- a/templates/login.jinja2
+++ b/templates/login.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}{{ T('login') }} – {{ app_name }}{% endblock %}
diff --git a/templates/month.jinja2 b/templates/month.jinja2
index 9211ade..55ba03b 100644
--- a/templates/month.jinja2
+++ b/templates/month.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}{{ d.strftime("%B %Y") }} – {{ app_name }}{% endblock %}
diff --git a/templates/notfound.jinja2 b/templates/notfound.jinja2
index 0bd7f79..5b1f7b8 100644
--- a/templates/notfound.jinja2
+++ b/templates/notfound.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}Not found - {{ app_name }}{% endblock %}
diff --git a/templates/register.jinja2 b/templates/register.jinja2
index cf6012f..f255136 100644
--- a/templates/register.jinja2
+++ b/templates/register.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}{{ T('sign-up') }} – {{ app_name }}{% endblock %}
diff --git a/templates/search.jinja2 b/templates/search.jinja2
index df1aaea..01a7304 100644
--- a/templates/search.jinja2
+++ b/templates/search.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}{% if q %}Search results for "{{ q }}"{% else %}Search{% endif %} - {{ app_name }}{% endblock %}
@@ -22,7 +22,7 @@
{% for n in results %}
- {% include "includes/nl_item.html" %}
+ {% include "includes/nl_item.jinja2" %}
{% endfor %}
{% elif q %}
diff --git a/templates/stats.jinja2 b/templates/stats.jinja2
index 4e660ca..0c0f2b0 100644
--- a/templates/stats.jinja2
+++ b/templates/stats.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}Statistics - {{ app_name }}{% endblock %}
diff --git a/templates/upload.jinja2 b/templates/upload.jinja2
index e3f2266..6c044b5 100644
--- a/templates/upload.jinja2
+++ b/templates/upload.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block content %}
Upload new file
diff --git a/templates/uploadinfo.jinja2 b/templates/uploadinfo.jinja2
index 6eec1fa..1be8c30 100644
--- a/templates/uploadinfo.jinja2
+++ b/templates/uploadinfo.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}Info on file "{{ upl.name }}" - {{ app_name }}{% endblock %}
diff --git a/templates/view.jinja2 b/templates/view.jinja2
index b66fb00..76fbb8e 100644
--- a/templates/view.jinja2
+++ b/templates/view.jinja2
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base.jinja2" %}
{% block title %}{{ p.title }} - {{ app_name }}{% endblock %}
diff --git a/templates/viewold.jinja2 b/templates/viewold.jinja2
index 085ba4a..0ea4139 100644
--- a/templates/viewold.jinja2
+++ b/templates/viewold.jinja2
@@ -1,4 +1,4 @@
-{% extends "view.html" %}
+{% extends "view.jinja2" %}
{% block meta %}
From a8b24f2765ea80f412c0322f421c84af95499669 Mon Sep 17 00:00:00 2001
From: Mattia Succurro
Date: Thu, 16 Mar 2023 14:52:55 +0100
Subject: [PATCH 18/44] minor fixes + update version number
---
README.md | 5 -----
app.py | 7 +++----
2 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/README.md b/README.md
index 7fabd29..b8e5e23 100644
--- a/README.md
+++ b/README.md
@@ -46,11 +46,6 @@ directory = /path/to/database/
+ You can now access Salvi in your browser at port 5000.
-## Caveats
-
-+ All pages created are, as of now, viewable and editable by anyone, with no
- trace of users and/or passwords.
-
## License
[MIT License](./LICENSE).
diff --git a/app.py b/app.py
index 26375bb..edc53fd 100644
--- a/app.py
+++ b/app.py
@@ -29,7 +29,7 @@ from configparser import ConfigParser
import i18n
import gzip
-__version__ = '0.7-dev'
+__version__ = '0.7.0'
#### CONSTANTS ####
@@ -381,7 +381,7 @@ class PageLink(BaseModel):
def init_db():
database.create_tables([
- Page, PageText, PageRevision, PageTag, PageProperty, PageLink
+ User, Page, PageText, PageRevision, PageTag, PageProperty, PageLink
])
#### WIKI SYNTAX ####
@@ -454,7 +454,6 @@ login_manager = LoginManager(app)
login_manager.login_view = 'accounts_login'
-
#### ROUTES ####
@app.before_request
@@ -487,13 +486,13 @@ def _inject_variables():
def _inject_user(userid):
return User[userid]
-
@app.template_filter()
def linebreaks(text):
text = html.escape(text)
text = text.replace("\n\n", '').replace('\n', ' ')
return Markup(text)
+
@app.route('/')
def homepage():
page_limit = _getconf("appearance","items_per_page",20,cast=int)
From 9f9525ecd1db02aac95e8a63be823c808d58787c Mon Sep 17 00:00:00 2001
From: Mattia Succurro
Date: Fri, 17 Mar 2023 11:40:34 +0100
Subject: [PATCH 19/44] Improved calendar view
---
CHANGELOG.md | 4 ++++
README.md | 1 +
app.py | 8 +++++--
migrations/0_7to0_8.py | 0
templates/calendar.jinja2 | 47 +++++++++++++++++++--------------------
5 files changed, 34 insertions(+), 26 deletions(-)
create mode 100644 migrations/0_7to0_8.py
diff --git a/CHANGELOG.md b/CHANGELOG.md
index af38890..77ebe84 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
# What’s New
+## 0.7.1
+
++ Improved calendar view. Now `/calendar` shows a list of years and months.
+
## 0.7
+ Schema changes:
diff --git a/README.md b/README.md
index b8e5e23..a3173fa 100644
--- a/README.md
+++ b/README.md
@@ -14,6 +14,7 @@ suitable as a community or team knowledge base.
+ Stored in SQLite/MySQL databases
+ Material Icons
+ Light/dark theme
++ Calendar
+ Works fine even with JavaScript disabled.
## Requirements
diff --git a/app.py b/app.py
index edc53fd..b3bdb4b 100644
--- a/app.py
+++ b/app.py
@@ -29,7 +29,7 @@ from configparser import ConfigParser
import i18n
import gzip
-__version__ = '0.7.0'
+__version__ = '0.7.1'
#### CONSTANTS ####
@@ -791,7 +791,11 @@ def contributions(username):
@app.route('/calendar/')
def calendar_view():
- return render_template('calendar.jinja2')
+ now = datetime.datetime.now()
+ return render_template('calendar.jinja2', now=now,
+ from_year=int(request.args.get('from_year', now.year - 12)),
+ till_year=int(request.args.get('till_year', now.year + 5))
+ )
@app.route('/calendar//')
def calendar_month(y, m):
diff --git a/migrations/0_7to0_8.py b/migrations/0_7to0_8.py
new file mode 100644
index 0000000..e69de29
diff --git a/templates/calendar.jinja2 b/templates/calendar.jinja2
index d4272f7..8edcc2a 100644
--- a/templates/calendar.jinja2
+++ b/templates/calendar.jinja2
@@ -5,29 +5,28 @@
{% block content %}
Calendar
-
-
- Calendar view
+
+ {% for year in range(till_year, from_year-1, -1) %}
+
+ {{ year }} {% if year == now.year %}(current){% endif %}:
+
+
+ {% endfor %}
+
-
-
Show as :
-
- {% set view_choices = ["month"] %}
- {% for vch in view_choices %}
-
- {% if vch == viewas %}
- {{ T(vch) }}
- {% else %}
- {{ T(vch) }}
- {% endif %}
-
- {% endfor %}
-
-
-
-
- Show month
-
-
-
+
+ Show more years:
+
+
{% endblock %}
\ No newline at end of file
From c46b07a3b293c49e1bf3bfff930299f687723562 Mon Sep 17 00:00:00 2001
From: Mattia Succurro
Date: Fri, 17 Mar 2023 23:26:05 +0100
Subject: [PATCH 20/44] version advance, schema changes, style changes, terms
and privacy policy, added installer script
---
CHANGELOG.md | 13 +++
README.md | 5 ++
app.py | 163 +++++++++++++++++++++++++++++++-----
app_init.py | 5 ++
migrations/0_7to0_8.py | 23 +++++
static/style.css | 11 ++-
templates/base.jinja2 | 32 ++++---
templates/edit.jinja2 | 4 +
templates/history.jinja2 | 4 +
templates/home.jinja2 | 8 +-
templates/listrecent.jinja2 | 8 +-
templates/listtag.jinja2 | 20 +++--
templates/privacy.jinja2 | 46 ++++++++++
templates/register.jinja2 | 2 +-
templates/terms.jinja2 | 145 ++++++++++++++++++++++++++++++++
templates/view.jinja2 | 8 ++
16 files changed, 446 insertions(+), 51 deletions(-)
create mode 100644 app_init.py
create mode 100644 templates/privacy.jinja2
create mode 100644 templates/terms.jinja2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 77ebe84..63b5360 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,18 @@
# What’s New
+## 0.8
+
++ Schema changes:
+ + New tables `UserGroup`, `UserGroupMembership` and `PagePermission`.
+ + Added flag `is_cw` to `Page`.
+ + Added `restrictions` field to `User`.
++ Pages now can have a Content Warning. It prevents them to show up in previews, and adds a
+ caution message when viewing them.
++ Added Terms and Privacy Policy.
++ Changed user page URLs (contributions page) from `/u/user` to `/@user`.
++ Style changes: added a top bar with the site title. It replaces the floating menu on the top right.
++ Added a built-in installer (`app_init.py`). You still need to manually create `site.conf`.
+
## 0.7.1
+ Improved calendar view. Now `/calendar` shows a list of years and months.
diff --git a/README.md b/README.md
index a3173fa..80617eb 100644
--- a/README.md
+++ b/README.md
@@ -43,9 +43,14 @@ name = Salvi
directory = /path/to/database/
```
++ Run `python3 -m app_init` to initialize the database and create the administrator user.
+ Run `flask run`.
+ You can now access Salvi in your browser at port 5000.
+## Caveats
+
++ The whole application is untested.
++ If you forget the password, there is currently no way to reset it.
## License
diff --git a/app.py b/app.py
index b3bdb4b..94ee51f 100644
--- a/app.py
+++ b/app.py
@@ -28,8 +28,9 @@ from urllib.parse import quote
from configparser import ConfigParser
import i18n
import gzip
+from getpass import getpass
-__version__ = '0.7.1'
+__version__ = '0.8-dev'
#### CONSTANTS ####
@@ -65,10 +66,8 @@ if _cfp.read([CONFIG_FILE]):
v = fallback
return v
else:
- def _getconf(k1, k2, fallback=None, cast=None):
- if fallback is None:
- fallback = DEFAULT_CONF.get((k1, k2))
- return fallback
+ print('Uh oh, site.conf not found.')
+ exit(-1)
#### OPTIONAL IMPORTS ####
@@ -148,6 +147,8 @@ class User(BaseModel):
karma = IntegerField(default=1)
privileges = BitField()
is_admin = privileges.flag(1)
+ restrictions = BitField()
+ is_disabled = restrictions.flag(1)
# helpers for flask_login
@property
@@ -155,11 +156,42 @@ class User(BaseModel):
return False
@property
def is_active(self):
- return True
+ return not self.is_disabled
@property
def is_authenticated(self):
return True
+class UserGroup(BaseModel):
+ name = CharField(32, unique=True)
+ permissions = BitField()
+ # Can read pages.
+ can_read = permissions.flag(1)
+ # Can edit all non-locked pages.
+ can_edit = permissions.flag(2)
+ # Can create and edit their own pages.
+ can_create = permissions.flag(4)
+ # Can set page URL.
+ can_set_url = permissions.flag(8)
+ # Can change page tags.
+ can_set_tags = permissions.flag(16)
+
+ @classmethod
+ def get_default_group(cls):
+ try:
+ return cls[1]
+ except cls.DoesNotExist:
+ return cls.get(cls.name == 'default')
+
+class UserGroupMembership(BaseModel):
+ user = ForeignKeyField(User, backref='group_memberships')
+ group = ForeignKeyField(UserGroup, backref='user_memberships')
+ since = DateTimeField(default=datetime.datetime.now)
+
+ class Meta:
+ indexes = (
+ (('user', 'group'), True),
+ )
+
class Page(BaseModel):
url = CharField(64, unique=True, null=True)
@@ -172,6 +204,7 @@ class Page(BaseModel):
is_sync = flags.flag(2)
is_math_enabled = flags.flag(4)
is_locked = flags.flag(8)
+ is_cw = flags.flag(16)
@property
def latest(self):
if self.revisions:
@@ -179,6 +212,8 @@ class Page(BaseModel):
def get_url(self):
return '/' + self.url + '/' if self.url else '/p/{}/'.format(self.id)
def short_desc(self):
+ if self.is_cw:
+ return '(Content Warning)'
full_text = self.latest.text
text = remove_tags(full_text, convert = not self.is_math_enabled and not _getconf('appearance', 'simple_remove_tags', False))
return text[:200] + ('\u2026' if len(text) > 200 else '')
@@ -377,13 +412,76 @@ class PageLink(BaseModel):
def refresh_all_links(cls):
for p in Page.select():
cls.parse_links(p, p.latest.text)
-
+
+class PagePermission(BaseModel):
+ page = ForeignKeyField(Page, backref='permission_overrides')
+ group = ForeignKeyField(UserGroup, backref='page_permissions')
+ permissions = BitField()
+ # Can read pages.
+ can_read = permissions.flag(1)
+ # Can edit all non-locked pages.
+ can_edit = permissions.flag(2)
+ # Can create and edit their own pages.
+ can_create = permissions.flag(4)
+ # Can set page URL.
+ can_set_url = permissions.flag(8)
+ # Can change page tags.
+ can_set_tags = permissions.flag(16)
+
+ class Meta:
+ indexes = (
+ (('page', 'group'), True),
+ )
def init_db():
database.create_tables([
- User, Page, PageText, PageRevision, PageTag, PageProperty, PageLink
+ User, UserGroup, UserGroupMembership,
+ Page, PageText, PageRevision, PageTag, PageProperty, PageLink,
+ PagePermission
])
+def init_db_and_create_first_user():
+ try:
+ User[1]
+ UserGroup[1]
+ except Exception:
+ pass
+ else:
+ print('Looks like this site is already set up!')
+ return
+ username = input('Username: ')
+ password = getpass('Password: ')
+ confirm_password = getpass('Confirm password: ')
+ email = input('Email: (optional)') or None
+ if not is_username(username):
+ print('Invalid username: usernames can contain only letters, numbers, underscores and hyphens.')
+ return
+ if password != confirm_password:
+ print('Passwords do not match.')
+ return
+ default_permissions = 31 # all permissions
+ if not input('Agree to the Terms of Use?')[0].lower() == 'y':
+ print('You must accept Terms in order to register.')
+ return
+ with database.atomic():
+ init_db()
+ ua = User.create(
+ username = username,
+ email = email,
+ password = generate_password_hash(password),
+ join_date = datetime.datetime.now(),
+ is_admin = True
+ )
+ ug = UserGroup.create(
+ name = 'default',
+ permissions = int(default_permissions)
+ )
+ UserGroupMembership.create(
+ user = ua,
+ group = ug
+ )
+ print('Installed successfully!')
+
#### WIKI SYNTAX ####
def md(text, expand_magic=False, toc=True, math=True):
@@ -456,8 +554,7 @@ login_manager.login_view = 'accounts_login'
#### ROUTES ####
-@app.before_request
-def _before_request():
+def _get_lang():
if request.args.get('uselang') is not None:
lang = request.args['uselang']
else:
@@ -468,12 +565,17 @@ def _before_request():
break
else:
lang = 'en'
- g.lang = lang
+ return lang
+
+@app.before_request
+def _before_request():
+ g.lang = _get_lang()
@app.context_processor
def _inject_variables():
+
return {
- 'T': partial(get_string, g.lang),
+ 'T': partial(get_string, _get_lang()),
'app_name': _getconf('site', 'title'),
'strong': lambda x:Markup('{0} ').format(x),
'app_version': __version__,
@@ -492,6 +594,7 @@ def linebreaks(text):
text = text.replace("\n\n", '').replace('\n', ' ')
return Markup(text)
+app.template_filter(name='markdown')(md)
@app.route('/')
def homepage():
@@ -523,6 +626,10 @@ def error_400(body):
@app.errorhandler(500)
def error_500(body):
+ try:
+ User[1]
+ except OperationalError:
+ g.need_install = True
return render_template('internalservererror.jinja2'), 500
# Middle point during page editing.
@@ -550,7 +657,8 @@ def savepoint(form, is_preview=False, pageobj=None):
preview=preview,
pl_js_info=pl_js_info,
pl_calendar=('usecalendar' in form) and form['calendar'],
- pl_readonly=not pageobj.can_edit(current_user) if pageobj else False
+ pl_readonly=not pageobj.can_edit(current_user) if pageobj else False,
+ pl_cw=('cw' in form) and form['cw']
)
@app.route('/create/', methods=['GET', 'POST'])
@@ -581,7 +689,8 @@ def create():
owner_id=current_user.id,
calendar=datetime.date.fromisoformat(request.form["calendar"]) if 'usecalendar' in request.form else None,
is_math_enabled='enablemath' in request.form,
- is_locked = 'lockpage' in request.form
+ is_locked = 'lockpage' in request.form,
+ is_cw = 'cw' in request.form
)
p.change_tags(p_tags)
except IntegrityError as e:
@@ -636,6 +745,7 @@ def edit(id):
p.touched = datetime.datetime.now()
p.is_math_enabled = 'enablemath' in request.form
p.is_locked = 'lockpage' in request.form
+ p.is_cw = 'cw' in request.form
p.calendar = datetime.date.fromisoformat(request.form["calendar"]) if 'usecalendar' in request.form else None
p.save()
p.change_tags(p_tags)
@@ -767,12 +877,6 @@ def view_named(name):
abort(404)
return render_template('view.jinja2', p=p, rev=p.latest)
-@app.route('/init-config/tables/')
-def init_config_tables():
- init_db()
- flash('Tables successfully created.')
- return redirect('/')
-
@app.route('/history//')
def history(id):
try:
@@ -782,6 +886,10 @@ def history(id):
return render_template('history.jinja2', p=p, history=p.revisions.order_by(PageRevision.pub_date.desc()))
@app.route('/u//')
+def contributions_legacy_url(username):
+ return redirect(f'/@{username}/')
+
+@app.route('/@/')
def contributions(username):
try:
user = User.get(User.username == username)
@@ -913,6 +1021,10 @@ def accounts_register():
password = generate_password_hash(password),
join_date = datetime.datetime.now()
)
+ UserGroupMembership.create(
+ user = u,
+ group = UserGroup.get_default_group()
+ )
login_user(u)
return redirect(request.args.get('next', '/'))
@@ -1058,7 +1170,6 @@ class Importer(object):
continue
return no_pages, no_revs
-
@app.route('/manage/export/', methods=['GET', 'POST'])
def exportpages():
if request.method == 'POST':
@@ -1103,6 +1214,16 @@ def importpages():
flash('Pages can be imported by Administrators only!')
return render_template('importpages.jinja2')
+## terms / privacy ##
+
+@app.route('/terms/')
+def terms():
+ return render_template('terms.jinja2')
+
+@app.route('/privacy/')
+def privacy():
+ return render_template('privacy.jinja2')
+
#### EXTENSIONS ####
active_extensions = []
diff --git a/app_init.py b/app_init.py
new file mode 100644
index 0000000..e872b6c
--- /dev/null
+++ b/app_init.py
@@ -0,0 +1,5 @@
+from app import init_db_and_create_first_user
+
+
+if __name__ == '__main__':
+ init_db_and_create_first_user()
\ No newline at end of file
diff --git a/migrations/0_7to0_8.py b/migrations/0_7to0_8.py
index e69de29..92a56cb 100644
--- a/migrations/0_7to0_8.py
+++ b/migrations/0_7to0_8.py
@@ -0,0 +1,23 @@
+from playhouse.migrate import migrate, SqliteMigrator, MySQLMigrator
+from peewee import MySQLDatabase, SqliteDatabase, \
+ IntegerField, DateTimeField, ForeignKeyField, DeferredForeignKey, BitField
+from app import database, UserGroup, UserGroupMembership, PagePermission
+
+
+if type(database) == MySQLDatabase:
+ migrator = MySQLMigrator(database)
+elif type(database) == SqliteDatabase:
+ migrator = SqliteMigrator(database)
+else:
+ print("Unsupported database")
+ exit()
+
+with database.atomic():
+ database.create_tables([UserGroup, UserGroupMembership, PagePermission])
+ migrate(
+ migrator.add_column('user', 'restrictions', BitField())
+ )
+ UserGroup.create(
+ name='default',
+ permissions=31
+ )
\ No newline at end of file
diff --git a/static/style.css b/static/style.css
index 49e1a57..ee5b0d7 100644
--- a/static/style.css
+++ b/static/style.css
@@ -22,8 +22,15 @@
/* basic styles */
* {box-sizing: border-box;}
-body{font-family:sans-serif;background-color:var(--bg-main); color: var(--fg-main)}
+body{font-family:sans-serif;background-color:var(--bg-main); color: var(--fg-main);margin:0;position:relative}
.content{margin: 3em 1.3em}
+.footer{text-align:center;}
+
+/* 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 .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}
/* content styles */
#firstHeading {font-family:sans-serif; text-align: center;font-size:3em; font-weight: normal}
@@ -105,8 +112,6 @@ ul.inline > li:last-child::after {content: ""}
/* floating elements */
-.top-menu{list-style:none;padding:0;margin:0;font-size:0.9em;position:absolute;right:0;top:.5em;text-transform:lowercase}
-.top-menu li{display:inline-block;padding-right:1em}
.toc{float:right}
@media (max-width:639px){
.toc{display:none}
diff --git a/templates/base.jinja2 b/templates/base.jinja2
index 6192923..d66af71 100644
--- a/templates/base.jinja2
+++ b/templates/base.jinja2
@@ -27,23 +27,33 @@
{% endif %}
{% block json_info %}{% endblock %}
-
+
+
{% for msg in get_flashed_messages() %}
{{ msg }}
{% endfor %}
{% block content %}{% endblock %}
-
-
+
{% block scripts %}{% endblock %}
diff --git a/templates/edit.jinja2 b/templates/edit.jinja2
index 45374c9..b574022 100644
--- a/templates/edit.jinja2
+++ b/templates/edit.jinja2
@@ -82,6 +82,10 @@
Use calendar:
+
+
+ Content Warning
+
{% endif %}
diff --git a/templates/history.jinja2 b/templates/history.jinja2
index 3f38d0c..ac47106 100644
--- a/templates/history.jinja2
+++ b/templates/history.jinja2
@@ -22,9 +22,13 @@
{% endif %}
by
+ {% if rev.user_id %}
{{ rev.user.username }}
+ {% else %}
+ <Unknown User>
+ {% endif %}
{% endfor %}
diff --git a/templates/home.jinja2 b/templates/home.jinja2
index 2c02af0..fd0f3ad 100644
--- a/templates/home.jinja2
+++ b/templates/home.jinja2
@@ -18,11 +18,13 @@
{{ n.title }}
{{ n.short_desc() }}
{% if n.tags %}
- {{ T('tags') }}:
- {% for tag in n.tags %}
+
+ tag
+ {{ T('tags') }}:
+ {% for tag in n.tags %}
{% set tn = tag.name %}
#{{ tn }}
- {% endfor %}
+ {% endfor %}
{% endif %}
{% if n.calendar %}
diff --git a/templates/listrecent.jinja2 b/templates/listrecent.jinja2
index deebe66..fa6ae03 100644
--- a/templates/listrecent.jinja2
+++ b/templates/listrecent.jinja2
@@ -14,11 +14,13 @@
{{ n.title }}
{{ n.short_desc() }}
{% if n.tags %}
- {{ T('tags') }}:
- {% for tag in n.tags %}
+
+ tag
+ {{ T('tags') }}:
+ {% for tag in n.tags %}
{% set tn = tag.name %}
#{{ tn }}
- {% endfor %}
+ {% endfor %}
{% endif %}
{% if n.calendar %}
diff --git a/templates/listtag.jinja2 b/templates/listtag.jinja2
index 4249bfe..c7c07aa 100644
--- a/templates/listtag.jinja2
+++ b/templates/listtag.jinja2
@@ -16,21 +16,23 @@
{{ n.title }}
{{ n.short_desc() }}
- Tags:
- {% for tag in n.tags %}
+
+ tag
+ {{ T('tags') }}:
+ {% for tag in n.tags %}
{% set tn = tag.name %}
{% if tn == tagname %}
#{{ tn }}
{% else %}
#{{ tn }}
{% endif %}
- {% endfor %}
- {% if n.calendar %}
-
- calendar_today
- {{ n.calendar.strftime('%B %-d, %Y') }}
-
- {% endif %}
+ {% endfor %}
+ {% if n.calendar %}
+
+ calendar_today
+ {{ n.calendar.strftime('%B %-d, %Y') }}
+
+ {% endif %}
{% endfor %}
diff --git a/templates/privacy.jinja2 b/templates/privacy.jinja2
new file mode 100644
index 0000000..a631f98
--- /dev/null
+++ b/templates/privacy.jinja2
@@ -0,0 +1,46 @@
+{% extends "base.jinja2" %}
+
+{% block title %}Privacy Policy — {{ app_name }}{% endblock %}
+
+
+{% block content %}
+
+Privacy Policy
+
+
+{% filter markdown %}
+# Privacy
+
+## Cookies
+
+{{ app_name }} uses one cryptographically signed cookie to maintain secure authenticated sessions. This cookie is randomized with each new session.
+
+This cookie is used for the following purposes:
+
+* Authentication
+* Abuse mitigation
+* Per-device settings like light/dark theme selection.
+
+This cookie is mandatory and cannot be opted out. Manual alteration or removal of this cookie will result in deauthentication and reversion to default per-device settings.
+
+## Your information
+
+We collect basic information in order to operate the platform, and to mitigate abuse. This includes:
+
+* Your email address, if you choose to provide it.
+* The IP address from which content is submitted.
+* Whether or not you have indicated that you are 18 years of age.
+* Other saved personal preferances, which you can edit from your account settings.
+
+We use - and then promptly forget - the following information about you from third parties:
+
+* Verification from our captcha provider that you aren't a bot, during account registration
+
+{{ app_name }} will not release your information to third parties, except:
+
+* As required by Italian law
+* At our discretion, {{ app_name }} may share your information with Italian law enforcement in the event of an emergency, if we have good cause to believe that doing so would avert or mitigate the emergency.
+{% endfilter %}
+
+
+{% endblock %}
diff --git a/templates/register.jinja2 b/templates/register.jinja2
index f255136..5b2f9d2 100644
--- a/templates/register.jinja2
+++ b/templates/register.jinja2
@@ -25,7 +25,7 @@
diff --git a/templates/terms.jinja2 b/templates/terms.jinja2
new file mode 100644
index 0000000..e02b8a6
--- /dev/null
+++ b/templates/terms.jinja2
@@ -0,0 +1,145 @@
+{% extends "base.jinja2" %}
+
+{% block title %}Terms of Service — {{ app_name }}{% endblock %}
+
+{% block content %}
+
Terms of Service
+
+
+{% filter markdown %}
+## Scope and Definitions
+
+These terms of service ("Terms") are between {{ app_name }}
+("{{ request.headers['Host'] }}") and You, regarding Your use of the social platform
+{{ app_name }}, and any other services or test servers which may exist
+now or in the future (collectively "{{ app_name }}").
+
+Content on this page displayed in blockquotes is provided for convenience
+and readability only. Blockquote text is not part of the terms of service.
+
+## Conduct and content
+
+You agree to follow the Content Policy [here](/rules/).
+The Content Policy is incorporated into these Terms by this reference.
+
+## Age
+
+You warrant that You are at least 13 years old.
+You warrant that You are at least 18 years old,
+if You indicate as such in Your user settings.
+
+
+## Account Access
+
+Your {{ app_name }} account is nontransferable. You will not buy, sell, gift, loan, or otherwise grant a third party access to Your {{ app_name }} account. You will not provide a third party with Your {{ app_name }} password or two-factor authentication codes.
+
+In the event that Your {{ app_name }} account is accessed by a third party anyways, You remain accountable for all actions taken by Your account.
+
+## Liability
+
+{{ app_name }} shall not be liable for Your damages arising from any of the following:
+
+* Use of the {{ app_name }} platform
+* Technical failure of {{ app_name }}
+* Administrative actions performed by {{ app_name }}, including both automatic and manual actions
+* Unauthorized access of a third party to Your {{ app_name }} account
+* Loss or breach of {{ app_name }} data
+* Force majeur
+
+You accept full liability for all content You upload to, or embed within, {{ app_name }}, and indemnify {{ app_name }} from all such liability.
+
+> You are responsible for everything You do, and everything that happens with, with Your {{ app_name }} account. Don't use {{ app_name }} to store important data or sensitive data.
+
+## Intellectual Property
+
+You grant {{ app_name }} a permanent, worldwide, and irrevocable license to store, modify, copy, and distribute all content that You submit to or upload to {{ app_name }}, including any creative works. Additionally, You grant {{ app_name }} a permanent, worldwide, and irrevocable license to sublicense these same rights to {{ app_name }}'s service providers. Additionally, You warrant that You are authorized to grant {{ app_name }} these rights.
+
+You retain all other intellectual property rights, including ownership.
+
+> We need to be able to store, copy, and distribute Your content, because that's just how websites like {{ app_name }} work. We also need to be able to modify it for security and formatting purposes.
+
+## Acceptable Use
+
+You will not use {{ app_name }} as a means to support any other website or service without written permission by {{ app_name }}.
+
+You will not attempt to gain access to a {{ app_name }} account that does not belong to You.
+
+You will not use {{ app_name }} to engage in child sexual abuse activities, as defined in the [CSAM Policy](/help/csam). The CSAM Policy is incorporated into these terms by this reference.
+
+## Multiple Accounts
+
+You are permitted to create and use multiple {{ app_name }} accounts.
+
+You will not use multiple accounts to circumvent per-user limits.
+
+Additionally, these terms apply to all of Your accounts, which may exist now or in the future. {{ app_name }} reserves the right to take administrative action against all of Your accounts in the event of a terms of service violation on any of Your accounts.
+
+## Your Privacy
+
+{{ app_name }} will never intentionally share Your personal information with third parties, except:
+
+* As required by United States law.
+* We will share Your data with our own service providers that are necessary for {{ app_name }} operations.
+* At our discretion, {{ app_name }} may share Your information with United States law enforcement in the event of an emergency, if we have good cause to believe that doing so would avert or mitigate the emergency.
+
+{{ app_name }} will make all reasonable efforts to ensure that user information is kept confidential.
+
+## Legal Forms
+
+{{ app_name }} grants You the ability to use Your {{ app_name }} account to send us certain types of legal forms through our help portal. These include, but are not limited to:
+
+* DMCA takedown request
+* DMCA takedown counter-request
+* Subpoenas and court orders
+
+You acknowledge that these forms are provided for the sake of convenience and speed, and that {{ app_name }} does not waive any of its rights regarding legal process, including the right to object for lack of proper service.
+
+You agree to refrain from making abusive, frivolous, or otherwise improper submissions to these forms. This includes, but is not limited to:
+
+* Nonsensical or incomplete requests
+* Duplicate submissions
+* DMCA takedown requests not made in good faith
+* DMCA takedown requests for content protected by Fair Use
+* DMCA takedown requests for content that you are not authorized to claim.
+* Legal demands not based in fact and/or not backed by appropriate law.
+* Legal documents from courts or law enforcement that lack jurisdiction inside the United States
+* Legal documents that are not in English and are not accompanied by an official English translation.
+
+## Enforcement
+
+{{ app_name }} retains sole discretion in all determinations regarding content policy and terms of service violations.
+
+{{ app_name }} reserves the right to remove content that we deem to violate content policy or the terms of service, and to deactivate accounts responsible for such violations.
+
+## Severability
+
+If one clause of these Terms or the Content Policy is determined by a court to be unenforceable, the remainder of the Terms and Content Policy shall remain in force.
+
+## No Implied Waiver
+
+A failure by {{ app_name }} in one or more instances to insist upon Your strict adherence to these terms or the Content Policy, shall not be construed as a waiver of any continuing or subsequent violations of these terms or the Content Policy.
+
+## Completeness
+
+These Terms, together with the other policies incorporated into them by reference, contain all the terms and conditions agreed upon by You and {{ app_name }} regarding Your use of the {{ app_name }} service. No other agreement, oral or otherwise, will be deemed to exist or to bind either of the parties to this Agreement.
+
+## Governing Law
+
+These terms of service are governed by, and shall be interpreted in accordance with, the laws of Italy. You consent to the sole jurisdiction of Italy for all disputes between You and {{ app_name }}, and You consent to the sole application of Italian and E.U. law for all such disputes.
+
+## Updates
+
+{{ app_name }} may periodically update these terms of service and/or the Content Policy. When this happens, {{ app_name }} will make reasonable efforts to notify You of such changes.
+
+Whenever {{ app_name }} updates these terms of service or the Content Policy, Your continued use of the {{ app_name }} platform constitutes Your agreement to the updated terms of service.
+
+## Translations
+
+If there is any inconsistency between these terms and any translation into other languages, the English language version takes precedence.
+
+
+
+{% endfilter %}
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/templates/view.jinja2 b/templates/view.jinja2
index 76fbb8e..14f3f81 100644
--- a/templates/view.jinja2
+++ b/templates/view.jinja2
@@ -19,6 +19,14 @@
{% block history_nav %}{% endblock %}
+ {% if p.is_cw %}
+
+ Content Warning -
+ this page may contain shocking or unexpected content, spoilers, or similar.
+ Proceed with caution.
+
+ {% endif %}
+
{{ rev.html(math = request.args.get('math') not in ['0', 'false', 'no', 'off'])|safe }}
From 4536f7fbd96e46c04d6bfc52fd7200977de5fa95 Mon Sep 17 00:00:00 2001
From: Mattia Succurro
Date: Mon, 20 Mar 2023 10:40:39 +0100
Subject: [PATCH 21/44] print style fixes
---
static/style.css | 1 +
1 file changed, 1 insertion(+)
diff --git a/static/style.css b/static/style.css
index ee5b0d7..e139c73 100644
--- a/static/style.css
+++ b/static/style.css
@@ -119,6 +119,7 @@ ul.inline > li:last-child::after {content: ""}
.backontop{position:fixed;bottom:0;right:0}
@media print{
.backontop {display:none}
+ .header{position:static}
}
#__top{position:absolute;top:0;left:0}
From 191e2351375596934810d403e9f6f3a282dd3323 Mon Sep 17 00:00:00 2001
From: Mattia Succurro
Date: Wed, 22 Mar 2023 09:49:38 +0100
Subject: [PATCH 22/44] added /manage/ and /manage/accounts/ views, added TOC
to template
---
CHANGELOG.md | 3 ++
app.py | 62 +++++++++++++++++++++++++++------
static/style.css | 9 ++---
templates/administration.jinja2 | 23 ++++++++++++
templates/base.jinja2 | 1 +
templates/contributions.jinja2 | 17 +++++++--
templates/manageaccounts.jinja2 | 52 +++++++++++++++++++++++++++
templates/notfound.jinja2 | 4 +--
templates/view.jinja2 | 12 +++++--
9 files changed, 162 insertions(+), 21 deletions(-)
create mode 100644 templates/administration.jinja2
create mode 100644 templates/manageaccounts.jinja2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 63b5360..a030905 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,9 @@
caution message when viewing them.
+ Added Terms and Privacy Policy.
+ Changed user page URLs (contributions page) from `/u/user` to `/@user`.
++ `/manage/` is now a list of all managing options, including export/import and the brand new
+ `/manage/accounts`.
++ TOC is now shown in pages where screen width is greater than 960 pixels.
+ Style changes: added a top bar with the site title. It replaces the floating menu on the top right.
+ Added a built-in installer (`app_init.py`). You still need to manually create `site.conf`.
diff --git a/app.py b/app.py
index 94ee51f..95f0ad4 100644
--- a/app.py
+++ b/app.py
@@ -161,6 +161,12 @@ class User(BaseModel):
def is_authenticated(self):
return True
+ def groups(self):
+ return (
+ UserGroup.select().join(UserGroupMembership, on=UserGroupMembership.group)
+ .where(UserGroupMembership.user == self)
+ )
+
class UserGroup(BaseModel):
name = CharField(32, unique=True)
permissions = BitField()
@@ -295,6 +301,8 @@ class PageRevision(BaseModel):
return self.textref.get_content()
def html(self, *, math=True):
return md(self.text, math=self.page.is_math_enabled and math)
+ def html_and_toc(self, *, math=True):
+ return md_and_toc(self.text, math=self.page.is_math_enabled and math)
def human_pub_date(self):
delta = datetime.datetime.now() - self.pub_date
T = partial(get_string, g.lang)
@@ -484,7 +492,7 @@ def init_db_and_create_first_user():
#### WIKI SYNTAX ####
-def md(text, expand_magic=False, toc=True, math=True):
+def md_and_toc(text, expand_magic=False, toc=True, math=True):
if expand_magic:
# DEPRECATED seeking for a better solution.
warnings.warn('Magic words are no more supported.', DeprecationWarning)
@@ -502,9 +510,16 @@ def md(text, expand_magic=False, toc=True, math=True):
'insert_fonts_css': not _getconf('site', 'katex_url')
}
try:
- return markdown.Markdown(extensions=extensions, extension_configs=extension_configs).convert(text)
+ converter = markdown.Markdown(extensions=extensions, extension_configs=extension_configs)
+ if toc:
+ return converter.convert(text), converter.toc
+ else:
+ return converter.convert(text), ''
except Exception as e:
- return 'There was an error during rendering: {e.__class__.__name__}: {e}
'.format(e=e)
+ return 'There was an error during rendering: {e.__class__.__name__}: {e}
'.format(e=e), ''
+
+def md(text, expand_magic=False, toc=True, math=True):
+ return md_and_toc(text, expand_magic=expand_magic, toc=toc, math=math)[0]
def remove_tags(text, convert=True, headings=True):
if headings:
@@ -538,7 +553,7 @@ def is_url_available(url):
forbidden_urls = [
'about', 'accounts', 'ajax', 'backlinks', 'calendar', 'circles', 'create',
- 'easter', 'edit', 'embed', 'help', 'history', 'init-config', 'kt',
+ 'easter', 'edit', 'embed', 'group', 'help', 'history', 'init-config', 'kt',
'manage', 'media', 'p', 'privacy', 'protect', 'search', 'static', 'stats',
'tags', 'terms', 'u', 'upload', 'upload-info'
]
@@ -783,11 +798,7 @@ def edit(id):
@app.route("/__sync_start")
def __sync_start():
- if _getconf("sync", "master", "this") == "this":
- abort(403)
- from app_sync import main
- main()
- flash("Successfully synced messages.")
+ flash("Sync is unavailable. Please import and export pages manually.")
return redirect("/")
@app.route('/_jsoninfo/', methods=['GET', 'POST'])
@@ -895,7 +906,15 @@ def contributions(username):
user = User.get(User.username == username)
except User.DoesNotExist:
abort(404)
- return render_template('contributions.jinja2', u=user, contributions=user.contributions.order_by(PageRevision.pub_date.desc()))
+ contributions = user.contributions.order_by(PageRevision.pub_date.desc())
+ page = int(request.args.get('page', 1))
+ return render_template('contributions.jinja2',
+ u=user,
+ contributions=contributions.paginate(page),
+ page_n=page,
+ total_count=contributions.count(),
+ min=min
+ )
@app.route('/calendar/')
def calendar_view():
@@ -1083,6 +1102,12 @@ def easter_y(y=None):
else:
return render_template('easter.jinja2')
+## administration ##
+
+@app.route('/manage/')
+def manage_main():
+ return render_template('administration.jinja2')
+
## import / export ##
class Exporter(object):
@@ -1214,6 +1239,23 @@ def importpages():
flash('Pages can be imported by Administrators only!')
return render_template('importpages.jinja2')
+@app.route('/manage/accounts/', methods=['GET', 'POST'])
+@login_required
+def manage_accounts():
+ users = User.select().order_by(User.join_date.desc())
+ page = int(request.args.get('page', 1))
+ if request.method == 'POST':
+ if current_user.is_admin:
+ pass
+ else:
+ flash('Operation not permitted!')
+ return render_template('manageaccounts.jinja2',
+ users=users.paginate(page),
+ page_n=page,
+ total_count=users.count(),
+ min=min
+ )
+
## terms / privacy ##
@app.route('/terms/')
diff --git a/static/style.css b/static/style.css
index e139c73..e30a246 100644
--- a/static/style.css
+++ b/static/style.css
@@ -23,7 +23,7 @@
/* basic styles */
* {box-sizing: border-box;}
body{font-family:sans-serif;background-color:var(--bg-main); color: var(--fg-main);margin:0;position:relative}
-.content{margin: 3em 1.3em}
+.content{margin: 3em 1.3em; position: relative}
.footer{text-align:center;}
/* header styles */
@@ -112,9 +112,10 @@ ul.inline > li:last-child::after {content: ""}
/* floating elements */
-.toc{float:right}
-@media (max-width:639px){
- .toc{display:none}
+nav.toc{display:none}
+@media only screen and (min-width:960px){
+ nav.toc{display:block;position:absolute; top: 0; right: 0; width: 320px;}
+ .inner-content {margin-right: 320px}
}
.backontop{position:fixed;bottom:0;right:0}
@media print{
diff --git a/templates/administration.jinja2 b/templates/administration.jinja2
new file mode 100644
index 0000000..39ce634
--- /dev/null
+++ b/templates/administration.jinja2
@@ -0,0 +1,23 @@
+{% extends "base.jinja2" %}
+
+{% block title %}Administrative tools — {{ app_name }}{% endblock %}
+
+{% block content %}
+Administrative tools
+
+{% 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/base.jinja2 b/templates/base.jinja2
index d66af71..288bd0a 100644
--- a/templates/base.jinja2
+++ b/templates/base.jinja2
@@ -52,6 +52,7 @@
{{ msg }}
{% endfor %}
{% block content %}{% endblock %}
+ {% block toc %}{% endblock %}