Completed
Push — master ( bce3b1...2804a0 )
by Pat
01:30
created

RequestPost   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 27
loc 27
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __init__() 6 6 1
A all() 4 4 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
3
from sqlalchemy_utils import ArrowType
4
5 View Code Duplication
class RequestPost(Base):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
6
    __tablename__ = 'request_posts'
7
8
    id         = Column(Integer, primary_key=True, nullable=False)
9
    timestamp  = Column(ArrowType, nullable=False, default=datetime.datetime.utcnow)
10
    request_id = Column(Integer, ForeignKey("requests.id"), nullable=False)
11
    user_id    = Column(Integer, ForeignKey("users.id"), nullable=False)
12
    post       = Column(Text)
13
    # Allow admin users to post as users or admins by tracking the view that the post is posted from
14
    staff_post = Column(Boolean, default=False, nullable=False)
15
    deleted    = Column(Boolean, default=False, nullable=False)
16
17
    def __init__(self, request, user, post, staff_post=False, deleted=False):
18
        self.request_id = request.id
19
        self.user_id = user.id
20
        self.post = post
21
        self.staff_post = staff_post
22
        self.deleted = deleted
23
24
    @classmethod
25
    def from_id(cls, id):
26
        return DBSession.query(cls).filter(cls.id == id).one()
27
28
    @classmethod
29
    def all(cls):
30
        return DBSession.query(cls).filter(cls.deleted==False)\
31
                        .order_by(desc(cls.timestamp))\
32
                        .all()
33
34