mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Update get_*_column functions
Use getattr instead of model_to_dict in single columns. We might want to change the functions later on so peewee's ForeignKeyField primary key shorthand like model.server_id instead of model.server.server_id will work. This will very likely increase performance of the get_*_column functions due to not having to call the model_to_dict function from Peewee's helper library.
This commit is contained in:
parent
48948423c9
commit
1b059b24df
@ -66,10 +66,9 @@ class HelperRoles:
|
||||
@staticmethod
|
||||
def get_role_column(role_id: t.Union[str, int], column_name: str) -> t.Any:
|
||||
column = getattr(Roles, column_name)
|
||||
return model_to_dict(
|
||||
Roles.select(column).where(Roles.role_id == role_id).get(),
|
||||
only=[column],
|
||||
)[column_name]
|
||||
return getattr(
|
||||
Roles.select(column).where(Roles.role_id == role_id).get(), column_name
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def add_role(role_name):
|
||||
|
@ -144,10 +144,10 @@ class HelperServers:
|
||||
@staticmethod
|
||||
def get_server_column(server_id: t.Union[str, int], column_name: str) -> t.Any:
|
||||
column = getattr(Servers, column_name)
|
||||
return model_to_dict(
|
||||
return getattr(
|
||||
Servers.select(column).where(Servers.server_id == server_id).get(),
|
||||
only=[column],
|
||||
)[column_name]
|
||||
column_name,
|
||||
)
|
||||
|
||||
# **********************************************************************************
|
||||
# Servers Methods
|
||||
|
@ -165,19 +165,10 @@ class HelperUsers:
|
||||
@staticmethod
|
||||
def get_user_column(user_id: t.Union[str, int], column_name: str) -> t.Any:
|
||||
column = getattr(Users, column_name)
|
||||
return model_to_dict(
|
||||
return getattr(
|
||||
Users.select(column).where(Users.user_id == user_id).get(),
|
||||
only=[column],
|
||||
)[column_name]
|
||||
|
||||
@staticmethod
|
||||
def check_system_user(user_id):
|
||||
try:
|
||||
result = Users.get(Users.user_id == user_id).user_id == user_id
|
||||
if result:
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
column_name,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_user_model(user_id: str) -> Users:
|
||||
|
Loading…
Reference in New Issue
Block a user