예제 #1
0
class Message(base_model.BaseModel, db.Model):

    __tablename__ = 'message'

    id = db.Column(db.Integer, db.Sequence('seq_message'), primary_key=True)
    deployment_id = db.Column(db.Integer, db.ForeignKey('deployment.id'))
    origin_message_id = db.Column(db.Integer, nullable=False)
    content = db.Column(db.Text, nullable=False)
    simhash = db.Column(db.String(64), nullable=False)
예제 #2
0
class Category(base_model.BaseModel, db.Model):
    """Mapping for the category table"""

    __tablename__ = 'category'

    id = db.Column(db.Integer,
                   db.Sequence('seq_category_id'),
                   primary_key=True)
    deployment_id = db.Column(db.Integer, db.ForeignKey('deployment.id'))
    origin_category_id = db.Column(db.Integer, nullable=False)
    origin_parent_id = db.Column(db.Integer, nullable=False)
    title = db.Column(db.String(50), nullable=False)
예제 #3
0
class ReportCategory(base_model.BaseModel, db.Model):
    __tablename__ = 'report_category'
    report_id = db.Column(db.Integer, db.ForeignKey('report.id'),
                          primary_key=True)
    category_id = db.Column(db.Integer, db.ForeignKey('category.id'),
                            primary_key=True)

    # bi-directional attribute/collection of report/report_categories
    report = db.relationship(Report,
                             backref=db.backref('report_categories',
                                                cascade='all, delete-orphan'))

    # Reference to the category object
    category = db.relationship("Category")
예제 #4
0
class Report(base_model.BaseModel, db.Model):
    __tablename__ = 'report'
    id = db.Column(db.Integer, db.Sequence('seq_report'), primary_key=True)
    deployment_id = db.Column(db.Integer, db.ForeignKey('deployment.id'))
    origin_report_id = db.Column(db.Integer, nullable=False)
    description = db.Column(db.Text, nullable=False)
    title = db.Column(db.String(255), nullable=False)
    simhash = db.Column(db.String(64), nullable=False)

    # Association proxy of "report_categories" collection
    # to "categories" attribute
    categories = association_proxy('report_categories', 'category')
예제 #5
0
class Deployment(base_model.BaseModel, db.Model):

    __tablename__ = 'deployment'

    id = db.Column(db.Integer, db.Sequence('seq_deployment'), primary_key=True)
    name = db.Column(db.String(50))
    url = db.Column(db.String(100), nullable=False)
    url_hash = db.Column(db.String(32), nullable=False, unique=True)
    message_count = db.Column(db.Integer)
    report_count = db.Column(db.Integer)

    # One-to-many relationship definitions
    categories = db.relationship('Category',
                                 backref='deployment',
                                 cascade="all, delete, delete-orphan")
    reports = db.relationship('Report',
                              backref='deployment',
                              cascade="all, delete, delete-orphan")
    messages = db.relationship('Message',
                               backref='deployment',
                               cascade="all, delete, delete-orphan")

    def save(self):
        self.url_hash = hashlib.md5(self.url).hexdigest()
        db.session.add(self)
        db.session.commit()

    @classmethod
    def by_url(cl, deployment_url):
        """Return the deployment with the given url

        :param deployment_url: the url of the deployment
        :type deployment_url: string

        :returns: the deployment with the given url or None if there is
            no deployment with that url
        :rtype: dssg.model.Deployment

        """
        # Get the MD5 hash of the deployment url
        url_hash = hashlib.md5(deployment_url).hexdigest()
        return Deployment.query.filter_by(url_hash=url_hash).first()