Some work on event models
This commit is contained in:
parent
854a1f6156
commit
92626dc0c6
|
@ -20,7 +20,7 @@ def login_user(username, password):
|
||||||
def update_user(user):
|
def update_user(user):
|
||||||
current_app.config["FG_AUTH_BACKEND"].update_user(user)
|
current_app.config["FG_AUTH_BACKEND"].update_user(user)
|
||||||
if not user.display_name:
|
if not user.display_name:
|
||||||
user.display_name = user.firstname[0] + user.lastname
|
user.display_name = "{} {}".format(user.firstname, user.lastname)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,76 +1,65 @@
|
||||||
|
from . import ModelSerializeMixin
|
||||||
from ..database import db
|
from ..database import db
|
||||||
|
|
||||||
|
|
||||||
class Event(db.Model):
|
class Event(db.Model, ModelSerializeMixin):
|
||||||
"""Model for an Event"""
|
"""Model for an Event"""
|
||||||
|
|
||||||
__tablename__ = "event"
|
__tablename__ = "event"
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
begin = db.Column(db.DateTime, nullable=False)
|
begin = db.Column(db.DateTime, nullable=False)
|
||||||
end = db.Column(db.DateTime)
|
end = db.Column(db.DateTime)
|
||||||
description = db.Column(db.String(240))
|
description = db.Column(db.String(240))
|
||||||
kind_id = db.Column(db.Integer, db.ForeignKey("event_kind.id", ondelete="CASCADE"), nullable=False)
|
|
||||||
kind = db.relationship("EventKind")
|
kind = db.relationship("EventKind")
|
||||||
slots = db.relationship("EventSlot", back_populates="event", cascade="all, delete")
|
slots = db.relationship("EventSlot", back_populates="event", cascade="all, delete")
|
||||||
# notices = db.relationship("EventNotice", back_populates="event")
|
# notices = db.relationship("EventNotice", back_populates="event")
|
||||||
|
|
||||||
def serialize(self):
|
_kind_id = db.Column(db.Integer, db.ForeignKey("event_kind.id", ondelete="CASCADE"), nullable=False)
|
||||||
return {"id": self.id, "begin": self.begin, "end": self.end, "description": self.description, "kind": self.kind}
|
|
||||||
|
|
||||||
|
|
||||||
class EventKind(db.Model):
|
class EventKind(db.Model, ModelSerializeMixin):
|
||||||
"""Model for an EventKind"""
|
"""Model for an EventKind"""
|
||||||
|
|
||||||
__tablename__ = "event_kind"
|
__tablename__ = "event_kind"
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
name = db.Column(db.String(30), nullable=False, unique=True)
|
name = db.Column(db.String(30), nullable=False, unique=True)
|
||||||
|
|
||||||
def serialize(self):
|
|
||||||
return {"id": self.id, "name": self.name}
|
|
||||||
|
|
||||||
|
class EventSlot(db.Model, ModelSerializeMixin):
|
||||||
class EventSlot(db.Model):
|
|
||||||
"""Model for an EventSlot"""
|
"""Model for an EventSlot"""
|
||||||
|
|
||||||
__tablename__ = "event_slot"
|
__tablename__ = "event_slot"
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
start = db.Column(db.DateTime)
|
start = db.Column(db.DateTime)
|
||||||
end = db.Column(db.DateTime)
|
end = db.Column(db.DateTime)
|
||||||
event_id = db.Column(db.Integer, db.ForeignKey("event.id"), nullable=False)
|
|
||||||
event = db.relationship("Event", back_populates="slots")
|
|
||||||
slots = db.relationship("JobSlot", back_populates="event_slot")
|
slots = db.relationship("JobSlot", back_populates="event_slot")
|
||||||
|
|
||||||
def serialize(self):
|
_event_id = db.Column(db.Integer, db.ForeignKey("event.id"), nullable=False)
|
||||||
return {
|
_event = db.relationship("Event", back_populates="slots")
|
||||||
"id": self.id,
|
|
||||||
"start": self.start,
|
|
||||||
"end": self.end,
|
|
||||||
"event": self.event_id,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class JobSlot(db.Model):
|
class JobSlot(db.Model, ModelSerializeMixin):
|
||||||
__tablename__ = "job_slot"
|
__tablename__ = "job_slot"
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
needed_persons = db.Column(db.Numeric(precision=4, scale=2))
|
needed_persons = db.Column(db.Numeric(precision=4, scale=2))
|
||||||
event_slot_id = db.Column(db.Integer, db.ForeignKey("event_slot.id"))
|
|
||||||
event_slot = db.relationship("EventSlot", back_populates="slots")
|
|
||||||
kind_id = db.Column(db.Integer, db.ForeignKey("job_kind.id"))
|
|
||||||
kind = db.relationship("JobKind")
|
kind = db.relationship("JobKind")
|
||||||
jobs = db.relationship("Job", back_populates="slot")
|
jobs = db.relationship("Job", back_populates="slot")
|
||||||
|
|
||||||
|
_event_slot_id = db.Column(db.Integer, db.ForeignKey("event_slot.id"))
|
||||||
|
_event_slot = db.relationship("EventSlot", back_populates="slots")
|
||||||
|
_kind_id = db.Column(db.Integer, db.ForeignKey("job_kind.id"))
|
||||||
|
|
||||||
class Job(db.Model):
|
|
||||||
|
class Job(db.Model, ModelSerializeMixin):
|
||||||
__tablename__ = "job"
|
__tablename__ = "job"
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
|
||||||
value = db.Column(db.Numeric(precision=3, scale=2))
|
|
||||||
user_id = db.Column(db.Integer, db.ForeignKey("user.id"))
|
|
||||||
user = db.relationship("User")
|
user = db.relationship("User")
|
||||||
slot_id = db.Column(db.Integer, db.ForeignKey("job_slot.id"))
|
value = db.Column(db.Numeric(precision=3, scale=2))
|
||||||
slot = db.relationship("JobSlot")
|
|
||||||
|
_user_id = db.Column(db.Integer, db.ForeignKey("user.id"))
|
||||||
|
_slot_id = db.Column(db.Integer, db.ForeignKey("job_slot.id"))
|
||||||
|
_slot = db.relationship("JobSlot")
|
||||||
|
_id = db.Column(db.Integer, primary_key=True)
|
||||||
|
|
||||||
|
|
||||||
class JobKind(db.Model):
|
class JobKind(db.Model, ModelSerializeMixin):
|
||||||
__tablename__ = "job_kind"
|
__tablename__ = "job_kind"
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
name = db.Column(db.String(30), nullable=False, unique=True)
|
||||||
name = db.Column(db.String(30))
|
|
||||||
|
_id = db.Column(db.Integer, primary_key=True)
|
||||||
|
|
Loading…
Reference in New Issue