Пример #1
0
class Shop(db.Model, Serializer):
    __tablename__ = 'shop'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    uid = db.Column(db.Integer, db.ForeignKey('user.id'))
    name = db.Column(db.String(32), nullable=False)
    description = db.Column(db.String(128))
    salesVolumes = db.Column(db.Integer, default=0)
    productAmount = db.Column(db.Integer, default=0)
    img = db.Column(db.String(128))

    def serialize(self):
        d = Serializer.serialize(self)
        return d
Пример #2
0
class URL(db.Model):
    __tablename__ = 'urls'

    id = db.Column(db.BigInteger, primary_key=True, index=True)
    user_id = db.Column(db.BigInteger,
                        db.ForeignKey('users.id'),
                        nullable=False)
    url = db.Column(db.String(length=500))
    seed = db.Column(db.BigInteger, nullable=True, unique=True, index=True)

    def __init__(self, user_id: int, url: str, seed=None):
        self.user_id = user_id
        self.url = url
        self.seed = seed
Пример #3
0
class Paper(BaseModel):
    __tablename__ = 'paper'
    name = db.Column(db.String(255), comment='考试名称')
    total_paper_score = db.Column(db.Integer, comment='考卷总分')
    exam_time = db.Column(db.Integer, comment='考试时间(分钟)')
    remainder_time = db.Column(db.Integer, comment='剩余时间(分钟)')
    head_id = db.Column(db.Integer, db.ForeignKey('head.id'),
                             comment='标题')
    head = db.relationship('Head',
                                 backref=db.backref('papers',
                                                    lazy='dynamic'))
    status = db.Column(db.String(255), comment='状态', default='new')
    users = db.relationship('User', secondary=users_papers,
                            backref=db.backref('papers', lazy='dynamic'))
Пример #4
0
class Shipping(db.Model):
    __tablename__ = 'shipping'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), nullable=False)
    line_one = db.Column(db.String(255), nullable=False)
    line_two = db.Column(db.String(255), nullable=True)
    city = db.Column(db.String(255), nullable=False)
    post_code = db.Column(db.String(255), nullable=False)
    country = db.Column(db.String(255), nullable=False)
    order_id = db.Column(db.String(50), db.ForeignKey('orders.order_id'))

    def add_shipping(self):
        db.session.add(self)
        db.session.commit()
Пример #5
0
class Autrag(db.Model, BaseMixin):
    __tablename__ = "auftrag"

    auftragID = db.Column(db.Integer, primary_key=True)
    anr = db.Column(db.Integer)
    untersuchungsname = db.Column(db.String)
    stemprop = db.Column(db.String)
    untersuchung_done = db.Column(db.Boolean, default=False)
    listen_id = db.Column(db.Integer, db.ForeignKey("listen.listID"))

    def __init__(self, anr, untersuchungsname, stemprop):
        self.anr = anr
        self.untersuchungsname = untersuchungsname
        self.stemprop = stemprop
Пример #6
0
class Mesures(db.Model):
    __tablename__ = 'mesures'

    id = db.Column(db.Integer, primary_key=True)
    niveau = db.Column(db.String(100), nullable=False)
    etat = db.Column(db.String(100), )
    date = db.Column(db.Date(), nullable=False)
    code_station = db.Column(db.Integer,
                             db.ForeignKey('station.code'),
                             nullable=False)
    id_polluant = db.Colulmn(db.Integer,
                             db.ForeignKey('polluant.id'),
                             nullable=False)

    def __init__(self, niveau, etat, date, code_station, id_polluant):
        self.niveau = niveau
        self.etat = etat
        self.date = date
        self.code_station = code_station
        self.id_polluant = id_polluant

    def __str__(self):
        return f'relevé du {self.date}'
Пример #7
0
class Plan(Model):
    __tablename__ = "plan"
    user_id = Column(db.Integer, db.ForeignKey('users.id'))
    name = Column(db.String(120), nullable=False)
    id = Column(db.Integer, primary_key=True)
    description = Column(db.String(1200), nullable=True)

    def makedict(self):
        return {
            "userId": self.user_id,
            "name": self.name,
            "id": self.id,
            "description": self.description,
        }
Пример #8
0
class City(db.Model):
    __tablename__ = "cities"

    code_insee = db.Column(db.String(10), primary_key=True, unique=True)
    code_postal = db.Column(
        db.String(50), primary_key=True
    )  # Long string because some examples seem to have chained post codes
    name = db.Column(db.String(100), primary_key=True)
    population = db.Column(db.Float(asdecimal=True))
    area = db.Column(db.Float(asdecimal=True))

    # Parents
    county_code = db.Column(db.ForeignKey('counties.code'))
    county = db.relationship('County', foreign_keys=county_code)
Пример #9
0
class Task(db.Model, base_task.BaseTask):
    __tablename__ = "Task"
    Priority = [('major', 'major'), ('normal', 'normal'), ('minor', 'minor')]
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100))
    description = db.Column(db.String(500))
    start_date = db.Column(db.Date(), nullable=False)
    expected_end_date = db.Column(db.Date(), nullable=True)
    actual_end_date = db.Column(db.Date(), nullable=True)
    status = db.Column(db.Integer, db.ForeignKey('Task_status.id'))
    Task_status = relationship("Task_status",
                               backref=backref("Task_status", uselist=False))
    priority = db.Column(ChoiceType(Priority))

    reporter = db.Column(db.Integer, db.ForeignKey("User.id"))
    assignee = db.Column(db.Integer, db.ForeignKey('User.id'))

    User = relationship('User',
                        primaryjoin=('and_('
                                     'Task.reporter == User.id, '
                                     'Task.assignee == User.id'
                                     ')'),
                        innerjoin=True)

    # User_reporter = relationship("User", backref="User_reporter", foreign_keys="User.reporter")
    # User_assignee = relationship("User", backref="User_assigned", foreign_keys="User.assignee")
    def __init__(self, title, description, start_date, expected_end_date,
                 actual_end_date, status, priority, reporter, assignee):
        self.title = title
        self.description = description
        self.start_date = start_date
        self.expected_end_date = expected_end_date
        self.actual_end_date = actual_end_date
        self.status = status
        self.priority = priority
        self.reporter = reporter
        self.assignee = assignee
Пример #10
0
class Sample(db.Model):
    """
    Sample model

    Arguments:
        id (int): Primary Sample key
        sensor_id (int): Foreign ``Sensor``.id key
        sensor: ``Sensor`` object related to this sample
        datetime (datetime): ``datetime`` object of this sample (should in UTC)
        value (float): Value of sample
    """
    __tablename__ = 'samples'

    id = db.Column(db.Integer, primary_key=True)

    sensor_id = db.Column(db.Integer, db.ForeignKey('sensors.id'), index=True)
    sensor = db.relationship('Sensor', backref=db.backref('samples'))

    datetime = db.Column(db.DateTime, index=True)
    value = db.Column(db.Float)

    def to_json(self):
        """
        Creates a JSON object from Sample. Used where multiple samples will be
        displayed at once.
        """
        json_sample = {
            'id': self.id,
            'sensor': self.sensor.to_sample_json(),
            'value': self.value,
            'datetime': self.datetime,
            'url': url_for('api.get_sample', sid=self.id, _external=True)
        }
        return json_sample

    def to_sensor_json(self):
        """
        Creates a JSON object from Sample for used with Sensor JSON.
        """
        json_sample = {
            'id': self.id,
            'value': self.value,
            'datetime': str(self.datetime),
            'url': url_for('api.get_sample', sid=self.id, _external=True)
        }
        return json_sample

    def __repr__(self):
        return '<Sample %r>' % self.id
Пример #11
0
class SMSLog(BaseModel):
    __tablename__ = 'sms_log'
    __table_args__ = {"schema": schema_name}

    sms_id = db.Column(UUID(as_uuid=True),
                       db.ForeignKey(f'{schema_name}.sms_message.id',
                                     ondelete='CASCADE'),
                       nullable=False,
                       index=True)
    timestamp = db.Column(db.DateTime, default=datetime.datetime.now)
    at_status_code = db.Column(db.String(), nullable=False)
    at_failure_reason = db.Column(db.String(), nullable=True)

    def __repr__(self):
        return f'<SMSLog {self.id}>'
Пример #12
0
class Product(db.Model, Serializer):
    __tablename__ = 'product'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    sid = db.Column(db.Integer, db.ForeignKey('shop.id'))
    name = db.Column(db.String(32), nullable=False)
    status = db.Column(db.String(10), nullable=False)
    description = db.Column(db.String(128))
    salesVolumes = db.Column(db.Integer, default=0)
    shop = db.Column(db.String(32), nullable=False)
    type = db.Column(db.Text)
    img = db.Column(db.String(128))

    def serialize(self):
        d = Serializer.serialize(self)
        return d
Пример #13
0
class Course(db.Model):
    """
    用户
    """
    __tablename__ = 'course'
    id = db.Column(db.Integer,primary_key=True)
    teacher_id = db.Column(db.Integer,db.ForeignKey('teacher.id'))
    course_org_id = db.Column(db.Integer,db.ForeignKey('courseOrg.id'))
    name = db.Column(db.String(50),unique=True,index=True)
    desc = db.Column(db.String(50)) # 课程描述
    detail = db.Column(db.Text) # 课程详情
    is_banner = db.Column(db.Boolean,default=False) # 是否轮播
    degree = db.Column(db.String(2)) # 程度
    learn_times = db.Column(db.Integer,default=0) # 学习时长(分)
    students = db.Column(db.Integer,default=0) # 学习人数
    fav_nums = db.Column(db.Integer,default=0) # 收藏人数
    image = db.Column(db.Text)  # 图像
    click_nums = db.Column(db.Integer,default=0) # 点击数
    add_time = db.Column(db.DateTime,default=datetime.now) # 添加时间
    category = db.Column(db.String(20),default='后端开发') # 课程类别
    tag = db.Column(db.String(15),default='') # 课程标签

    def __repr__(self):
        return '<Course {}>'.format(self.name)
Пример #14
0
class TeacherInfo(BaseModel, db.Model):
    __tablename__ = 'teacher_info'
    id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True)
    # 毕业学校
    graduated = db.Column(db.String(20))
    # 专业
    major = db.Column(db.String(20))
    country = db.Column(db.String(10))
    weichat = db.Column(db.String(20), default='')
    introduce = db.Column(db.String(200))
    success_case = db.Column(db.String(200))
    feature = db.Column(db.String(500))
    show = db.Column(db.Boolean)

    course_tables = db.relationship('CourseTable', backref='teacher_info', cascade="all, delete-orphan")
class ProfileImageHistory(db.Model):
    __tablename__ = 'profile_image_historys'

    id = db.Column(db.Integer, primary_key=True)
    bot_id = db.Column(db.Integer, db.ForeignKey('bots.id'), nullable=False)
    image_path = db.Column(db.Text, comment='ファイルパス', nullable=False)
    create_at = db.Column(db.DateTime, default=datetime.now, nullable=False)
    update_at = db.Column(db.DateTime, default=datetime.now, nullable=False)

    @classmethod
    def create(cls, bot_id, image_path):
        image_info = cls(bot_id=bot_id, image_path=image_path)
        db.session.add(image_info)
        db.session.flush()
        return image_info
Пример #16
0
class Revier(db.Model, BaseMixin):
    __tablename__ = "reviere"

    reviername = db.Column(db.String)
    ort = db.Column(db.String)
    grenzen = db.relationship('GrenzPunkt', backref="Revier", lazy=False)
    user_id = db.Column(db.Integer, db.ForeignKey("users.id"))
    #tagebucheintraege = db.relationship("TagebuchEintrag", backref="Revier", lazy=False)
    #revier_gäste
    #einrichtungen

    def __init__(self, reviername, ort, user_id):
        self.user_id = user_id
        self.reviername = reviername
        self.ort = ort
Пример #17
0
class VerifyEmail(db.Model):
    _id = db.Column('id', db.Integer, primary_key=True,
                    autoincrement=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('user.id'),
                        nullable=False)

    key = db.Column(db.String(40), unique=True, nullable=False, default="")
    is_verified = db.Column(db.Boolean, nullable=False, default=False)
    sended_at = db.Column(db.DateTime, nullable=True)
    verified_at = db.Column(db.DateTime, nullable=True)
    expired = db.Column(db.Boolean, nullable=False, default=False)

    def __repr__(self):
        return '<%r %r>' % (self.__class__.__name__, self.name)
Пример #18
0
class Link(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    full_link = db.Column(db.String)
    page = db.Column(db.String, unique=True)
    short_link = db.Column(db.String)
    visits = db.Column(db.Integer, default=0)
    created = db.Column(db.DateTime, index=True, default=datetime.now())

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))

    def __repr__(self):
        return f'<ID {self.id}>'

    def get_date(self):
        return self.created.strftime('%d.%m.%y %H:%M')
Пример #19
0
class Message(CRUDMixin, db.Model):
    "Lists messages exchanged between users."
    __tablename__ = "message"
    id = db.Column(db.Integer, primary_key=True)

    sender_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
    sender = db.relationship("User", foreign_keys=[sender_id])

    receiver_id = db.Column(db.Integer,
                            db.ForeignKey("user.id"),
                            nullable=False)
    receiver = db.relationship("User", foreign_keys=[receiver_id])

    listing_id = db.Column(db.Integer,
                           db.ForeignKey("listing.id"),
                           nullable=False)
    listing = db.relationship("Listing")

    timestamp = db.Column(db.DateTime, server_default=func.now())
    message_text = db.Column(db.String(255), nullable=False)

    def __repr__(self):
        return "<Message #%s:%r:%r:%r>" % (self.id, self.message_text,
                                           self.sender, self.listing)
Пример #20
0
class Quest(db.Model):
    __tablename__ = "quests"
    id = db.Column(
        INTEGER(unsigned=True),
        primary_key=True,
        autoincrement=True,
    )
    user_id = db.Column(
        INTEGER(unsigned=True),
        db.ForeignKey("users.id", ondelete="cascade", onupdate="cascade"),
        nullable=False,
    )
    name = db.Column(db.String(255), nullable=False)
    category = db.Column(db.String(255), nullable=False)
    description = db.Column(db.String(5000))
    exp = db.Column(INTEGER(unsigned=True), default=0)
    done = db.Column(db.Boolean, default=False)
    created_at = db.Column(
        db.DateTime,
        server_default=db.func.current_timestamp(),
        server_onupdate=db.func.current_timestamp(),
        nullable=False,
    )
    updated_at = db.Column(
        db.DateTime,
        server_default=db.func.current_timestamp(),
        server_onupdate=db.func.current_timestamp(),
        nullable=False,
    )
    quests_shared = db.relationship("QuestShared",
                                    backref="quest",
                                    cascade="all")
    quests_exp = db.relationship("QuestExp", backref="quest", cascade="all")
    tasks = db.relationship("Task", backref="quest", cascade="all")

    def __init__(self, user_id, name, category, description=None):
        self.user_id = user_id
        self.name = name
        self.category = category
        self.description = description

    def to_dict(self):
        return dict(
            id=self.id,
            name=self.name,
            category=self.category,
            description="" if self.description is None else self.description,
        )
Пример #21
0
class Match(PkModel):
    """A role for a user."""

    __tablename__ = "match"
    id = Column(db.Integer, primary_key=True)
    external_id = Column(db.Integer)
    player_stats = relationship("PlayerStat", backref="match", lazy=True)
    team_id = db.Column(db.Integer, db.ForeignKey('team.id'), nullable=False)

    def __init__(self, name, **kwargs):
        """Create instance."""
        super().__init__(**kwargs)

    def __repr__(self):
        """Represent instance as a unique string."""
        return f"<Match({self.external_id})>"
Пример #22
0
class SentosaUntersuchung(db.Model, BaseMixin):
    __tablename__ = "sentosaUnters"

    sentosaUntersID = db.Column(db.Integer, primary_key=True)
    bezeichnung = db.Column(db.String)
    host_code = db.Column(db.String)
    sentosaSetting_id = db.Column(db.Integer,
                                  db.ForeignKey('sentosaSettings.sentosaID'))

    def __init__(self, bezeichnung, host_code):
        self.bezeichnung = bezeichnung
        self.host_code = host_code

    @classmethod
    def find_by_host_code(cls, host_code):
        return cls.query.filter_by(host_code=host_code).first()
Пример #23
0
class Release(db.Model):
    __tablename__ = 'release'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), unique=True)
    description = db.Column(db.String(180), unique=False)
    open_date =  db.Column(db.String(80), unique=False)
    close_date = db.Column(db.String(80), unique=False)
    comment = db.Column(db.String(300), unique=False)
    xml = db.Column(db.String(80), unique=False)
    status = db.Column(db.String(20), unique=False)

    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))

    def __repr__(self):
        return '%r' % (self.name)
Пример #24
0
class Recipient(db.Model):
    __tablename__ = 'recipients'
    id = db.Column(db.Integer, primary_key=True)
    email_address = db.Column(db.String, nullable=False)
    event_id = db.Column(db.Integer, db.ForeignKey('events.id'))
    is_sent = db.Column(db.Boolean, nullable=True, default=False)
    sent_at = db.Column(db.DateTime, nullable=True)

    def __init__(self, email_address, event_id, is_sent=None, sent_at=None):
        self.email_address = email_address
        self.event_id = event_id
        self.is_sent = is_sent
        self.sent_at = sent_at

    def __repr__(self):
        return '<ID: {} Email: {}'.format(self.id, self.email_address)
Пример #25
0
class TestPlan(db.Model):
    __tablename__ = 'test_plan'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), unique=True)
    description = db.Column(db.String(180), unique=False)
    comment = db.Column(db.String(300), unique=False)
    status = db.Column(db.String(20), unique=False)

    test_case = db.relationship("TestCase",
                                backref="test_plan",
                                lazy="dynamic")
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))

    def __repr__(self):
        return '%r' % (self.name)
Пример #26
0
class ContactEmail(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    contact_id = db.Column(db.Integer, db.ForeignKey('contact.id'))
    contact = db.relationship("Contact")
    email = db.Column(db.String(120), nullable=False, unique=True)
    created_at = db.Column(db.DateTime, default=datetime.now, index=True)

    __mapper_args__ = {"order_by": created_at}
    __tablename__ = 'contact_email'

    def __repr__(self):
        return ('<{class_name}('
                'contact_id={self.id}, '
                'username="******")'
                'email="{self.email}">'.format(
                    class_name=self.__class__.__name__, self=self))
Пример #27
0
class Product(db.Model):
    __tablename__ = 'products'
    id = db.Column(db.Integer, primary_key=True)
    full_name = db.Column(db.String(255), nullable=False)
    short_name = db.Column(db.String(255), nullable=False)
    raw_description = db.Column(db.Text, nullable=False)
    img = db.Column(db.String(255), nullable=True)
    price = db.Column(db.String(25), nullable=False)
    color = db.Column(db.String(255), nullable=True)
    review_number = db.Column(db.Integer, nullable=True)

    category_id = db.Column(db.Integer, db.ForeignKey('category.id'), nullable=False)
    category = db.relationship('Category', backref=db.backref('product', lazy=True))

    def __str__(self):
        return self.short_name
Пример #28
0
class Task(db.Model):
    """
    Model for tasks – everything user has to work on.
    All of the tasks are bound by dane before which they must be accomplished although the date isn't fixed.
    """
    __tablename__ = 'tasks'
    id = db.Column(Integer, primary_key=True)
    name = db.Column(String(200), nullable=False)
    date = db.Column(Date, nullable=False)
    done = db.Column(Boolean)
    # priority: Integer for ordering importance of tasks. The base priority value is 0.
    priority = db.Column(Integer, nullable=False)
    # date_created: saved for future usage
    date_created = db.Column(DateTime, nullable=False)
    # user_id: nullable for testing and API development version compatibility
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=True)

    def __init__(self, name, date, done=False, priority=0):
        self.name = name
        self.date = date
        self.done = done
        self.priority = priority
        self.date_created = datetime.utcnow()

    def __repr__(self):
        return '<Task {}: {}>'.format(self.id, self.name)

    @staticmethod
    def from_form_data(form):
        """
        Creates new Task object from given Flask-WTF Form.
        :param form: Flask-WTF Form instance
        :return: new Task object
        """
        return Task(name=form.name.data,
                    date=form.date.data,
                    done=form.done.data,
                    priority=form.priority.data)

    @hybrid_property
    def date_time(self):
        """
        Creates datetime object from given date field and midnight ending this date

        :return: datetime object equivalent to this date
        """
        return datetime.combine(self.date, datetime.max.time())
Пример #29
0
class Slides(db.Model):
    __tablename__ = "slides"
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(300))
    hsize = db.Column(db.String(100))
    hcolor = db.Column(db.String(100))
    hfont = db.Column(db.String(100))
    hbg = db.Column(db.String(100))
    subti = db.Column(db.String(300))
    tsize = db.Column(db.String(100))
    tcolor = db.Column(db.String(100))
    tfont = db.Column(db.String(100))
    tbg = db.Column(db.String(100))
    bname = db.Column(db.String(300))
    ikey = db.Column(db.Integer,
                     db.ForeignKey("media.id", ondelete='cascade'),
                     nullable=True)
class OAuth2Token(CRUDMixin, db.Model, OAuth2TokenMixin):
    __tablename__ = 'oauth2_token'

    provider = db.Column('provider',
                         db.String(255),
                         nullable=False,
                         default='opus')

    user_id = db.Column('user_id',
                        GUID(),
                        db.ForeignKey('users.id',
                                      name="oauth2_token_user_id_fkey"),
                        nullable=False)
    users = db.relationship("Users",
                            uselist=False,
                            back_populates="oauth2_token",
                            cascade=KEEP_PARENTS)