fix depracation warnings (sqlalchemy 2.0), fix installable plugin

This commit is contained in:
Tim Gröger 2023-04-09 23:41:10 +02:00
parent 75fa825962
commit 7923f4889c
2 changed files with 18 additions and 10 deletions

View File

@ -14,14 +14,17 @@ __version__ = pkg_resources.get_distribution("flaschengeist_events").version
class EventPlugin(Plugin): class EventPlugin(Plugin):
id = "dev.flaschengeist.events" #id = "dev.flaschengeist.events"
plugin = LocalProxy(lambda: current_app.config["FG_PLUGINS"][EventPlugin.id]) #plugin = LocalProxy(lambda: current_app.config["FG_PLUGINS"][EventPlugin.id])
# provided resources # provided resources
permissions = permissions.permissions #permissions = permissions.permissions
blueprint = Blueprint("events", __name__) blueprint = Blueprint("events", __name__)
models = models models = models
def __init__(self, cfg): # def __init__(self, cfg):
super(EventPlugin, self).__init__(cfg) # super(EventPlugin, self).__init__(cfg)
from . import routes # from . import routes
from .event_controller import clear_services # from .event_controller import clear_services
def install(self):
self.install_permissions(permissions.permissions)

View File

@ -1,7 +1,7 @@
from __future__ import annotations # TODO: Remove if python requirement is >= 3.10 from __future__ import annotations # TODO: Remove if python requirement is >= 3.10
from datetime import datetime from datetime import datetime
from typing import Optional, Union from typing import Optional, Union, List
from sqlalchemy import UniqueConstraint from sqlalchemy import UniqueConstraint
@ -17,6 +17,7 @@ _table_prefix_ = "events_"
class EventType(db.Model, ModelSerializeMixin): class EventType(db.Model, ModelSerializeMixin):
__allow_unmapped__ = True
__tablename__ = _table_prefix_ + "event_type" __tablename__ = _table_prefix_ + "event_type"
id: int = db.Column(Serial, primary_key=True) id: int = db.Column(Serial, primary_key=True)
name: str = db.Column(db.String(30), nullable=False, unique=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): class Service(db.Model, ModelSerializeMixin):
__allow_unmapped__ = True
__tablename__ = _table_prefix_ + "service" __tablename__ = _table_prefix_ + "service"
userid: str = "" userid: str = ""
is_backup: bool = db.Column(db.Boolean, default=False) is_backup: bool = db.Column(db.Boolean, default=False)
@ -57,6 +59,7 @@ class Service(db.Model, ModelSerializeMixin):
class Job(db.Model, ModelSerializeMixin): class Job(db.Model, ModelSerializeMixin):
__allow_unmapped__ = True
__tablename__ = _table_prefix_ + "job" __tablename__ = _table_prefix_ + "job"
id: int = db.Column(Serial, primary_key=True) 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)) 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) 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) 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" "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) 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): class Event(db.Model, ModelSerializeMixin):
"""Model for an Event""" """Model for an Event"""
__allow_unmapped__ = True
__tablename__ = _table_prefix_ + "event" __tablename__ = _table_prefix_ + "event"
id: int = db.Column(Serial, primary_key=True) id: int = db.Column(Serial, primary_key=True)
start: datetime = db.Column(UtcDateTime, nullable=False) start: datetime = db.Column(UtcDateTime, nullable=False)
@ -93,7 +97,7 @@ class Event(db.Model, ModelSerializeMixin):
description: Optional[str] = db.Column(db.String(512)) description: Optional[str] = db.Column(db.String(512))
type: Union[EventType, int] = db.relationship("EventType") type: Union[EventType, int] = db.relationship("EventType")
is_template: bool = db.Column(db.Boolean, default=False) is_template: bool = db.Column(db.Boolean, default=False)
jobs: list[Job] = db.relationship( jobs: List[Job] = db.relationship(
"Job", "Job",
back_populates="event_", back_populates="event_",
cascade="all,delete,delete-orphan", cascade="all,delete,delete-orphan",
@ -109,6 +113,7 @@ class Event(db.Model, ModelSerializeMixin):
class Invitation(db.Model, ModelSerializeMixin): class Invitation(db.Model, ModelSerializeMixin):
__allow_unmapped__ = True
__tablename__ = _table_prefix_ + "invitation" __tablename__ = _table_prefix_ + "invitation"
id: int = db.Column(Serial, primary_key=True) id: int = db.Column(Serial, primary_key=True)