PEP
This commit is contained in:
@@ -14,6 +14,7 @@ def get_operator():
|
||||
users.append(i.user_id)
|
||||
return users
|
||||
|
||||
|
||||
def get_full_admin():
|
||||
usr = []
|
||||
for i in Admin.select():
|
||||
@@ -28,3 +29,10 @@ def get_full_admin():
|
||||
|
||||
def del_admin(user_id:int):
|
||||
Admin.delete().where(Admin.user_id == user_id).execute()
|
||||
|
||||
|
||||
def get_active_operator():
|
||||
usr = []
|
||||
for i in Operator.select().where(Operator.active==True):
|
||||
usr.append(i.user_id)
|
||||
return usr
|
||||
|
@@ -16,6 +16,7 @@ def del_from_cart(user_id: int, item_id: int):
|
||||
def clean_cart(user_id: int):
|
||||
Cart.delete().where(Cart.user_id==user_id).execute()
|
||||
|
||||
|
||||
def get_user_cart(user_id:int):
|
||||
cart = []
|
||||
for i in Cart.select().where(Cart.user_id == user_id):
|
||||
|
@@ -1,10 +1,9 @@
|
||||
from ast import Mod
|
||||
import typing as t
|
||||
|
||||
from .model import Catalog as Model
|
||||
|
||||
|
||||
class Catalog():
|
||||
class Catalog:
|
||||
@staticmethod
|
||||
def __get_item(item_id: int) -> dict:
|
||||
item = {}
|
||||
@@ -23,17 +22,16 @@ class Catalog():
|
||||
return item
|
||||
|
||||
@classmethod
|
||||
def get_catalog(self, item_id:int = None, get_count:bool = False) -> t.Union[list, dict]:
|
||||
def get_catalog(cls, item_id:int = None, get_count:bool = False) -> t.Union[list, dict]:
|
||||
if item_id:
|
||||
if get_count:
|
||||
return self.__get_item(item_id), Model.select().count()
|
||||
return self.__get_item(item_id)
|
||||
return cls.__get_item(item_id), Model.select().count()
|
||||
return cls.__get_item(item_id)
|
||||
|
||||
items = []
|
||||
for i in Model.select():
|
||||
items.append(self.__get_item(i.id))
|
||||
items.append(cls.__get_item(i.id))
|
||||
return items
|
||||
|
||||
|
||||
@staticmethod
|
||||
def delete_post(item_id: int):
|
||||
|
@@ -1,11 +1,11 @@
|
||||
from peewee import (Model, BigIntegerField, TextField, BlobField,
|
||||
IntegerField, CharField, FloatField, ForeignKeyField)
|
||||
IntegerField, CharField, FloatField, BooleanField)
|
||||
|
||||
from load import db
|
||||
|
||||
|
||||
class BaseModel(Model):
|
||||
'''Base model. Abstract Class'''
|
||||
"""Base model. Abstract Class"""
|
||||
class Meta:
|
||||
database = db
|
||||
|
||||
@@ -22,7 +22,7 @@ class Admin(User):
|
||||
|
||||
|
||||
class Operator(User):
|
||||
pass
|
||||
active = BooleanField(default=False)
|
||||
|
||||
|
||||
class Catalog(BaseModel):
|
||||
@@ -45,4 +45,5 @@ class UserInfo(BaseModel):
|
||||
phone_number = CharField(15)
|
||||
address = TextField()
|
||||
|
||||
|
||||
db.create_tables([Cart, Catalog, Operator, Admin, User, UserInfo])
|
||||
|
@@ -10,6 +10,7 @@ def save_info(user_id: int, last_name:str, first_name:str, phone_number:str, add
|
||||
address=address
|
||||
).on_conflict_replace().execute()
|
||||
|
||||
|
||||
def get_info(user_id: int):
|
||||
output = None
|
||||
if UserInfo.select().where(UserInfo.user_id == user_id).exists():
|
||||
|
@@ -9,7 +9,7 @@ from utils import types
|
||||
class Register:
|
||||
|
||||
@classmethod
|
||||
def __register_user(self, model: Model, user: UserType):
|
||||
def __register_user(cls, model: Model, user: UserType):
|
||||
model.insert(
|
||||
user_id=user.id,
|
||||
first_name=user.first_name,
|
||||
@@ -18,16 +18,16 @@ class Register:
|
||||
).on_conflict_replace().execute()
|
||||
|
||||
@classmethod
|
||||
def register_user(self, user: UserType):
|
||||
return self.__register_user(UserModel, user)
|
||||
def register_user(cls, user: UserType):
|
||||
return cls.__register_user(UserModel, user)
|
||||
|
||||
@classmethod
|
||||
def register_admin(self, user: UserType):
|
||||
return self.__register_user(Admin, user)
|
||||
def register_admin(cls, user: UserType):
|
||||
return cls.__register_user(Admin, user)
|
||||
|
||||
@classmethod
|
||||
def register_operator(self, user: UserType):
|
||||
return self.__register_user(Operator, user)
|
||||
def register_operator(cls, user: UserType):
|
||||
return cls.__register_user(Operator, user)
|
||||
|
||||
|
||||
class User:
|
||||
@@ -43,3 +43,15 @@ class User:
|
||||
last_name=data.last_name,
|
||||
username=data.username
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_state(user_id:int):
|
||||
if Operator.select().where(Operator.user_id == user_id).exists():
|
||||
return Operator.get(Operator.user_id == user_id).active
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def set_state(user_id:int, state:bool=False):
|
||||
if Operator.select().where(Operator.user_id == user_id).exists():
|
||||
Operator.update(active=state).where(Operator.user_id == user_id).execute()
|
||||
return None
|
||||
|
Reference in New Issue
Block a user