1
|
|
|
""" |
2
|
|
|
byceps.services.tourney.models.match_comment |
3
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
4
|
|
|
|
5
|
|
|
:Copyright: 2006-2019 Jochen Kupperschmidt |
6
|
|
|
:License: Modified BSD, see LICENSE for details. |
7
|
|
|
""" |
8
|
|
|
|
9
|
|
|
from datetime import datetime |
10
|
|
|
|
11
|
|
|
from ....database import BaseQuery, db, generate_uuid |
12
|
|
|
from ....typing import UserID |
13
|
|
|
|
14
|
|
|
from ...user.models.user import User |
15
|
|
|
|
16
|
|
|
from ..transfer.models import MatchID |
17
|
|
|
|
18
|
|
|
from .match import Match |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
class MatchCommentQuery(BaseQuery): |
22
|
|
|
|
23
|
|
|
def for_match(self, match_id: MatchID) -> BaseQuery: |
24
|
|
|
return self.filter_by(match_id=match_id) |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
class MatchComment(db.Model): |
28
|
|
|
"""An immutable comment on a match by one of the opponents.""" |
29
|
|
|
|
30
|
|
|
__tablename__ = 'tourney_match_comments' |
31
|
|
|
query_class = MatchCommentQuery |
32
|
|
|
|
33
|
|
|
id = db.Column(db.Uuid, default=generate_uuid, primary_key=True) |
34
|
|
|
match_id = db.Column(db.Uuid, db.ForeignKey('tourney_matches.id'), index=True, nullable=False) |
35
|
|
|
match = db.relationship(Match) |
36
|
|
|
created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False) |
37
|
|
|
created_by_id = db.Column(db.Uuid, db.ForeignKey('users.id'), nullable=False) |
38
|
|
|
created_by = db.relationship(User, foreign_keys=[created_by_id]) |
39
|
|
|
body = db.Column(db.UnicodeText, nullable=False) |
40
|
|
|
last_edited_at = db.Column(db.DateTime) |
41
|
|
|
last_edited_by_id = db.Column(db.Uuid, db.ForeignKey('users.id')) |
42
|
|
|
last_edited_by = db.relationship(User, foreign_keys=[last_edited_by_id]) |
43
|
|
|
hidden = db.Column(db.Boolean, default=False, nullable=False) |
44
|
|
|
hidden_at = db.Column(db.DateTime) |
45
|
|
|
hidden_by_id = db.Column(db.Uuid, db.ForeignKey('users.id')) |
46
|
|
|
hidden_by = db.relationship(User, foreign_keys=[hidden_by_id]) |
47
|
|
|
|
48
|
|
|
def __init__( |
49
|
|
|
self, match_id: MatchID, creator_id: UserID, body: str |
50
|
|
|
) -> None: |
51
|
|
|
self.match_id = match_id |
52
|
|
|
self.created_by_id = creator_id |
53
|
|
|
self.body = body |
54
|
|
|
|