Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class Token(Table):
id = pw.CharField(
unique=True, primary_key=True, default=random_string, max_length=10
)
user = pw.ForeignKeyField(User)
class Language(Table):
name = pw.CharField()
shell_cmd = pw.CharField()
memory_multiplier = pw.FloatField()
time_multiplier = pw.FloatField()
class Program(Table):
code = pw.TextField()
language = pw.ForeignKeyField(Language)
author = pw.ForeignKeyField(User)
class Question(Table):
statement = pw.TextField()
solution = pw.ForeignKeyField(Program)
mem_limit = pw.IntegerField()
time_limit = pw.IntegerField()
class Contest(Table):
title = pw.CharField()
description = pw.TextField()
host = pw.ForeignKeyField(User)
start = pw.DateTimeField()
class Token(BaseModel):
"""Bearer Token.
A bearer token is the final token that could be used by the client.
There are other token types, but bearer token is widely used.
Flask-OAuthlib only comes with a bearer token.
"""
client = ForeignKeyField(Client, on_delete="CASCADE")
user = ForeignKeyField(User, null=True, on_delete="SET NULL")
token_type = CharField(max_length=40)
access_token = CharField(max_length=100, unique=True)
refresh_token = CharField(max_length=100, unique=True, null=True)
expires = DateTimeField(null=True)
_scopes = TextField(null=True)
@property
def scopes(self): # noqa: D102
if self._scopes:
return self._scopes.split()
return []
@property
def expires_at(self): # noqa: D102
return self.expires
def readup_file(input_file):
"""Read up the whole content and deconde it and return the whole content."""
raw = input_file.read()
for encoding in "utf-8-sig", "utf-8", "utf-16":
curve_key = TextField()
device = ForeignKeyField(
column_name="device_id",
field="device_id",
model=Accounts,
on_delete="CASCADE"
)
session = ByteField()
session_id = TextField(primary_key=True)
class Meta:
table_name = "olm_sessions"
class OutgoingKeyRequests(Model):
session_id = TextField()
device = ForeignKeyField(
Accounts,
on_delete="CASCADE",
backref="key_requests",
)
class SyncTokens(Model):
token = TextField()
device = ForeignKeyField(
model=Accounts,
primary_key=True,
on_delete="CASCADE"
)
upvotes = pw.IntegerField(constraints=[SQL("DEFAULT 0")])
downvotes = pw.IntegerField(constraints=[SQL("DEFAULT 0")])
sid = pw.ForeignKeyField(backref='subpost_set', column_name='sid', field='sid', model=migrator.orm['sub'], null=True)
thumbnail = pw.CharField(max_length=255, null=True)
title = pw.CharField(max_length=255, null=True)
comments = pw.IntegerField()
uid = pw.ForeignKeyField(backref='posts', column_name='uid', field='uid', model=migrator.orm['user'], null=True)
flair = pw.CharField(max_length=25, null=True)
class Meta:
table_name = "sub_post"
@migrator.create_model
class SubPostComment(pw.Model):
cid = pw.CharField(max_length=40, primary_key=True)
content = pw.TextField(null=True)
lastedit = pw.DateTimeField(null=True)
parentcid = pw.ForeignKeyField(backref='subpostcomment_set', column_name='parentcid', field='cid', model='self', null=True)
pid = pw.ForeignKeyField(backref='subpostcomment_set', column_name='pid', field='pid', model=migrator.orm['sub_post'], null=True)
score = pw.IntegerField(null=True)
upvotes = pw.IntegerField(constraints=[SQL("DEFAULT 0")])
downvotes = pw.IntegerField(constraints=[SQL("DEFAULT 0")])
status = pw.IntegerField(null=True)
time = pw.DateTimeField(null=True)
uid = pw.ForeignKeyField(backref='comments', column_name='uid', field='uid', model=migrator.orm['user'], null=True)
class Meta:
table_name = "sub_post_comment"
@migrator.create_model
class SubPostCommentReport(pw.Model):
id = pw.AutoField()
db_table = 'RnaQuantificationSet'
indexes = (
(('datasetid', 'name'), True),
)
class System(BaseModel):
key = pw.TextField(primary_key=True)
value = pw.TextField()
class Meta:
db_table = 'System'
class Variantannotationset(BaseModel):
analysis = pw.TextField(null=True)
annotationtype = pw.TextField(db_column='annotationType', null=True)
created = pw.TextField(null=True)
id = pw.TextField(primary_key=True)
name = pw.TextField()
ontologyid = pw.ForeignKeyField(
db_column='ontologyId', rel_model=Ontology, to_field='id')
updated = pw.TextField(null=True)
variantsetid = pw.ForeignKeyField(
db_column='variantSetId', rel_model=Variantset, to_field='id')
class Meta:
db_table = 'VariantAnnotationSet'
indexes = (
(('variantsetid', 'name'), True),
)
species = pw.TextField(db_column='species', null=True)
referencesetid = pw.ForeignKeyField(
db_column='referenceSetId', rel_model=Referenceset, to_field='id')
sourceaccessions = pw.TextField(db_column='sourceAccessions', null=True)
sourcedivergence = pw.FloatField(db_column='sourceDivergence', null=True)
sourceuri = pw.TextField(db_column='sourceUri', null=True)
class Meta:
db_table = 'Reference'
indexes = (
(('referencesetid', 'name'), True),
)
class Rnaquantificationset(BaseModel):
dataurl = pw.TextField(db_column='dataUrl')
datasetid = pw.ForeignKeyField(
db_column='datasetId', rel_model=Dataset, to_field='id')
id = pw.TextField(primary_key=True)
info = pw.TextField(null=True)
name = pw.TextField()
referencesetid = pw.ForeignKeyField(
db_column='referenceSetId', rel_model=Referenceset, to_field='id')
class Meta:
db_table = 'RnaQuantificationSet'
indexes = (
(('datasetid', 'name'), True),
)
class System(BaseModel):
class Study(BaseModel):
"""
A study is a scientific study with a PI and a description, and may include
one or more datasets.
"""
class Meta:
table_name = 'studies'
schema = 'data'
pi_name = CharField()
pi_email = CharField()
contact_name = CharField()
contact_email = CharField()
title = CharField()
description = TextField(column_name="study_description", null=True)
publication_date = DateTimeField()
ref_doi = CharField(null=True)
class Dataset(BaseModel):
"""
A dataset is part of a study, and usually include a certain population.
Most studies only have a single dataset, but multiple are allowed.
"""
class Meta:
table_name = 'datasets'
schema = 'data'
study = ForeignKeyField(Study, column_name="study", backref='datasets')
short_name = CharField()
ignored = peewee.ForeignKeyField(User, related_name='ignored_by')
ignored_by = peewee.ForeignKeyField(User, related_name='ignored')
class Meta:
indexes = (
(('ignored', 'ignored_by'), True),
)
class ListForMail(BaseModel):
user_id = peewee.BigIntegerField(unique=True)
date = peewee.DateTimeField(default=datetime.datetime.now())
class BotStatus(BaseModel):
last_top = peewee.TextField(default="")
mail_data = peewee.TextField(default="")
photos = peewee.IntegerField(default=0)
timestamp = peewee.IntegerField(default=time.time())
if database:
db = peewee_async.Manager(database)
User.create_table(True)
Ignore.create_table(True)
ListForMail.create_table(True)
BotStatus.create_table(True)
Role.create_table(True)
else:
r[k] = json.dumps(getattr(self, k), default=lambda o: o.to_json())
r['timestamp'] = r['timestamp'].strftime('%m/%d/%Y %H:%M:%S')
return r
def __str__(self):
return str(self.to_json())
# This has information about a specific command that can be executed by a PayloadType
# Custom commands can be created by users
# There will be a new Command instance for every cmd+payload_type combination
# (each payload_type needs its own 'shell' command because they might be implemented differently)
class Command(p.Model):
needs_admin = p.BooleanField(null=False, default=False)
# generates get-help info on the command
help_cmd = p.TextField(null=False, default="")
description = p.TextField(null=False)
cmd = p.CharField(null=False) # shell, for example, doesn't have to be a globally unique name
# this command applies to what payload types
payload_type = p.ForeignKeyField(PayloadType, null=False)
operator = p.ForeignKeyField(Operator, null=False)
creation_time = p.DateTimeField(null=False, default=datetime.datetime.utcnow)
version = p.IntegerField(null=False, default=1) # what version, so we can know if loaded commands are out of date
is_exit = p.BooleanField(null=False, default=False) # indicate if this command is the exit command for a payload type
class Meta:
indexes = ((('cmd', 'payload_type'), True),)
database = apfell_db
def to_json(self):
r = {}
for k in self._data.keys():
class Meta: # noqa: D101,D106
db_table = "user_organisation_affiliation"
table_alias = "oua"
class OrcidApiCall(BaseModel):
"""ORCID API call audit entry."""
called_at = DateTimeField(default=datetime.utcnow)
user = ForeignKeyField(User, null=True, on_delete="SET NULL")
method = TextField()
url = TextField()
query_params = TextField(null=True)
body = TextField(null=True)
put_code = IntegerField(null=True)
response = TextField(null=True)
response_time_ms = IntegerField(null=True)
class Meta: # noqa: D101,D106
db_table = "orcid_api_call"
table_alias = "oac"
class OrcidAuthorizeCall(BaseModel):
"""ORCID Authorize call audit entry."""
called_at = DateTimeField(default=datetime.utcnow)
user = ForeignKeyField(User, null=True, on_delete="SET NULL")
method = TextField(null=True)
url = TextField(null=True)
token = TextField(null=True)
state = TextField(null=True)