Compare commits
3 Commits
b8ac6eb462
...
22fbb526bb
Author | SHA1 | Date |
---|---|---|
Ferdinand Thiessen | 22fbb526bb | |
Ferdinand Thiessen | d9be9430db | |
Ferdinand Thiessen | 4df7f1cc01 |
|
@ -1,8 +1,4 @@
|
||||||
""" Server-package
|
"""Flaschengeist"""
|
||||||
|
|
||||||
Initialize app, CORS, database and add it to the application.
|
|
||||||
|
|
||||||
"""
|
|
||||||
import logging
|
import logging
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
@ -10,5 +6,7 @@ from werkzeug.local import LocalProxy
|
||||||
|
|
||||||
__version__ = pkg_resources.get_distribution("flaschengeist").version
|
__version__ = pkg_resources.get_distribution("flaschengeist").version
|
||||||
_module_path = Path(__file__).parent
|
_module_path = Path(__file__).parent
|
||||||
|
__pdoc__ = {}
|
||||||
|
|
||||||
logger: logging.Logger = LocalProxy(lambda: logging.getLogger(__name__))
|
logger: logging.Logger = LocalProxy(lambda: logging.getLogger(__name__))
|
||||||
|
__pdoc__["logger"] = "Flaschengeist's logger instance (`werkzeug.local.LocalProxy`)"
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
"""Basic controllers for interaction with the Flaschengeist core"""
|
|
@ -99,7 +99,7 @@ def set_roles(user: User, roles: list[str], create=False):
|
||||||
roles: List of role names
|
roles: List of role names
|
||||||
create: If set to true, create not existing roles
|
create: If set to true, create not existing roles
|
||||||
Raises:
|
Raises:
|
||||||
BadRequest if invalid arguments given or not all roles found while `create` is set to false
|
BadRequest if invalid arguments given or not all roles found while *create* is set to false
|
||||||
"""
|
"""
|
||||||
from roleController import create_role
|
from roleController import create_role
|
||||||
|
|
||||||
|
|
|
@ -54,10 +54,21 @@ class Plugin:
|
||||||
If your class uses custom models add a static property called ``models``"""
|
If your class uses custom models add a static property called ``models``"""
|
||||||
|
|
||||||
blueprint = None # You have to override
|
blueprint = None # You have to override
|
||||||
|
"""Override with a `flask.blueprint` if the plugin uses custom routes"""
|
||||||
permissions = [] # You have to override
|
permissions = [] # You have to override
|
||||||
|
"""Override to add custom permissions used by the plugin
|
||||||
|
|
||||||
|
A good style is to name the permissions with a prefix related to the plugin name,
|
||||||
|
to prevent clashes with other plugins. E. g. instead of *delete* use *plugin_delete*.
|
||||||
|
"""
|
||||||
id = "dev.flaschengeist.plugin" # You have to override
|
id = "dev.flaschengeist.plugin" # You have to override
|
||||||
|
"""Override with the unique ID of the plugin (Hint: FQN)"""
|
||||||
name = "plugin" # You have to override
|
name = "plugin" # You have to override
|
||||||
|
"""Override with human readable name of the plugin"""
|
||||||
models = None # You have to override
|
models = None # You have to override
|
||||||
|
"""Override with models module"""
|
||||||
|
migrations_path = None # Override this with the location of your db migrations directory
|
||||||
|
"""Override with path to migration files, if custome db tables are used"""
|
||||||
|
|
||||||
def __init__(self, config=None):
|
def __init__(self, config=None):
|
||||||
"""Constructor called by create_app
|
"""Constructor called by create_app
|
||||||
|
@ -68,17 +79,21 @@ class Plugin:
|
||||||
|
|
||||||
def install(self):
|
def install(self):
|
||||||
"""Installation routine
|
"""Installation routine
|
||||||
|
|
||||||
Is always called with Flask application context
|
Is always called with Flask application context
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_setting(self, name: str, **kwargs):
|
def get_setting(self, name: str, **kwargs):
|
||||||
"""Get plugin setting from database
|
"""Get plugin setting from database
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
name: string identifying the setting
|
name: string identifying the setting
|
||||||
default: Default value
|
default: Default value
|
||||||
Returns:
|
Returns:
|
||||||
Value stored in database (native python)
|
Value stored in database (native python)
|
||||||
|
Raises:
|
||||||
|
`KeyError` if no such setting exists in the database
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
setting = (
|
setting = (
|
||||||
|
@ -95,6 +110,7 @@ class Plugin:
|
||||||
|
|
||||||
def set_setting(self, name: str, value):
|
def set_setting(self, name: str, value):
|
||||||
"""Save setting in database
|
"""Save setting in database
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
name: String identifying the setting
|
name: String identifying the setting
|
||||||
value: Value to be stored
|
value: Value to be stored
|
||||||
|
@ -114,10 +130,22 @@ class Plugin:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
def notify(self, user, text: str, data=None):
|
def notify(self, user, text: str, data=None):
|
||||||
|
"""Create a new notification for an user
|
||||||
|
|
||||||
|
Args:
|
||||||
|
user: `flaschengeist.models.user.User` to notify
|
||||||
|
text: Visibile notification text
|
||||||
|
data: Optional data passed to the notificaton
|
||||||
|
Returns:
|
||||||
|
ID of the created `flaschengeist.models.notification.Notification`
|
||||||
|
|
||||||
|
Hint: use the data for frontend actions.
|
||||||
|
"""
|
||||||
if not user.deleted:
|
if not user.deleted:
|
||||||
n = Notification(text=text, data=data, plugin=self.id, user_=user)
|
n = Notification(text=text, data=data, plugin=self.id, user_=user)
|
||||||
db.session.add(n)
|
db.session.add(n)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
return n.id
|
||||||
|
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
"""Serialize a plugin into a dict
|
"""Serialize a plugin into a dict
|
||||||
|
|
|
@ -40,7 +40,7 @@ class Transaction(db.Model, ModelSerializeMixin):
|
||||||
|
|
||||||
@sender_id.expression
|
@sender_id.expression
|
||||||
def sender_id(cls):
|
def sender_id(cls):
|
||||||
return db.select([User.userid]).where(cls._sender_id == User.id_).as_scalar()
|
return db.select([User.userid]).where(cls._sender_id == User.id_).scalar_subquery()
|
||||||
|
|
||||||
@hybrid_property
|
@hybrid_property
|
||||||
def receiver_id(self):
|
def receiver_id(self):
|
||||||
|
@ -48,7 +48,7 @@ class Transaction(db.Model, ModelSerializeMixin):
|
||||||
|
|
||||||
@receiver_id.expression
|
@receiver_id.expression
|
||||||
def receiver_id(cls):
|
def receiver_id(cls):
|
||||||
return db.select([User.userid]).where(cls._receiver_id == User.id_).as_scalar()
|
return db.select([User.userid]).where(cls._receiver_id == User.id_).scalar_subquery()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def author_id(self):
|
def author_id(self):
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
"""Common utilities"""
|
Loading…
Reference in New Issue