Пример #1
0
class Folder(BaseModel):
    name = TextField()
    parent_id = IntegerField(default=0)
    created = TimestampField(default=datetime.datetime.now, utc=True)
    modified = TimestampField(default=datetime.datetime.now, utc=True)
    payload = BlobField(null=True)
    md5 = TextField(null=True)
    readable = BooleanField(default=True)
    writable = BooleanField(default=True)
    isDir = BooleanField()
    size = IntegerField(default=0)
    meta_info = ForeignKeyField(PaperRecord, null=True)

    def save(self, *args, **kwargs):
        self.modified = datetime.datetime.now()
        if self.payload is not None:
            self.md5 = md5(bytes(self.payload)).hexdigest()
        if 'only' in kwargs:
            kwargs['only'] = [k for k in kwargs['only']] + ['modified', 'md5']
        return super(Folder, self).save(*args, **kwargs)

    class Meta:
        indexes = (
            # create a unique constraint
            ((
                'parent_id',
                'name',
            ), True), )
Пример #2
0
class problem(BaseModel):
    ID = IntegerField(primary_key=True)
    is_public = BooleanField()
    title = TextField()
    description = TextField()
    input_description = TextField()
    output_description = TextField()
    samples = BinaryJSONField()
    test_case_score = BinaryJSONField()
    hint = TextField()
    languages = BinaryJSONField()
    template = BinaryJSONField()
    create_time = TimestampField()
    last_update_time = TimestampField()
    time_limit = IntegerField()
    memory_limit = IntegerField()
    difficulty = IntegerField()
    source = TextField()
    total_score = IntegerField()
    submission_number = BigIntegerField()
    accepted_number = BigIntegerField()
    statistic_info = BinaryJSONField()
    created_by_id = CharField(max_length=50)

    class Meta:
        db_table = "problem"
Пример #3
0
class PostModel(Model):
    """Model for posts."""

    class Meta:
        """TODO document this."""

        database = db
        table_name = POSTS_TABLE

    id = UUIDField(unique=True, null=False, column_name="id", primary_key=True)
    user_id = ForeignKeyField(
        UserModel,
        on_delete="CASCADE",
        on_update="CASCADE",
        column_name="user_id",
    )
    image_id = ForeignKeyField(
        ImageModel,
        on_delete="CASCADE",
        on_update="CASCADE",
        column_name="image_id",
        null=True,
    )
    content = CharField(null=True)
    create_time = TimestampField(default=None, resolution=0, utc=False)
    edited = BooleanField(null=False, default=False)
    edit_time = TimestampField(default=None, resolution=0, utc=False)
    visibility = CharField(null=False, default="public")
    likes = ArrayField(null=True, field_class=TextField)
Пример #4
0
class Comment(BaseModel):
    class Meta:
        table_name = 'comment'

    comment_id = TextField(unique=True)
    approved_at_utc = BooleanField(default=None, null=True)
    author = ForeignKeyField(Author, backref='comment')
    author_flair = ForeignKeyField(AuthorFlair,
                                   backref='comment',
                                   default=None,
                                   null=True)
    archived = BooleanField(default=None, null=True)
    banned_at_utc = BooleanField(default=None, null=True)
    body = TextField()
    created_utc = TimestampField(index=True)
    edited = BooleanField(default=None, null=True)
    gilded = IntegerField(default=None, null=True)
    is_submitter = BooleanField(default=None, null=True)
    link_id = TextField(default=None, null=True)
    parent_id = TextField(default=None, null=True)
    retrieved_on = TimestampField(default=None, null=True, index=True)
    score = IntegerField(default=0, null=True)
    stickied = BooleanField(default=None, null=True)
    subreddit = ForeignKeyField(Subreddit, backref='comment')
    number_urls = IntegerField(default=None, null=True, index=True)
    deleted = BooleanField(default=None, null=True, index=True)
Пример #5
0
class AgendaModel(BaseModel):
    id_agenda = AutoField(column_name='id_agenda', primary_key=True)
    nombre = CharField(column_name='nombre')
    fecha_inicio = DateTimeField(column_name='fecha_inicio', null=True)
    fecha_final = DateTimeField(column_name='fecha_final', null=True)
    motivo = CharField(column_name='motivo', null=True)
    tipo_cita = ForeignKeyField(TipoCitaModel, null=True)
    veterinario = ForeignKeyField(UserModel)
    usuario = ForeignKeyField(UserModel, null=True)
    mascota = ForeignKeyField(MascotaModel, null=True)
    creado = TimestampField(column_name='creado')
    actualizado = TimestampField(column_name='actualizado')
    eliminado = DateTimeField(column_name='eliminado', null=True)

    class Meta:
        table_name = 'agenda'

    def agenda_intervalo(segundos):
        minutos, segundos = divmod(segundos, 60)
        horas, minutos = divmod(minutos, 60)
        dias, horas = divmod(horas, 24)

        return dias, horas, minutos, segundos

    def delete(self):
        self.eliminado = None if self.eliminado is not None else datetime.now()
        self.save()
Пример #6
0
class SubmissionModel(BaseModel):
    submission_id = TextField()
    sticky_cmt_id = TextField(null=True)
    lock_type = TextField(null=True)
    lock_remaining = TimestampField(default=0)
    remove_remaining = TimestampField(default=0)
    subreddit = TextField()
Пример #7
0
class UserModel(BaseModel):
    id = AutoField(column_name='id', primary_key=True)
    nombre = CharField(column_name='nombre', max_length=60)
    apellido = CharField(column_name='apellido', max_length=60)
    email = CharField(column_name='email', max_length=100, unique=True)
    password = CharField(column_name='password', max_length=150)
    celular = CharField(column_name='celular', max_length=10)
    direccion = CharField(column_name='direccion', max_length=255)
    remember_token = CharField(null=True, max_length=255)
    rol = ForeignKeyField(RolModel)
    creado = TimestampField(column_name='creado')
    actualizado = TimestampField(column_name='actualizado')
    eliminado = DateTimeField(column_name='eliminado', null=True)

    class Meta:
        table_name = 'usuarios'
    
    def save(self, *args, **kwargs):
        super(UserModel, self).save(*args, **kwargs)
    
    def verify_password(self, pwd: str)-> bool:
        return check_password_hash(self.password, pwd)

    def delete(self):
        self.eliminado = None if self.eliminado is not None else datetime.now()
        self.save()

    def create_jwt(self):
        payload = {'payload': self.email, 'exp': datetime.utcnow() + timedelta(hours=1)}
        self.remember_token = jwt.encode(payload=payload, key=app.config.get('SECRET_KEY'), algorithm="HS256")
        self.save()

    @staticmethod
    def decode_jwt(token):
        try:
            payload = jwt.decode(token, key=app.config.get('SECRET_KEY'), algorithms=["HS256"])
            
        except:
            abort(make_response(jsonify(message="No autorizado", error=True)), 401)  
        return payload


    @staticmethod
    def make_password(pwd: str)-> str:
        return generate_password_hash(pwd, method='sha256')

    @classmethod
    def create(cls, **query):
        query['password'] = cls.make_password(query['password'])
        return super().create(**query)

    @classmethod
    def login(cls, **kwargs):
        self: cls = cls.get_or_none(cls.email == kwargs['email'])
        
        if self is None or not self.verify_password(kwargs['password']):
            abort(make_response(jsonify(message='Lo sentimos, sus credenciales no son correctas. Verifique o regístrese antes de volver a intentarlo.', error=True),422))

        return self
Пример #8
0
class Document(BaseModel):
    filename = CharField(unique=True)
    # tag_ids = CharField(null=True)
    ts_added = TimestampField()
    ts_updated = TimestampField()

    def __repr__(self):
        return self.filename
Пример #9
0
class TestModel(BaseModel):

    id = AutoField()
    time_start = TimestampField()
    time_end = TimestampField()
    status = IntegerField()
    elapsed_time = IntegerField()
    test_info = ForeignKeyField(TestInfoModel)
    test_set = ForeignKeyField(TestSetModel, backref="tests")
Пример #10
0
class Topic(BaseModel):
    id = PrimaryKeyField(null=False)
    title = CharField()
    link = CharField()
    ext_id = IntegerField()
    saved_on = TimestampField()
    announced_on = TimestampField()

    class Meta:
        db_table = 'topics'
Пример #11
0
class Contact(Model):
    #  id = PrimaryKeyField()
    #  user_id = CharField(unique=True)
    user = ForeignKeyField(User, related_name='contacts')
    name = CharField()
    phone_number = CharField()
    created_at = TimestampField(null=False)
    updated_at = TimestampField(null=False)

    class Meta:
        database = DATABASE
Пример #12
0
class Role(BaseModel, RoleMixin):
    class Meta:
        table_name = 'roles'

    name = CharField(unique=True)
    description = TextField(null=True)
    label = CharField()
    created_at = TimestampField(default=None)
    updated_at = TimestampField()
    deleted_at = TimestampField(default=None, null=True)

    def __init__(self, *args, **kwargs):
        super(Role, self).__init__(*args, **kwargs)
Пример #13
0
class Infraction(Model):
    id = PrimaryKeyField()
    guild_id = BigIntegerField()
    user_id = BigIntegerField()
    mod_id = BigIntegerField()
    type = CharField(max_length=10, collation="utf8mb4_general_ci")
    reason = CharField(max_length=2000, collation="utf8mb4_general_ci")
    start = TimestampField()
    end = TimestampField(null=True)
    active = BooleanField(default=True)

    class Meta:
        database = connection
Пример #14
0
class Job(Model):
    id = CharField()
    job_id = CharField()
    job_type = CharField()
    created_at = TimestampField(default=get_timestamp)
    updated_at = TimestampField(null=True)
    done = IntegerField(default=0)
    response = TextField(null=True)
    archiveid = TextField(default='')
    error = IntegerField(default=0)
    description = TextField(null=True)

    class Meta:
        database = db
        table_name = 'jobs'
Пример #15
0
class Command(BaseModel):
    id = PrimaryKeyField()
    order = IntegerField()
    cmd = CharField()
    type: CommandType = EnumField(choices=CommandType,
                                  default=CommandType.NORMAL)
    job: Job = ForeignKeyField(Job, on_delete='CASCADE')
    log_start = BigIntegerField(null=True, default=None)
    log_end = BigIntegerField(null=True, default=None)
    start = TimestampField(null=True, default=None)
    end = TimestampField(null=True, default=None)
    return_code = IntegerField(null=True, default=None)

    @classmethod
    def create(cls, **query) -> 'Command':
        return super().create(**query)
Пример #16
0
class Thing(Model):
    # This table is not meant to represent a complete relationship of submissions/comments on reddit

    # Its behaviour is more of a log to track submissions and comments
    # that have had replies attempted and prevent replying twice

    # It also acts as a job queue of sorts, for the model text generator daemon

    # timestamp representation of when this record was entered into the database
    created_utc = TimestampField(default=time.time, utc=True)

    # the praw *name* of the original comment or submission,
    # where t3_ prefix = submission, t1_ prefix = comment
    source_name = TextField()

    # json object of the model parameters, passed into the generator daemon function
    text_generation_parameters = JSONField(null=True)

    # Count text generation attempts. In normal operation this will only be 0 or 1
    text_generation_attempts = IntegerField(default=0)
    # text generated by model and returned to the job
    generated_text = TextField(null=True)

    # the subreddit used by new_submission job type
    subreddit = TextField(null=True)

    # attempts to post the generated_text back to reddit
    reddit_post_attempts = IntegerField(default=0)

    # The 'name' of the object posted back to reddit
    posted_name = TextField(null=True)

    class Meta:
        database = db
class SteamGameNews(Model):
    game = ForeignKeyField(SteamGame)
    steam_news_id = BigIntegerField()
    steam_date = TimestampField()

    class Meta:
        database = db
class Comment(BaseModel):
    rid = CharField(unique=True)
    sub_rid = ForeignKeyField(Submission, backref="comments")
    redditor = ForeignKeyField(User, backref="comments", null=True)
    score = IntegerField()
    subreddit = ForeignKeyField(Subreddit, backref="comments")
    timestamp = TimestampField()
Пример #19
0
class contest(BaseModel):
    id = IntegerField(primary_key=True)
    title = CharField(max_length=128)
    description = TextField()
    password = TextField()
    rule_type = TextField()
    start_time = TimestampField()
    end_time = TimestampField()
    create_time = TimestampField()
    last_update_time = TimestampField()
    visible = BooleanField()
    allowed_ip_ranges = BinaryJSONField()
    created_by_id = CharField(max_length=50)

    class Meta:
        db_table = "contest"
Пример #20
0
class WikiPageVersion(BaseModel):
    """Model of page versions.
    """
    wiki_page = ForeignKeyField(WikiPage, backref='versions')
    diff = TextField()
    version = IntegerField()
    modified_on = TimestampField(resolution=1000, utc=True)
Пример #21
0
class HistoriasModel(BaseModel):
    id_historia = AutoField(column_name='id_historia', primary_key=True)
    observacion = CharField(column_name='observacion', max_length=255)
    medicamentos = CharField(column_name='medicamentos',
                             max_length=100,
                             null=True)
    fecha = DateField(column_name='fecha')
    tipo_cita = ForeignKeyField(TipoCitaModel)
    mascota = ForeignKeyField(MascotaModel)
    veterinario = ForeignKeyField(UserModel)
    usuario = ForeignKeyField(UserModel)
    creado = TimestampField(column_name='creado')
    actualizado = TimestampField(column_name='actualizado')
    eliminado = DateTimeField(column_name='eliminado', null=True)

    class Meta:
        table_name = 'historias'
Пример #22
0
class User(Model):
    #  id = PrimaryKeyField()
    name = CharField()
    user_id = CharField(unique=True)
    conversation_state = CharField()
    fp_user = CharField(null=True)
    fp_pass = CharField(null=True)
    fp_api_token = CharField(null=True)
    fp_api_refresh_token = CharField(null=True)
    fp_api_token_expiration = TimestampField(null=True)
    fp_api_connection_errors = IntegerField(default=0)
    send_text_phone = IntegerField(null=True)
    created_at = TimestampField(null=False)
    updated_at = TimestampField(null=False)

    class Meta:
        database = DATABASE
Пример #23
0
class Vault(Model):
    account_id = CharField()
    updated_at = TimestampField(default=get_timestamp)
    response = TextField()

    class Meta:
        database = db
        table_name = 'vaults'
Пример #24
0
        class Activity(Model):
            key = CharField(index=True, default="")
            gitHostRefs = CharField(index=True, default="")
            name = CharField(index=True, default="")
            repo = CharField(index=True, default="")
            timestamp = TimestampField(index=True, default=j.data.time.epoch)

            class Meta:
                database = indexinfo.indexDB
Пример #25
0
class DeletedArchive(Model):
    vaultname = CharField()
    archiveid = TextField()
    response = TextField(null=True)
    deleted_at = TimestampField(default=get_timestamp)

    class Meta:
        database = db
        table_name = 'deleted_archives'
Пример #26
0
class Submission(BaseModel):
    class Meta:
        table_name = 'submission'

    link_id = TextField(unique=True)  # "ao38em",
    author = ForeignKeyField(Author, backref='submission')
    author_flair = ForeignKeyField(AuthorFlair,
                                   backref='submission',
                                   default=None,
                                   null=True)  # verified",
    created_utc = TimestampField(index=True)  # 1517416133,
    title = TextField(
    )  # The opposite of r/ChoosingBeggars - my wife trying to sell her car.
    domain = ForeignKeyField(Domain,
                             backref='submission',
                             default=None,
                             null=True)  # imgur.com",
    full_link = TextField(default=None, null=True)
    link_flair_text = TextField(default=None, null=True)
    is_crosspostable = BooleanField(default=None, null=True)  # true,
    is_reddit_media_domain = BooleanField(default=None, null=True)  # false,
    is_self = BooleanField(default=None, null=True)  # false,
    is_video = BooleanField(default=None, null=True)  # false,
    locked = BooleanField(default=None, null=True)  # false,
    num_comments = IntegerField(default=None, null=True)  # 0,
    media = ForeignKeyField(Url, default=None, null=True)
    over_18 = BooleanField(default=None, null=True)  # true,
    preview = ForeignKeyField(Url, default=None,
                              null=True)  # https://imgur.com/a/Zp1D8",
    pinned = BooleanField(default=None, null=True)  # false,
    retrieved_on = TimestampField(default=None, null=True,
                                  index=True)  # 1517416135,
    score = IntegerField(default=0, null=True)  # 1,
    selftext = TextField(default=None, null=True)  # ",
    spoiler = BooleanField(default=None, null=True)  # false,
    stickied = BooleanField(default=None, null=True)  # false,
    subreddit = ForeignKeyField(Subreddit,
                                backref='submission')  # humansbeingbros",
    thumbnail = ForeignKeyField(Url, default=None, null=True)  # default",
    view_count = IntegerField(default=None, null=True)
    permalink = TextField(
        default=None, null=True
    )  # /r/HumansBeingBros/comments/ao38em/the_opposite_of_rchoosingbeggars_my_wife_trying/
    deleted = BooleanField(default=None, null=True, index=True)
Пример #27
0
class FinancialDonate(BaseModel):
    id = AutoField(primary_key=True, )
    category = ForeignKeyField(
        FinancialCategory,
        backref="categories",
        on_delete="CASCADE",
        on_update="CASCADE",
    )
    student = ForeignKeyField(
        Student,
        backref="students",
        on_delete="CASCADE",
        on_update="CASCADE",
    )
    summ = IntegerField()
    create_date = TimestampField(default=fn.NOW())
    update_date = TimestampField(null=True)

    class Meta:
        table_name = "financial_donates"
Пример #28
0
class Packet(Model):
    size = IntegerField()

    sender = TextField()
    receiver = TextField()
    interface_used = TextField()

    datetime = TimestampField(resolution=1e3)  # ms

    class Meta:
        database = db = SqliteDatabase('data.db')
Пример #29
0
class MascotaModel(BaseModel):
    id_mascota = AutoField(column_name='id_mascota', primary_key=True)
    nombre = CharField(column_name='nombre', max_length=45)
    genero = CharField(column_name='genero', max_length=1)
    edad = CharField(column_name='edad')
    raza = CharField(column_name='raza')
    peso = CharField(column_name='peso')
    estado_salud = CharField(column_name='estado_salud', max_length=60)
    tipo_mascota = CharField(column_name="tipo_mascota")
    usuario_id = ForeignKeyField(UserModel)
    creado = TimestampField(column_name='creado')
    actualizado = TimestampField(column_name='actualizado')
    eliminado = DateTimeField(column_name='eliminado', null=True)

    class Meta:
        table_name = 'mascotas'

    def delete(self):
        self.eliminado = None if self.eliminado is not None else datetime.now()
        self.save()
Пример #30
0
class Person(Model):
    uname = CharField()  # user name, e.g. janedoe
    role = CharField()  # role is usually empty or "library"
    display_name = CharField()  # display_name, optional
    updated = TimestampField()  # last successful login timestamp

    def has_role(self, required_role):
        return self.role == required_role

    class Meta:
        database = _db