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
|
||||
|
@@ -3,6 +3,7 @@ import typing as t
|
||||
|
||||
from load import bot, config
|
||||
|
||||
|
||||
async def download_file(file_path, *args, **kw) -> t.Union[io.BytesIO, t.Any]:
|
||||
if config.telegram_api_server == "https://api.telegram.org":
|
||||
return await bot.download_file(file_path, *args, **kw)
|
||||
|
@@ -2,4 +2,4 @@ from load import permissions as __permissions
|
||||
|
||||
from .model import Permission
|
||||
|
||||
permission = Permission(**__permissions)
|
||||
permission = Permission(**__permissions)
|
||||
|
@@ -1,5 +1,6 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class Permission(BaseModel):
|
||||
can_admin_add_admins: bool
|
||||
can_admin_del_admins: bool
|
||||
|
@@ -19,6 +19,9 @@ continue_ = "Продолжить"
|
||||
rewrite_data = "Ввести заново"
|
||||
load_data = "Загрузить данные"
|
||||
|
||||
#Operator
|
||||
on_work = "Активировать"
|
||||
leave_work = "Выключить"
|
||||
|
||||
#Admins \ Moder
|
||||
admin_panel = "Админ панель"
|
||||
|
@@ -2,22 +2,22 @@ import typing as t
|
||||
from abc import ABC
|
||||
|
||||
|
||||
class BaseUserFileds(ABC):
|
||||
class BaseUser(ABC):
|
||||
id: int
|
||||
first_name: str
|
||||
last_name: t.Union[str, None] = None
|
||||
username: t.Union[str, None] = None
|
||||
|
||||
|
||||
class User(BaseUserFileds):
|
||||
class User(BaseUser):
|
||||
|
||||
def __new__(self, **kw):
|
||||
def __new__(cls, **kw):
|
||||
if "user_id" in kw:
|
||||
self.id = kw["user_id"]
|
||||
cls.id = kw["user_id"]
|
||||
if "first_name" in kw:
|
||||
self.first_name = kw["first_name"]
|
||||
cls.first_name = kw["first_name"]
|
||||
if "last_name" in kw:
|
||||
self.last_name = kw["last_name"]
|
||||
cls.last_name = kw["last_name"]
|
||||
if "username" in kw:
|
||||
self.username = kw["username"]
|
||||
return self
|
||||
cls.username = kw["username"]
|
||||
return cls
|
||||
|
Reference in New Issue
Block a user