Code Duplication    Length = 21-28 lines in 3 locations

chezbetty/models/pool_user.py 1 location

@@ 6-33 (lines=28) @@
3
from . import user
4
from . import pool
5
6
class PoolUser(Base):
7
    __tablename__ = 'pool_users'
8
9
    id          = Column(Integer, primary_key=True, nullable=False)
10
    pool_id     = Column(Integer, ForeignKey("accounts.id"), nullable=False)
11
    user_id     = Column(Integer, ForeignKey("users.id"), nullable=False)
12
13
    enabled     = Column(Boolean, default=True, nullable=False)
14
    deleted     = Column(Boolean, default=False, nullable=False)
15
16
    pool        = relationship(
17
                    account.Account,
18
                    primaryjoin="and_(PoolUser.pool_id==Account.id, PoolUser.deleted==False)",
19
                    backref="users"
20
                  )
21
    user        = relationship(
22
                    user.User,
23
                    primaryjoin="and_(PoolUser.user_id==User.id, PoolUser.deleted==False)",
24
                    backref="pools"
25
                  )
26
27
    def __init__(self, pool, user):
28
        self.pool_id  = pool.id
29
        self.user_id  = user.id
30
31
    @classmethod
32
    def from_id(cls, id):
33
        return DBSession.query(cls).filter(cls.id == id).one()
34

chezbetty/models/item_tag.py 1 location

@@ 5-27 (lines=23) @@
2
from . import tag
3
from . import item
4
5
class ItemTag(Base):
6
    __tablename__ = 'item_tags'
7
8
    id      = Column(Integer, primary_key=True, nullable=False)
9
    tag_id  = Column(Integer, ForeignKey('tags.id'), nullable=False)
10
    item_id = Column(Integer, ForeignKey('items.id'), nullable=False)
11
12
    deleted = Column(Boolean, default=False, nullable=False)
13
14
    tag     = relationship(tag.Tag,
15
                           primaryjoin='and_(ItemTag.tag_id==tag.Tag.id, ItemTag.deleted==False)',
16
                           backref='items')
17
    item    = relationship(item.Item,
18
                           primaryjoin='and_(ItemTag.item_id==item.Item.id, ItemTag.deleted==False)',
19
                           backref='tags')
20
21
    def __init__(self, item, tag):
22
        self.tag_id  = tag.id
23
        self.item_id = item.id
24
25
    @classmethod
26
    def from_id(cls, id):
27
        return DBSession.query(cls).filter(cls.id == id).one()
28
29
@classmethod
30
@limitable_all

chezbetty/models/tag_relations.py 1 location

@@ 4-24 (lines=21) @@
1
from .model import *
2
from . import tag as tagobject
3
4
class TagRelations(Base):
5
    __tablename__ = 'tag_relations'
6
7
    id            = Column(Integer, primary_key=True, nullable=False)
8
    tag_id        = Column(Integer, ForeignKey('tags.id'), nullable=False)
9
    parent_tag_id = Column(Integer, ForeignKey('tags.id'), nullable=False)
10
11
    deleted       = Column(Boolean, default=False, nullable=False)
12
13
    tag           = relationship(tagobject.Tag,
14
                                 primaryjoin=tag_id==tagobject.Tag.id,
15
                                 backref='parents')
16
17
    parent        = relationship(tagobject.Tag,
18
                                 primaryjoin=parent_tag_id==tagobject.Tag.id,
19
                                 backref='children')
20
21
22
    def __init__(self, tag, parent_tag):
23
        self.tag_id        = tag.id
24
        self.parent_tag_id = parent_tag.id
25