Passed
Push — main ( 2c88b8...eed5d0 )
by Jochen
04:23
created

DbNewsChannel.__repr__()   A

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1.125

Importance

Changes 0
Metric Value
cc 1
eloc 6
nop 1
dl 0
loc 6
ccs 1
cts 2
cp 0.5
crap 1.125
rs 10
c 0
b 0
f 0
1
"""
2
byceps.services.news.dbmodels.channel
3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
5
:Copyright: 2014-2023 Jochen Kupperschmidt
6
:License: Revised BSD (see `LICENSE` file for details)
7
"""
8
9 1
from typing import Optional
10
11 1
from ....database import db
12 1
from ....typing import BrandID
13 1
from ....util.instances import ReprBuilder
14
15 1
from ...site.transfer.models import SiteID
16
17 1
from ..transfer.models import NewsChannelID
18
19
20 1
class DbNewsChannel(db.Model):
21
    """A channel to which news items can be published."""
22
23 1
    __tablename__ = 'news_channels'
24
25 1
    id = db.Column(db.UnicodeText, primary_key=True)
26 1
    brand_id = db.Column(
27
        db.UnicodeText, db.ForeignKey('brands.id'), index=True, nullable=False
28
    )
29 1
    announcement_site_id = db.Column(
30
        db.UnicodeText, db.ForeignKey('sites.id'), nullable=True
31
    )
32 1
    archived = db.Column(db.Boolean, default=False, nullable=False)
33
34 1
    def __init__(
35
        self,
36
        channel_id: NewsChannelID,
37
        brand_id: BrandID,
38
        *,
39
        announcement_site_id: Optional[SiteID] = None,
40
    ) -> None:
41 1
        self.id = channel_id
42 1
        self.brand_id = brand_id
43 1
        self.announcement_site_id = announcement_site_id
44
45 1
    def __repr__(self) -> str:
46
        return (
47
            ReprBuilder(self)
48
            .add_with_lookup('id')
49
            .add('brand', self.brand_id)
50
            .build()
51
        )
52