~homeworkprod/byceps

ref: bcef32cd2dc329bcf81057794883008f5c040ac8 byceps/byceps/services/orga_presence/dbmodels.py -rw-r--r-- 1.4 KiB
bcef32cd — Jochen Kupperschmidt Work around Jinja 3.0.0 bug with `for` inside of `set` block 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
byceps.services.orga_presence.dbmodels
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2021 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""

from ...database import BaseQuery, db, generate_uuid
from ..user.dbmodels.user import User


class TimeSlotQuery(BaseQuery):

    def for_party(self, party_id) -> BaseQuery:
        return self.filter_by(party_id=party_id)


class TimeSlot(db.Model):
    """A time slot at a party."""

    __tablename__ = 'orga_time_slots'
    __mapper_args__ = {
        'polymorphic_on': 'type',
        'polymorphic_identity': 'time_slot',
    }
    query_class = TimeSlotQuery

    id = db.Column(db.Uuid, default=generate_uuid, primary_key=True)
    party_id = db.Column(db.UnicodeText, db.ForeignKey('parties.id'), index=True, nullable=False)
    type = db.Column(db.UnicodeText, index=True, nullable=False)
    starts_at = db.Column(db.DateTime, nullable=False)
    ends_at = db.Column(db.DateTime, nullable=False)


class Presence(TimeSlot):
    """The scheduled presence of an organizer at a party."""
    __mapper_args__ = {
        'polymorphic_identity': 'orga_presence',
    }

    orga_id = db.Column(db.Uuid, db.ForeignKey('users.id'))
    orga = db.relationship(User)


class Task(TimeSlot):
    """A scheduled task connected to a party."""
    __mapper_args__ = {
        'polymorphic_identity': 'task',
    }

    title = db.Column(db.UnicodeText)