Tag.all()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
from .model import *
2
3
class Tag(Base):
4
    __tablename__ = 'tags'
5
6
    id         = Column(Integer, primary_key=True, nullable=False)
7
    name       = Column(String(255), nullable=False, unique=True)
8
9
    # Show this page as a top-level item selector
10
    homepage   = Column(Boolean, nullable=False, default=False)
11
12
    enabled    = Column(Boolean, default=True, nullable=False)
13
    deleted    = Column(Boolean, default=False, nullable=False)
14
15
    def __init__(self, name):
16
        self.name = name
17
18
    @classmethod
19
    def from_id(cls, id):
20
        return DBSession.query(cls).filter(cls.id == id).one()
21
22
    @classmethod
23
    def all(cls):
24
        return DBSession.query(cls)\
25
                        .filter(cls.deleted==False)\
26
                        .order_by(cls.name).all()
27
28
    @classmethod
29
    def count(cls):
30
        return DBSession.query(func.count(cls.id).label('c'))\
31
                        .filter(cls.deleted==False).one().c
32