Vendor.count()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
from .model import *
2
3
class Vendor(Base):
4
    __tablename__ = 'vendors'
5
6
    id           = Column(Integer, primary_key=True, nullable=False)
7
    name         = Column(String(255), nullable=False)
8
9
    enabled      = Column(Boolean, default=True, nullable=False)
10
    product_urls = Column(Boolean)
11
12
    def __init__(self, name, enabled=True):
13
        self.name = name
14
        self.enabled = enabled
15
16
    @classmethod
17
    def from_id(cls, id):
18
        return DBSession.query(cls).filter(cls.id == id).one()
19
20
    @classmethod
21
    def all(cls):
22
        return DBSession.query(cls)\
23
                        .filter(cls.enabled)\
24
                        .order_by(cls.name).all()
25
26
    @classmethod
27
    def count(cls):
28
        return DBSession.query(func.count(cls.id).label('c'))\
29
                        .filter(cls.enabled).one().c
30
31
    def __str__(self):
32
        return "<Vendor (%s)>" % self.name
33
34
    __repr__ = __str__
35