PoolUser   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 100 %

Importance

Changes 0
Metric Value
dl 28
loc 28
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __init__() 3 3 1
A from_id() 3 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
from .model import *
2
from . import account
3
from . import user
4
from . import pool
5
6 View Code Duplication
class PoolUser(Base):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
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