Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class Role(pw.Model):
name = pw.CharField(255, default='user')
class Meta:
database = database
class User(pw.Model):
created = pw.DateTimeField(default=dt.datetime.utcnow)
login = pw.CharField(255)
name = pw.CharField(255, null=True)
password = pw.CharField(127, null=True)
is_active = pw.BooleanField(default=True)
role = pw.ForeignKeyField(Role, null=True)
class Meta:
database = database
database.create_tables([User, Role], safe=True)
def test_resource(app, api, client):
from flask_restler.peewee import ModelResource
@api.route
class UserResouce(ModelResource):
class ProxyIP(BaseModel):
class Meta:
table_name = 'proxy_ips'
indexes = (
(('ip', 'port'), True),
)
ip = CharField()
port = IntegerField()
is_valid = BooleanField(default=False)
created_at = DateTimeField(default=datetime.datetime.now)
updated_at = DateTimeField(default=datetime.datetime.now)
latency = FloatField()
stability = FloatField()
is_anonymous = BooleanField(default=False)
is_https = BooleanField(default=False)
attempts = IntegerField(default=0)
https_attempts = IntegerField(default=0)
location = CharField(null=True)
organization = CharField(null=True)
region = CharField(null=True)
country = CharField(null=True)
city = CharField(null=True)
def assign_from(self, p):
self.ip = p.ip
self.port = p.port
self.is_valid = p.is_valid
self.latency = p.latency
self.stability = p.stability
self.is_anonymous = p.is_anonymous
given = pw.IntegerField(constraints=[SQL("DEFAULT 0")])
status = pw.IntegerField(constraints=[SQL("DEFAULT 0")])
resets = pw.IntegerField(constraints=[SQL("DEFAULT 0")])
class Meta:
table_name = "user"
@migrator.create_model
class APIToken(pw.Model):
id = pw.AutoField()
user = pw.ForeignKeyField(backref='apitoken_set', column_name='uid', field='uid', model=migrator.orm['user'])
token = pw.CharField(max_length=255, unique=True)
can_post = pw.BooleanField()
can_mod = pw.BooleanField()
can_message = pw.BooleanField()
can_upload = pw.BooleanField()
is_active = pw.BooleanField(constraints=[SQL("DEFAULT True")])
is_ip_restricted = pw.BooleanField(constraints=[SQL("DEFAULT False")])
class Meta:
table_name = "api_token"
@migrator.create_model
class APITokenSettings(pw.Model):
id = pw.AutoField()
token = pw.ForeignKeyField(backref='apitokensettings_set', column_name='token_id', field='id', model=migrator.orm['api_token'])
key = pw.CharField(max_length=255)
value = pw.CharField(max_length=255)
class Meta:
table_name = "api_token_settings"
# There are cases where an object has the same name but different paths.
# In that case, create_or_get will just make a new one.
name = peewee.CharField(null=True, max_length=128, index=True)
category = peewee.ForeignKeyField(Category)
# This can be null.
dataset = peewee.ForeignKeyField(Dataset, null=True)
num_vertices = peewee.IntegerField(null=True)
num_faces = peewee.IntegerField(null=True)
mesh_filename = peewee.TextField(null=True, unique=True)
class Camera(BaseModel):
position_xyz = Vec3Field()
up = Vec3Field()
lookat = Vec3Field()
is_orthographic = peewee.BooleanField(default=True)
fov = peewee.FloatField(null=True)
scale = peewee.FloatField(null=True) # Scale of the frustum's top, left, bottom, right parameters.
class RenderingType(BaseModel):
"""
rgb, normal, depth, voxels
"""
name = peewee.CharField(unique=True, max_length=128, index=True)
class ObjectRendering(BaseModel):
"""
Shape representation of an object with a reference camera.
"""
type = peewee.ForeignKeyField(RenderingType)
class UserIgnores(BaseModel):
uid = ForeignKeyField(db_column='uid', model=User, field='uid')
target = CharField(max_length=40)
date = DateTimeField(default=datetime.datetime.now)
def __repr__(self):
return f''
class Meta:
table_name = 'user_ignores'
class APIToken(BaseModel):
user = ForeignKeyField(db_column='uid', model=User, field='uid')
token = CharField(unique=True)
can_post = BooleanField()
can_mod = BooleanField()
can_message = BooleanField()
can_upload = BooleanField()
is_active = BooleanField(default=True)
is_ip_restricted = BooleanField(default=False)
def __repr__(self):
return f''
class Meta:
table_name = 'api_token'
class APITokenSettings(BaseModel):
""" API Token settings. Mainly used for IP whitelisting """
token = ForeignKeyField(model=APIToken, field='id')
uuid = peewee.CharField(default=uuid.uuid4())
def __repr__(self):
return "".format(**self._data)
class Meta:
db_table = 'history'
class Backups(SyncedModel):
"""Backups Model."""
backend = peewee.CharField(index=True)
backend_hash = peewee.CharField(index=True, null=True)
backup_date = peewee.IntegerField(index=True)
filename = peewee.TextField(index=True)
is_deleted = peewee.BooleanField()
last_updated = peewee.IntegerField()
metadata = JsonField()
size = peewee.IntegerField()
stored_filename = peewee.TextField(index=True, unique=True)
tags = peewee.CharField()
@classmethod
def match_filename(cls, filename, destination, **kwargs):
conf = config
if kwargs.get("config"):
conf = load_config(kwargs.get("config"))
profile = conf.get(kwargs.get("profile", "default"))
s3_key = hashlib.sha512(profile.get("access_key") +
profile.get("s3_bucket")).hexdigest()
class PlayerRoom(BaseModel):
player = ForeignKeyField(User, backref="rooms_joined", on_delete="CASCADE")
room = ForeignKeyField(Room, backref="players", on_delete="CASCADE")
def __repr__(self):
return f""
class Location(BaseModel):
room = ForeignKeyField(Room, backref="locations", on_delete="CASCADE")
name = TextField()
unit_size = FloatField(default=5)
use_grid = BooleanField(default=True)
full_fow = BooleanField(default=False)
fow_opacity = FloatField(default=0.3)
fow_los = BooleanField(default=False)
vision_mode = TextField(default="triangle")
# default is 1km max, 0.5km min
vision_min_range = FloatField(default=1640)
vision_max_range = FloatField(default=3281)
def __repr__(self):
return f""
def get_path(self):
return f"{self.room.get_path()}/{self.name}"
def as_dict(self):
return model_to_dict(self, recurse=False, exclude=[Location.id, Location.room])
class Meta:
database = database
class Role(BaseModel):
user_id = peewee.BigIntegerField()
role = peewee.TextField()
# blacklisted - юзер забанен
# whitelisted - юзер находится в белом списке
# admin - юзер является админом
class User(BaseModel):
uid = peewee.BigIntegerField(primary_key=True, unique=True)
message_date = peewee.BigIntegerField(default=0)
in_group = peewee.BooleanField(default=False)
do_not_disturb = peewee.BooleanField(default=False)
memory = peewee.TextField(default="")
chat_data = peewee.TextField(default="")
class Ignore(BaseModel):
ignored = peewee.ForeignKeyField(User, related_name='ignored_by')
ignored_by = peewee.ForeignKeyField(User, related_name='ignored')
class Meta:
indexes = (
(('ignored', 'ignored_by'), True),
)
class Gallery(BaseModel):
job = ForeignKeyField(Job)
name = CharField()
query = CharField()
target = CharField()
picture = CharField()
class Session(BaseModel):
s_id = CharField(max_length=20, unique=True)
date_created = DateTimeField()
upload_folder = CharField(max_length=20)
last_ping = DateTimeField()
status = CharField(default="reset")
keep_active = BooleanField(default=False) # Uploads made by the server must be keep active
@classmethod
def new(cls, keep_active=False):
from dgenies.lib.functions import Functions
my_s_id = Functions.random_string(20)
while len(cls.select().where(cls.s_id == my_s_id)) > 0:
my_s_id = Functions.random_string(20)
upload_folder = Functions.random_string(20)
tmp_dir = config.upload_folder
upload_folder_path = os.path.join(tmp_dir, upload_folder)
while os.path.exists(upload_folder_path):
upload_folder = Functions.random_string(20)
upload_folder_path = os.path.join(tmp_dir, upload_folder)
cls.create(s_id=my_s_id, date_created=datetime.now(), upload_folder=upload_folder, last_ping=datetime.now(),
keep_active=keep_active)
return my_s_id