39 lines
838 B
Python
39 lines
838 B
Python
import datetime
|
|
from dataclasses import dataclass
|
|
from typing import Optional
|
|
|
|
import marshmallow_dataclass
|
|
from marshmallow import EXCLUDE, pre_load
|
|
|
|
|
|
@dataclass
|
|
class User:
|
|
chat_id: int
|
|
name: Optional[str] = None
|
|
group: Optional[str] = None
|
|
hse_id: Optional[int] = None
|
|
state: str = "new"
|
|
notify_minutes: Optional[int] = 10
|
|
daily_notify_time: Optional[str] = None
|
|
next_daily_notify_time: Optional[datetime.datetime] = None
|
|
|
|
class Meta:
|
|
unknown = EXCLUDE
|
|
|
|
|
|
@dataclass
|
|
class Lesson:
|
|
hse_id: int
|
|
|
|
|
|
USchema = marshmallow_dataclass.class_schema(User)
|
|
|
|
|
|
class UserSchema(USchema):
|
|
|
|
@pre_load
|
|
def stringify_time(self, data, many, **kwargs):
|
|
if 'next_daily_notify_time' in data:
|
|
data['next_daily_notify_time'] = str(data['next_daily_notify_time'])
|
|
return data
|