~homeworkprod/byceps

ref: 4237b3ec9496efe95dcce82bea3207ab9de4d520 byceps/byceps/services/terms/models/version.py -rw-r--r-- 2.1 KiB
4237b3ec — Jochen Kupperschmidt Move ticketing blueprint into `site` subpackage 2 years 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
53
54
55
56
57
58
59
60
61
"""
byceps.services.terms.models.version
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2020 Jochen Kupperschmidt
:License: Modified BSD, see LICENSE for details.
"""

from datetime import datetime

from ....database import db, generate_uuid
from ....util.instances import ReprBuilder

from ...consent.models.subject import Subject as ConsentSubject
from ...consent.transfer.models import SubjectID as ConsentSubjectID
from ...snippet.models.snippet import SnippetVersion
from ...snippet.transfer.models import SnippetVersionID

from ..transfer.models import DocumentID

from .document import Document


class Version(db.Model):
    """A specific version of a terms and conditions document."""

    __tablename__ = 'terms_versions'

    id = db.Column(db.Uuid, default=generate_uuid, primary_key=True)
    document_id = db.Column(db.UnicodeText, db.ForeignKey('terms_documents.id', name='terms_versions_document_id_fkey'), index=True, nullable=False)
    document = db.relationship(Document, foreign_keys=[document_id])
    created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
    title = db.Column(db.UnicodeText, nullable=False)
    snippet_version_id = db.Column(db.Uuid, db.ForeignKey('snippet_versions.id'), index=True, nullable=False)
    snippet_version = db.relationship(SnippetVersion)
    consent_subject_id = db.Column(db.Uuid, db.ForeignKey('consent_subjects.id'), nullable=False)
    consent_subject = db.relationship(ConsentSubject)

    def __init__(
        self,
        document_id: DocumentID,
        title: str,
        snippet_version_id: SnippetVersionID,
        consent_subject_id: ConsentSubjectID,
    ) -> None:
        self.document_id = document_id
        self.title = title
        self.snippet_version_id = snippet_version_id
        self.consent_subject_id = consent_subject_id

    @property
    def body(self) -> str:
        return self.snippet_version.body

    def __repr__(self) -> str:
        return ReprBuilder(self) \
            .add_with_lookup('id') \
            .add_with_lookup('document_id') \
            .add_with_lookup('created_at') \
            .add_with_lookup('title') \
            .build()