Compare commits
No commits in common. "22fbb526bb2f2bf5912dbd31dc8f1029b1732c9b" and "b8ac6eb462366074a4dbffa50c7e21c56eb8d053" have entirely different histories.
22fbb526bb
...
b8ac6eb462
|
@ -1,4 +1,8 @@
|
||||||
"""Flaschengeist"""
|
""" Server-package
|
||||||
|
|
||||||
|
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
|
||||||
|
@ -6,7 +10,5 @@ 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`)"
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
"""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,21 +54,10 @@ 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
|
||||||
|
@ -79,21 +68,17 @@ 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 = (
|
||||||
|
@ -110,7 +95,6 @@ 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
|
||||||
|
@ -130,22 +114,10 @@ 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_).scalar_subquery()
|
return db.select([User.userid]).where(cls._sender_id == User.id_).as_scalar()
|
||||||
|
|
||||||
@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_).scalar_subquery()
|
return db.select([User.userid]).where(cls._receiver_id == User.id_).as_scalar()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def author_id(self):
|
def author_id(self):
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
"""Common utilities"""
|
|
Loading…
Reference in New Issue