Files

35 lines
1.1 KiB
Python

import os, logging
from typing import override
from flask import Blueprint, send_from_directory, jsonify, app
from base.basemodule import BaseModule, SyncResult
class TestModule(BaseModule):
def __init__(self, app: app):
name = "testmodule"
faIcon = "fa-vial"
blueprint = Blueprint(
"testmodule", __name__,
static_folder="static",
static_url_path=f"/static" # prefix /module/<name> comes from BaseModule
)
blueprint.add_url_rule("/api/status", view_func=self.status_api, methods=["GET"])
super().__init__(app=app, name=name, faIcon=faIcon, blueprint=blueprint)
def status_api(self):
return jsonify({"status": "ok", "value": 42})
@override
def get_page(self):
return send_from_directory(
os.path.join(self.blueprint.root_path, "static"),
"_page.html"
)
@override
def sync(self):
logging.getLogger(__name__).info("Syncing testmodule")
return SyncResult(success=True, msg="Updated")
MODULE_CLASS = TestModule