コード例 #1
0
ファイル: models.py プロジェクト: dariomiceli/Flask_blog
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(20), nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    def __repr__(self):
        return f"Post('{self.title}', '{self.date_posted}')"
コード例 #2
0
class Edge(db.Model):
    __tablename__ = 'edge'
    id = db.Column(db.Integer(), primary_key=True)
    source = db.Column(db.Integer(), db.ForeignKey('node.id'), nullable=False)
    target = db.Column(db.Integer(), db.ForeignKey('node.id'), nullable=False)
    crawlerId = db.Column(db.Integer(),
                          db.ForeignKey('crawler.id'),
                          nullable=False)

    def as_dict(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}
コード例 #3
0
class Administrator(db.Model):
  __bind_key__ = 'wehomeproperty'
  id = db.Column(db.Integer(), index=True, primary_key=True)
  user_id = db.Column(db.Integer(), db.ForeignKey("user.id", ondelete="CASCADE"),
                      nullable=False, index=True, unique=True)
  created_at = db.Column(db.DateTime(), default=datetime.datetime.now)
  updated_at = db.Column(db.DateTime(), default=datetime.datetime.now, onupdate=datetime.datetime.now)
  
  @staticmethod
  def is_user_admin(user_id):
    admin = Administrator.query.filter_by(user_id=user_id).first()
    return admin is not None
コード例 #4
0
ファイル: models.py プロジェクト: topnaita/Blog
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    image_file = db.Column(db.String(20),
                           nullable=False,
                           default='default.jpg')
    password = db.Column(db.String(60), nullable=False)
    posts = db.relationship('Post', backref='author', lazy=True)

    def __repr__(self):
        return f"User('{self.username}', '{self.email}', '{self.image_file}')"
コード例 #5
0
class RevokedTokenModel(db.Model):
    __tablename__ = 'revoked_tokens'
    id = db.Column(db.Integer, primary_key=True)
    jti = db.Column(db.String(120))

    def add(self):
        db.session.add(self)
        db.session.commit()

    @classmethod
    def is_jti_blacklisted(cls, jti):
        query = cls.query.filter_by(jti=jti).first()
        return bool(query)
コード例 #6
0
class UserTags(db.Model):
    __tablename__ = "user_tag"
    id = db.Column(db.Integer(), primary_key=True)
    user_id = db.Column(db.Integer(), ForeignKey('user.id'))
    tag_id = db.Column(db.Integer(), ForeignKey('tag.id'))

    tag = relationship("Tag",
                       primaryjoin="and_(UserTags.tag_id==Tag.id)",
                       backref="user_tags")

    def __init__(self, user_id, tag_id):
        self.user_id = user_id
        self.tag_id = tag_id
コード例 #7
0
ファイル: models.py プロジェクト: ch4nc3l0/apache_catalog
class Usercat(UserMixin, db.Model):
    __tablename__ = 'usercat'
    id = db.Column(db.Integer, primary_key=True, nullable=False)
    username = db.Column(db.String(80), nullable=False)
    picurl = db.Column(db.String(2000))

    def __init__(self, id, username, picurl):
        self.id = id
        self.username = username
        self.picurl = picurl

    def __repr__(self):
        return '<id {}>'.format(self.id)
コード例 #8
0
class Rule(db.Model):
  __bind_key__ = 'wehomeproperty'
  id = db.Column(db.Integer(), index=True, primary_key=True)
  users = relationship("User", secondary=user_rule_association, back_populates="rules")
  api_id = db.Column(db.String(255))
  throttle_day = db.Column(db.String(255))
  throttle_hour = db.Column(db.String(255))
  throttle_min = db.Column(db.String(255))
  includes = db.Column(db.Text())
  excludes = db.Column(db.Text())
  statistics = db.Column(db.Boolean(), default=False)
  notes = db.Column(db.String(255))
  extra = db.Column(db.Text())
コード例 #9
0
ファイル: models.py プロジェクト: kpully/flask-react
class Dog(db.Model):
    __tablename__ = 'dogs'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255))
    breed = db.Column(db.String(255))
    user_id = db.Column(db.Integer(), db.ForeignKey('users.id'))
    dog_image = db.Column(db.LargeBinary)

    def __init__(self, name, breed, user_id, image):
        self.name = name
        self.breed = breed
        self.user_id = user_id
        self.image = image
コード例 #10
0
class spys(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    targ = db.Column(db.Text, unique=True)
    arch = db.Column(db.Text)
    os = db.Column(db.Text)
    secret = db.Column(db.Text)
    calls = db.Column(db.Integer)
    ring = db.Column(db.Integer)
    firstseen = db.Column(db.Integer)
    lastseen = db.Column(db.Integer)
コード例 #11
0
class DoctorSchedule(db.Model):
    from application.models import Clinic
    permit_number = db.Column(db.String(), primary_key=True)
    date = db.Column(db.String(), primary_key=True)
    timeSlots = db.Column(db.String(), nullable=False)
    clinic_id = db.Column(db.Integer,
                          db.ForeignKey('clinic.id'),
                          nullable=False)

    def __iter__(self):
        yield 'permit_number', self.permit_number
        yield 'clinic_id', self.clinic_id
        yield 'date', self.date
        yield 'timeSlots', self.timeSlots
コード例 #12
0
class Appointment(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    room = db.Column(db.Integer,
                     db.ForeignKey('room.roomNumber'),
                     nullable=False)
    clinic_id = db.Column(db.Integer,
                          db.ForeignKey('clinic.id'),
                          nullable=False)
    doctor_permit_number = db.Column(db.String(7),
                                     db.ForeignKey('doctor.permit_number'),
                                     nullable=False)
    patient_hcnumber = db.Column(db.String(12),
                                 db.ForeignKey('patient.hcnumber'),
                                 nullable=False)
    length = db.Column(db.Integer, nullable=False)
    time = db.Column(db.String(), nullable=False)
    date = db.Column(db.Date(), nullable=False)

    def __iter__(self):
        yield 'id', self.id
        yield 'room', self.room
        yield 'clinic_id', self.clinic_id
        yield 'doctor_permit_number', self.doctor_permit_number
        yield 'patient_hcnumber', self.patient_hcnumber
        yield 'length', self.length
        yield 'time', self.time
        yield 'date', self.date.strftime("%Y-%m-%d")
コード例 #13
0
ファイル: Answers.py プロジェクト: linkmarche/Ask-Eng
class Answer(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.String(1000))
    register_date = db.Column(db.DateTime,
                              nullable=False,
                              default=datetime.utcnow)
    accepted = db.Column(db.Boolean)
    user_id = db.Column(db.Integer, nullable=False)
    question_id = db.Column(db.Integer, nullable=False)
    ups = db.Column(db.Integer)
    downs = db.Column(db.Integer)

    def __repr__(self):
        return '<Answer %r>' % self.id

    # the Answers object can now be iterated over. (also allows us to convert to a dict() )
    def __iter__(self):
        yield 'id', self.id
        yield 'text', self.text
        yield 'register_date', str(self.register_date)
        yield 'accepted', self.accepted
        yield 'user_id', self.user_id
        yield 'question_id', self.question_id
        yield 'ups', self.ups
        yield 'downs', self.downs
コード例 #14
0
class RecurringGroup(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    account_id = db.Column(db.Integer())
    label = db.Column(db.String(255))
    amount = db.Column(db.DECIMAL(19, 2))
    start_date = db.Column(db.Date())
    end_date = db.Column(db.Date())
    recurrence_day = db.Column(db.Integer())
    recurrence_month = db.Column(db.Integer())

    def __init__(self, account_id, label, amount, start_date, end_date,
                 recurrence_day, recurrence_month):
        self.account_id = account_id
        self.label = label
        self.amount = amount
        self.start_date = start_date
        self.end_date = end_date
        self.recurrence_day = recurrence_day
        self.recurrence_month = recurrence_month

    @staticmethod
    def get_groups(account_ids):
        if not isinstance(account_ids, (list)):
            account_ids = [account_ids]
        return RecurringGroup.query.filter(
            RecurringGroup.account_id.in_(account_ids)).all()
コード例 #15
0
class Node(db.Model):
    __tablename__ = 'node'
    id = db.Column(db.Integer(), primary_key=True)
    url = db.Column(db.String(255), unique=False, nullable=False)
    level = db.Column(db.Integer(), nullable=False)
    crawlerId = db.Column(db.Integer(),
                          db.ForeignKey('crawler.id'),
                          nullable=False)
    __table_args__ = (db.UniqueConstraint('url',
                                          'crawlerId',
                                          name='_url_crawlerId_uc'), )

    def as_dict(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}
コード例 #16
0
class Offer(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    asal = db.Column(db.String(255))
    tujuan = db.Column(db.String(255))
    fee = db.Column(db.Integer())
    time = db.Column(db.DateTime())
    passenger = db.Column(db.Integer)
    color = db.Column(db.Integer)

    @staticmethod
    def get_all_offers():
        offers = Offer.query.all()
        offers = {
            x.id: {
                'user_id': x.user_id,
                'asal': x.asal,
                'tujuan': x.tujuan,
                'fee': x.fee,
                'time': x.time,
                'passenger': x.passenger,
                'passengers': [y.id for y in x.passenger_list],
                'color': x.color
            }
            for x in offers
        }
        return offers
コード例 #17
0
ファイル: models.py プロジェクト: accionlabs/acciom
class TestSuite(db.Model):
    __tablename__ = "test_suite"
    test_suite_id = db.Column(db.Integer, primary_key=True)
    project_id = db.Column(db.ForeignKey('project.project_id'),
                           nullable=False,
                           index=True)
    owner_id = db.Column(db.ForeignKey('user.user_id'), nullable=False)
    excel_name = db.Column(db.Text)
    test_suite_name = db.Column(db.Text, nullable=False)
    is_deleted = db.Column(db.Boolean, nullable=False, default=False)
    created_at = db.Column(db.DateTime, default=datetime.now)
    modified_at = db.Column(db.DateTime, default=datetime.now)
    test_case = db.relationship("TestCase",
                                back_populates='test_suite',
                                lazy=True,
                                order_by='TestCase.created_at')

    def __init__(self, project_id, owner_id, excel_name, test_suite_name):
        self.project_id = project_id
        self.owner_id = owner_id
        self.excel_name = excel_name
        self.test_suite_name = test_suite_name

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()
コード例 #18
0
ファイル: models.py プロジェクト: accionlabs/acciom
class TestCaseLog(db.Model):
    __tablename__ = "test_case_log"
    test_case_log_id = db.Column(db.Integer, primary_key=True)
    test_case_id = db.Column(db.ForeignKey('test_case.test_case_id'),
                             index=True)
    job_id = db.Column(db.ForeignKey('job.job_id'), index=True)
    execution_status = db.Column(db.SMALLINT, nullable=False)
    dqi_percentage = db.Column(db.Float(precision=2), nullable=True)
    execution_log = db.Column(JSON, nullable=False)
    created_at = db.Column(db.DateTime, default=datetime.now)
    modified_at = db.Column(db.DateTime, default=datetime.now, index=True)
    test_cases = db.relationship(TestCase,
                                 back_populates='test_case_log',
                                 lazy=True)

    def __init__(
        self,
        test_case_id,
        job_id,
        execution_status=ExecutionStatus().get_execution_status_id_by_name(
            "new")):
        self.test_case_id = test_case_id
        self.job_id = job_id
        self.execution_status = execution_status

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()
コード例 #19
0
ファイル: models.py プロジェクト: JosephLee9297/betya
class Wallet(db.Model, DictSerializable):
    id = db.Column(db.Integer(), primary_key=True)
    user_id = db.Column(db.Integer(), db.ForeignKey('user.id'))
    address = db.Column(db.String(255), unique=True)
    guid = db.Column(db.String(255), unique=True)

    def __init__(self, user_id, address, guid):
        self.user_id = user_id
        self.address = address
        self.guid = guid

    @staticmethod
    def get_user_wallet(user_id):
        return Wallet.filter_by(user_id=user_id).first()
コード例 #20
0
ファイル: models.py プロジェクト: ch4nc3l0/apache_catalog
class Category(db.Model):
    __tablename__ = 'category'
    id = db.Column(db.Integer, primary_key=True, nullable=False,
                   autoincrement=True)
    name = db.Column(db.String(80), nullable=False)
    user = db.relationship(Usercat)
    user_id = db.Column(db.Integer, db.ForeignKey('usercat.id'))

    def __init__(self, name, user_id):
        self.name = name
        self.user_id = user_id

    def __repr__(self):
        return '<id {}>'.format(self.id)
コード例 #21
0
ファイル: models.py プロジェクト: atang167/storybook
class Tag(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    tag_name = db.Column(db.String(255))
    image_url = db.Column(db.String(255))

    def __init__(self, tag_name, image_url):
        self.tag_name = tag_name
        self.active = True
        self.image_url = image_url

    @staticmethod
    def get_tag_with_image_url(imageurl):
        tag = Tag.query.filter_by(imageurl=image_url)
        return tag
コード例 #22
0
class County(db.Model):
  __bind_key__ = 'wehomeproperty'
  id = db.Column(db.Integer(), index=True, primary_key=True)
  name = db.Column(db.String(255), index=True)
  geoid = db.Column(db.String(255), index=True, unique=True)
  cbsa_geoid = db.Column(db.String(255), index=True)
  lat = db.Column(db.Float())
  lng = db.Column(db.Float())
  properties = db.Column(JSON)
  created_at = db.Column(db.DateTime(), default=datetime.datetime.now)
  updated_at = db.Column(db.DateTime(), default=datetime.datetime.now, onupdate=datetime.datetime.now)
コード例 #23
0
class Nurse(db.Model):
    access_ID = db.Column(db.String(8), nullable=False, primary_key=True)
    fname = db.Column(db.String(30), nullable=False)
    lname = db.Column(db.String(30), nullable=False)
    password_hash = db.Column(db.String(100), nullable=False)

    def __repr__(self):
        return '<Nurse %r %r>' % self.fname % self.lname

    # to iterate over a patient to retrieve specific attributes
    def __iter__(self):
        yield 'access_ID', self.access_ID
        yield 'fname', self.fname
        yield 'lname', self.lname
        yield 'password_hash', self.password_hash
コード例 #24
0
class City(db.Model):
  __bind_key__ = 'wehomeproperty'
  id = db.Column(db.Integer(), index=True, primary_key=True)
  geoid = db.Column(db.String(255), index=True, unique=True)
  area_geoid = db.Column(db.String(255), db.ForeignKey('area.geoid'), index=True)
  state_geoid = db.Column(db.String(255), db.ForeignKey('state.geoid'),index=True)
  zipcodes = db.relationship('Zipcode', backref='city')
  neighbors = db.relationship('Neighbor', backref='city_')
  name = db.Column(db.String(255), index=True)
  lat = db.Column(db.Float())
  lng = db.Column(db.Float())
  properties = db.Column(JSON)
  
  created_at = db.Column(db.DateTime(), default=datetime.datetime.now)
  updated_at = db.Column(db.DateTime(), default=datetime.datetime.now, onupdate=datetime.datetime.now)
コード例 #25
0
class Post(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    author = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
    location = db.Column(db.Integer,
                         db.ForeignKey("location.id"),
                         nullable=False)
    title = db.Column(db.String(255), unique=True)
    body = db.Column(db.String(255))

    def __init__(self, title, body, author_id, location):
        self.active = True
        self.title = title
        self.body = body
        self.author = author_id
        self.location = location
コード例 #26
0
class Message(db.Model):

    __tablename__ = 'messages'

    id = db.Column(db.Integer, primary_key=True)
    site_id = db.Column(db.ForeignKey('sites.site_id'), index=True)
    received = db.Column(db.DateTime, nullable=False)
    ts = db.Column(db.DateTime, nullable=False, index=True)
    message = db.Column(JSONB, nullable=False)

    def __init__(self, message):
        self.message = message
        self.site_id = message['site_id']
        self.received = datetime.utcnow()        
        # fill trailing zeros to make sure the ts string is the expected length
        self.ts = datetime.strptime(message['ts'] + '0' * (14 - len(message['ts'])), '%Y%m%d%H%M%S')
コード例 #27
0
ファイル: models.py プロジェクト: bopopescu/mvp
class ChallengeFollower(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    challenge_instance_id = db.Column(db.Integer(),
                                      db.ForeignKey("challenge_instance.id"),
                                      nullable=False)
    challenge_instance = db.relationship('ChallengeInstance')
    follower_id = db.Column(db.Integer(),
                            db.ForeignKey("user.id"),
                            nullable=False)
    follower = db.relationship('User')
    date_joined = db.Column(db.DateTime(), nullable=False)

    def __init__(self, challenge, follower):
        self.challenge_instance = challenge
        self.follower = follower
        self.date_joined = datetime.datetime.now()
コード例 #28
0
class DbDetail(db.Model):
    __tablename__ = "dbdetail"
    db_id = db.Column(INTEGER(unsigned=True),
                      autoincrement=True,
                      primary_key=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('user.user_id'),
                        nullable=False)
    connection_name = db.Column(db.String(80))
    db_type = db.Column(db.String(80), nullable=False)
    db_name = db.Column(db.String(80), nullable=False)
    db_hostname = db.Column(db.String(128), nullable=False)
    db_username = db.Column(db.String(80), nullable=False)
    db_password = db.Column(db.String(256))  #
    users = db.relationship('User', back_populates='dbdetail', lazy=True)
    created = db.Column(db.DateTime, default=datetime.datetime.now)

    def __init__(self, connection_name, db_type, db_name, db_hostname,
                 db_username, db_password, user_id):
        self.connection_name = connection_name
        self.db_type = db_type
        self.db_name = db_name
        self.db_hostname = db_hostname
        self.db_username = db_username
        self.db_password = db_password
        self.user_id = user_id

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()

    def get_private_key(password1):
        salt = b"this is a salt"
        kdf = PBKDF2(password1, salt, 64, 1000)
        key = kdf[:32]
        return key

    def encrypt(raw):
        private_key = DbDetail.get_private_key(
            app.config.get('DB_ENCRYPTION_KEY'))
        raw = pad(raw)
        iv = Random.new().read(AES.block_size)
        cipher = AES.new(private_key, AES.MODE_CBC, iv)
        return base64.b64encode(iv + cipher.encrypt(raw))

    def decrypt(enc):
        private_key = DbDetail.get_private_key(
            app.config.get('DB_ENCRYPTION_KEY'))
        enc = base64.b64decode(enc)
        iv = enc[:16]
        cipher = AES.new(private_key, AES.MODE_CBC, iv)
        return unpad(cipher.decrypt(enc[16:]))
コード例 #29
0
class tasks(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    targ = db.Column(db.Text)
    job = db.Column(db.Integer, unique=True)
    command = db.Column(db.Text)
    status = db.Column(db.Text)
    taskdate = db.Column(db.Integer)
    completedate = db.Column(db.Integer)
    complete = db.Column(db.Boolean)
コード例 #30
0
class State(db.Model):
  __bind_key__ = 'wehomeproperty'
  id = db.Column(db.Integer(), index=True, primary_key=True)
  geoid = db.Column(db.String(255), index=True, unique=True)
  name = db.Column(db.String(255))
  name_abbr = db.Column(db.String(255))
  lat = db.Column(db.Float())
  lng = db.Column(db.Float())
  properties = db.Column(JSON)
  cities = db.relationship('City', backref='state')
  
  created_at = db.Column(db.DateTime(), default=datetime.datetime.now)
  updated_at = db.Column(db.DateTime(), default=datetime.datetime.now, onupdate=datetime.datetime.now)