From 7923f4889c02b19ba4fd6d8a1e29bd45ae6ce866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sun, 9 Apr 2023 23:41:10 +0200 Subject: [PATCH] fix depracation warnings (sqlalchemy 2.0), fix installable plugin --- backend/flaschengeist_events/__init__.py | 17 ++++++++++------- backend/flaschengeist_events/models.py | 11 ++++++++--- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/backend/flaschengeist_events/__init__.py b/backend/flaschengeist_events/__init__.py index ff707d2..9cf458e 100644 --- a/backend/flaschengeist_events/__init__.py +++ b/backend/flaschengeist_events/__init__.py @@ -14,14 +14,17 @@ __version__ = pkg_resources.get_distribution("flaschengeist_events").version class EventPlugin(Plugin): - id = "dev.flaschengeist.events" - plugin = LocalProxy(lambda: current_app.config["FG_PLUGINS"][EventPlugin.id]) + #id = "dev.flaschengeist.events" + #plugin = LocalProxy(lambda: current_app.config["FG_PLUGINS"][EventPlugin.id]) # provided resources - permissions = permissions.permissions + #permissions = permissions.permissions blueprint = Blueprint("events", __name__) models = models - def __init__(self, cfg): - super(EventPlugin, self).__init__(cfg) - from . import routes - from .event_controller import clear_services + # def __init__(self, cfg): + # super(EventPlugin, self).__init__(cfg) + # from . import routes + # from .event_controller import clear_services + + def install(self): + self.install_permissions(permissions.permissions) diff --git a/backend/flaschengeist_events/models.py b/backend/flaschengeist_events/models.py index 47dc293..c69bc7f 100644 --- a/backend/flaschengeist_events/models.py +++ b/backend/flaschengeist_events/models.py @@ -1,7 +1,7 @@ from __future__ import annotations # TODO: Remove if python requirement is >= 3.10 from datetime import datetime -from typing import Optional, Union +from typing import Optional, Union, List from sqlalchemy import UniqueConstraint @@ -17,6 +17,7 @@ _table_prefix_ = "events_" class EventType(db.Model, ModelSerializeMixin): + __allow_unmapped__ = True __tablename__ = _table_prefix_ + "event_type" id: int = db.Column(Serial, primary_key=True) name: str = db.Column(db.String(30), nullable=False, unique=True) @@ -34,6 +35,7 @@ class JobType(db.Model, ModelSerializeMixin): class Service(db.Model, ModelSerializeMixin): + __allow_unmapped__ = True __tablename__ = _table_prefix_ + "service" userid: str = "" is_backup: bool = db.Column(db.Boolean, default=False) @@ -57,6 +59,7 @@ class Service(db.Model, ModelSerializeMixin): class Job(db.Model, ModelSerializeMixin): + __allow_unmapped__ = True __tablename__ = _table_prefix_ + "job" id: int = db.Column(Serial, primary_key=True) @@ -65,7 +68,7 @@ class Job(db.Model, ModelSerializeMixin): comment: Optional[str] = db.Column(db.String(256)) type: int = db.Column("type_id", Serial, db.ForeignKey(f"{_table_prefix_}job_type.id"), nullable=False) locked: bool = db.Column(db.Boolean(), default=False, nullable=False) - services: list[Service] = db.relationship( + services: List[Service] = db.relationship( "Service", back_populates="job_", cascade="save-update, merge, delete, delete-orphan" ) required_services: float = db.Column(db.Numeric(precision=4, scale=2, asdecimal=False), nullable=False) @@ -85,6 +88,7 @@ class Job(db.Model, ModelSerializeMixin): class Event(db.Model, ModelSerializeMixin): """Model for an Event""" + __allow_unmapped__ = True __tablename__ = _table_prefix_ + "event" id: int = db.Column(Serial, primary_key=True) start: datetime = db.Column(UtcDateTime, nullable=False) @@ -93,7 +97,7 @@ class Event(db.Model, ModelSerializeMixin): description: Optional[str] = db.Column(db.String(512)) type: Union[EventType, int] = db.relationship("EventType") is_template: bool = db.Column(db.Boolean, default=False) - jobs: list[Job] = db.relationship( + jobs: List[Job] = db.relationship( "Job", back_populates="event_", cascade="all,delete,delete-orphan", @@ -109,6 +113,7 @@ class Event(db.Model, ModelSerializeMixin): class Invitation(db.Model, ModelSerializeMixin): + __allow_unmapped__ = True __tablename__ = _table_prefix_ + "invitation" id: int = db.Column(Serial, primary_key=True)