From 7413437b4c4af5dbbc57b85f82fed7c0340e036b Mon Sep 17 00:00:00 2001 From: Mattia Succurro Date: Tue, 17 Aug 2021 06:24:15 +0200 Subject: [PATCH] Some minor fixes to app_sync.py --- app_sync.py | 4 +- extensions/circles.py | 86 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 extensions/circles.py diff --git a/app_sync.py b/app_sync.py index 9dbc123..25ba22d 100644 --- a/app_sync.py +++ b/app_sync.py @@ -1,6 +1,8 @@ """ Helper module for sync. +Remember to set sync:master variable in site.conf! + (c) 2021 Sakuragasaki46. """ @@ -118,7 +120,7 @@ def main(): failed += 1 continue else: - if pageinfo["touched"] > p.touched: + if pageinfo["touched"] > p.touched.timestamp(): update_page(p, pageinfo) passed += 1 with open(DATABASE_DIR + "/last_sync", "w") as fw: diff --git a/extensions/circles.py b/extensions/circles.py new file mode 100644 index 0000000..5b2993e --- /dev/null +++ b/extensions/circles.py @@ -0,0 +1,86 @@ +# (C) 2020-2021 Sakuragasaki46. +# See LICENSE for copying info. + +''' +Circles (people) extension for Salvi. +''' + +from peewee import * +from ..app import _getconf + +#### HELPERS #### + +def _getmbt(s): + s = s.upper() + try: + return 16 + ( + dict(I=0, E=8)[s[0]] | + dict(N=0, S=4)[s[1]] | + dict(T=0, F=2)[s[2]] | + dict(J=0, P=1)[s[3]] + ) + except Exception: + return 2 + + +def _putmbt(s): + if s & 16 == 0: + return "1x38b" + return ''.join(( + 'IE'[(s & 8) >> 3], + 'NS'[(s & 4) >> 2], + 'TF'[(s & 2) >> 1], + 'JP'[s & 1] + )) + + +#### DATABASE SCHEMA #### + +database = SqliteDatabase(_getconf("config", "database_dir") + '/circles.sqlite') + +class BaseModel(Model): + class Meta: + database = database + +class MbTypeField(Field): + field_type = 'integer' + + def db_value(self, value): + return _getmbt(value) + def python_value(self, value): + return _putmbt(value) + +ST_ORANGE = 0 +ST_YELLOW = 1 +ST_GREEN = 2 +ST_RED = -1 + +class Person(BaseModel): + code = IntegerField(primary_key=True) + display_name = CharField(256) + first_name = CharField(128, null=True) + last_name = CharField(128, null=True) + circle = IntegerField(default=7, index=True) + status = IntegerField(default=ST_ORANGE, index=True) + type = MbTypeField(default=0, index=True) + class Meta: + indexes = ( + (('last_name', 'first_name'), False), + ) + +def init_db(): + database.create_tables([Person]) + +#### ROUTING #### + +bp = Blueprint('circles', __name__, + url_prefix='/circles') + +@bp.route('/init-config') +def _init_config(): + init_db() + return redirect('/circles') + +@bp.route('/') +def homepage(): + return render_template("base.html")