Example #1
0
class Disease(db.Model):
    __table__name = "diseases"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Text(), nullable=False)
    symptoms = db.Column(db.Text(), nullable=False)
    causes = db.Column(db.Text(), nullable=False)
    solutions = db.Column(db.Text(), nullable=False)
    url = db.Column(db.Text(), nullable=False)
Example #2
0
File: topic.py Project: xiecang/bbs
class Topic(db.Model, ModelMixin):
    __tablename__ = 'topics'
    id = db.Column(db.Integer, primary_key=True)
    created_time = db.Column(db.Integer)
    title = db.Column(db.String(64))
    content = db.Column(db.Text())
    clicked = db.Column(db.Integer)
    visit_count = db.Column(db.Integer)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    comments = db.relationship('Comment', backref='topic', lazy="dynamic")
    top_node_id = db.Column(db.Integer, db.ForeignKey('top_nodes.id'))
    node_id = db.Column(db.Integer, db.ForeignKey('nodes.id'))

    def __init__(self, form):
        self.created_time = timestamp()
        self.clicked = 0
        self.title = form.get('title', '')
        self.content = form.get('content', '')
        self.node_id = int(form.get('node', '0'))
        node = Node.query.filter_by(id=self.node_id).first()
        self.top_node_id = node.top_node_id

    def validate(self):
        if len(self.title) > 0:
            return True
        else:
            return False
Example #3
0
class Feedback(BaseModel):
    __tablename__ = 'feedback'
    msg = db.Column('msg', db.Text())

    @property
    def to_json(self):
        return {'msg': self.msg, 'id': self.id}
Example #4
0
class searchAdClientOrderExecutiveReport(db.Model, BaseModelMixin):
    __tablename__ = 'searchAd_bra_client_order_executive_report'
    id = db.Column(db.Integer, primary_key=True)
    client_order_id = db.Column(
        db.Integer, db.ForeignKey('searchAd_bra_client_order.id'))  # 客户合同
    client_order = db.relationship(
        'searchAdClientOrder', backref=db.backref('executive_reports', lazy='dynamic'))
    money = db.Column(db.Float())
    month_day = db.Column(db.DateTime)
    days = db.Column(db.Integer)
    create_time = db.Column(db.DateTime)
    # 合同文件打包
    order_json = db.Column(db.Text(), default=json.dumps({}))
    status = db.Column(db.Integer, index=True)
    contract_status = db.Column(db.Integer, index=True)
    __table_args__ = (db.UniqueConstraint(
        'client_order_id', 'month_day', name='_searchAd_client_order_month_day'),)
    __mapper_args__ = {'order_by': create_time.desc()}

    def __init__(self, client_order, money=0, month_day=None, days=0, create_time=None):
        self.client_order = client_order
        self.money = money
        self.month_day = month_day or datetime.date.today()
        self.days = days
        self.create_time = create_time or datetime.date.today()
        # 合同文件打包
        self.status = client_order.status
        self.contract_status = client_order.contract_status
        # 获取相应合同字段
        dict_order = {}
        dict_order['client_name'] = client_order.client.name
        dict_order['agent_name'] = client_order.agent.name
        dict_order['contract'] = client_order.contract
        dict_order['campaign'] = client_order.campaign
        dict_order['industry_cn'] = client_order.client.industry_cn
        dict_order['locations'] = client_order.locations
        dict_order['sales'] = [
            {'id': k.id, 'name': k.name, 'location': k.team.location}for k in client_order.direct_sales]
        dict_order['salers_ids'] = [k['id'] for k in dict_order['sales']]
        dict_order['get_saler_leaders'] = [
            k.id for k in client_order.get_saler_leaders()]
        dict_order['resource_type_cn'] = client_order.resource_type_cn
        dict_order['operater_users'] = [
            {'id': k.id, 'name': k.name}for k in client_order.operater_users]
        dict_order['client_start'] = client_order.client_start.strftime(
            '%Y-%m-%d')
        dict_order['client_end'] = client_order.client_end.strftime('%Y-%m-%d')
        self.order_json = json.dumps(dict_order)

    @property
    def month_cn(self):
        return self.month_day.strftime('%Y-%m') + u'月'
class Event(db.Model):
    __tablename__ = 'events'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(250), nullable=False)
    creation_date = db.Column(db.TIMESTAMP, server_default=db.func.current_timestamp(), nullable=False)
    startDate = db.Column(db.DateTime, default=db.func.current_timestamp(), nullable=False)
    endDate = db.Column(db.DateTime, default=db.func.current_timestamp(), nullable=False)
    description = db.Column(db.Text(), nullable=True)

    def updateFromSchema(self, new):
        self.name = new.name
        self.startDate = new.startDate
        self.endDate = new.endDate
        self.description = new.description
Example #6
0
class Notice(db.Model, BaseModelMixin):
    __tablename__ = 'notice'
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100))
    emails = db.Column(db.Text(), default=json.dumps([]))
    content = db.Column(db.Text(), default="")
    creator_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    creator = db.relationship('User',
                              backref=db.backref('notice_creator',
                                                 lazy='dynamic'),
                              foreign_keys=[creator_id])
    create_time = db.Column(db.DateTime)
    __mapper_args__ = {'order_by': create_time.desc()}

    def __init__(self, title, emails, content, creator, create_time=None):
        self.title = title
        self.emails = emails
        self.content = content
        self.creator = creator
        self.create_time = create_time or datetime.date.today()

    @property
    def create_time_cn(self):
        return self.create_time.strftime('%Y-%m-%d %H:%M')
Example #7
0
class Comment(db.Model, ModelMixin):
    __tablename__ = 'comments'
    id = db.Column(db.Integer, primary_key=True)
    created_time = db.Column(db.Integer)
    content = db.Column(db.Text())
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    topic_id = db.Column(db.Integer, db.ForeignKey('topics.id'))

    def __init__(self, form):
        self.created_time = timestamp()
        self.topic_id = form.get('topic_id', '')
        self.content = form.get('comment', '')

    def validate(self):
        if len(self.content) > 0:
            return True
        else:
            return False
Example #8
0
class Device(db.Model):
    __tablename__ = 'devices'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(250), nullable=False)
    title = db.Column(db.String(250), nullable=False)
    vendor = db.Column(db.String(250), nullable=False)
    description = db.Column(db.Text(), nullable=True)
    creation_date = db.Column(db.TIMESTAMP,
                              server_default=db.func.current_timestamp(),
                              nullable=False)
    tags = db.relationship('Tag',
                           secondary="has_tags",
                           backref=db.backref("devices"))

    def updateFromSchema(self, new):
        self.name = new.name
        self.title = new.title
        self.vendor = new.vendor
        self.description = new.description
        self.tags = new.tags
Example #9
0
class Reviews(db.Model):
    __tablename__ = 'reviews'
    col_id = db.Column(db.Integer, primary_key=True)
    reviewid = db.Column(db.String(200))
    userid = db.Column(db.Integer)
    business_id = db.Column(db.String(200))
    rating = db.Column(db.Integer)
    text = db.Column(db.Text())
    bid = db.Column(db.Integer)
    username = db.Column(db.String(200))

    def __init__(self, col_id, reviewid, userid, business_id, rating, text, bid, username):
        self.col_id = col_id
        self.userid = userid
        self.rating = rating
        self.business_id = business_id
        self.bid = bid
        self.reviewid = reviewid
        self.username = username
        self.text = text
Example #10
0
class Todo(db.Model, ModelMixin):
    __tablename__ = 'todos'
    id = db.Column(db.Integer, primary_key=True)
    task = db.Column(db.Text())
    created_time = db.Column(db.Integer, default=0)
    updated_time = db.Column(db.Integer)

    # 这是一个外键
    # user_id = db.Column(db.Integer, db.ForeignKey('stb_users.id'))
    # # relationship
    # reviews = db.relationship('Review', backref='chest')

    def __init__(self, form):
        print('chest init', form)
        self.task = form.get('task', '')
        self.created_time = int(time.time())

    def update(self, form):
        self.task = form.get('task', '')
        self.save()
Example #11
0
class Job(db.Model):
    __tablename__ = 'jobs'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(250), nullable=False)
    creation_date = db.Column(db.TIMESTAMP,
                              server_default=db.func.current_timestamp(),
                              nullable=False)
    locationID = db.Column(db.Integer,
                           db.ForeignKey('locations.id', ondelete="CASCADE"),
                           nullable=True)
    location = db.relationship('Location', backref='jobs')
    events = db.relationship('Event',
                             secondary="job_hasEvents",
                             backref=db.backref("jobs"))
    description = db.Column(db.Text(), nullable=True)

    def updateFromSchema(self, new):
        self.name = new.name
        self.location = new.location
        self.events = new.events
        self.description = new.description
Example #12
0
class Feedback(db.Model):
    __table__name = "feedbacks"
    id = db.Column(db.Integer, primary_key=True)
    state = db.Column(db.Text(), nullable=False)
    disease = db.Column(db.Text(), nullable=False)
Example #13
0
class Material(db.Model, BaseModelMixin, CommentMixin, DeliveryMixin):
    __tablename__ = 'materials'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100))
    type = db.Column(db.Integer)
    item_id = db.Column(db.Integer, db.ForeignKey('bra_item.id'))
    item = db.relationship('AdItem',
                           backref=db.backref('materials',
                                              lazy='dynamic',
                                              enable_typechecks=False))
    code = db.Column(db.Text())  # 原生广告代码
    props = db.Column(MutableDict.as_mutable(
        db.PickleType(pickler=json)))  # 广告属性, 一个字典, PikleType可以存储大部分 Python 实例
    status = db.Column(db.Integer, default=1)
    creator_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    creator = db.relationship('User',
                              backref=db.backref('created_material',
                                                 lazy='dynamic',
                                                 enable_typechecks=False))

    def __init__(self, name, item, creator, type=MATERIAL_TYPE_RAW):
        self.name = name
        self.type = type
        self.item = item
        self.creator = creator
        self.props = {}

    def __repr__(self):
        return '<Material %s>' % (self.name)

    @property
    def type_cn(self):
        return MATERIAL_TYPE_CN[self.type]

    @property
    def status_cn(self):
        return STATUS_CN[self.status]

    @property
    def width(self):
        return self.item.position.size.width

    @property
    def height(self):
        return self.item.position.size.height

    def path(self):
        if self.type == MATERIAL_TYPE_PICTURE:
            return url_for('material.image_material', material_id=self.id)
        else:
            return url_for('material.raw_material', material_id=self.id)

    @property
    def html(self):
        return self.code

    @property
    def processed_html(self):
        if self.html:
            return self.html.replace("%%CLICK%%", "")  # 预览的时候, 去掉CLICK宏

    @property
    def get_ctr(self):
        return (str(
            round(
                float(self.get_click_num_all()) /
                float(self.get_monitor_num_all()), 2) * 100) +
                '%') if self.get_monitor_num_all() else 0.0

    @property
    def preview_path(self):
        if self.type == MATERIAL_TYPE_PICTURE:
            return url_for('material.image_preview', material_id=self.id)
        else:
            return url_for('material.raw_preview', material_id=self.id)

    def is_online_by_date(self, _date):
        """该日期是否有投放"""
        return self.item.is_online_by_date(_date)

    @classmethod
    def online_materials(cls, _date):
        return [m for m in cls.all() if m.is_online_by_date(_date)]