| Total Complexity | 5 |
| Total Lines | 32 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from .model import * |
||
| 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 |