#!/usr/bin/env python # -*- coding: utf-8 -*- from typing import List, Optional, Union from pydantic import Field from pydantic.main import BaseModel from schemas.base import ListMixin, DetailMixin, Datetime2Str class SchoolItem(BaseModel): id: Optional[int] = None name: Optional[str] = None area: Optional[Union[str, List[str]]] = None category: Optional[int] = None contact_name: Optional[str] = None contact_phone: Optional[str] = None created_at: Datetime2Str = None class Config: orm_mode = True class SchoolItemList(ListMixin): data: List[SchoolItem] = [] class NewSchoolInfo(BaseModel): category: int = Field(..., description="学制") name: str = Field(..., max_length=100, description="学校名称") area_code: List[str] = Field(..., alias="area", min_items=3, max_items=3, description="区域code,逗号分隔,顺序:省市区") contact_name: str = Field(..., max_length=20, description="联系人姓名") contact_phone: str = Field(..., max_length=20, description="联系人电话") class Config: anystr_strip_whitespace = True class SchoolInDB(NewSchoolInfo): area_code: str = Field(..., description="区域code,逗号分隔,顺序:省市区") area_name: str = Field(..., description="区域名称,逗号分隔,顺序:省市区") creator_id: int = Field(..., description="创建人ID") creator_name: str = Field(..., description="创建人姓名") editor_id: int = Field(..., description="最后编辑人ID") editor_name: str = Field(..., description="最后编辑人姓名") class UpdateSchool(BaseModel): category: Optional[int] = Field(None, description="学制") area_code: Optional[Union[str, List[str]]] = Field( None, alias="area", description="区域code,逗号分隔,顺序:省市区") area_name: Optional[str] = Field(None, description="区域名称,后端处理,前端忽略") contact_name: Optional[str] = Field(None, max_length=20, description="联系人姓名") contact_phone: Optional[str] = Field(None, max_length=20, description="联系人电话") editor_id: Optional[int] = Field(None, description="最后编辑人ID,后端处理,前端忽略") editor_name: Optional[int] = Field(None, description="最后编辑人姓名,后端处理,前端忽略") class Config: anystr_strip_whitespace = True class SchoolDetail(DetailMixin): data: Optional[SchoolItem] = None class NewGrade(BaseModel): name: str = Field(..., description="年级名称") school_id: int = Field(..., alias="sid", description="年级ID") teacher_amount: int = Field(0, alias="teacher", description="教师数量") student_amount: int = Field(0, alias="student", description="学生数量") class Config: anystr_strip_whitespace = True class UpdateGrade(BaseModel): teacher_amount: Optional[int] = Field(None, alias="teacher", description="教师数量") student_amount: Optional[int] = Field(None, alias="student", description="学生数量") class Config: anystr_strip_whitespace = True class GradeItem(BaseModel): id: int name: str class Config: orm_mode = True class GradeItemList(ListMixin): data: List[GradeItem] = [] class GradeDetail(DetailMixin): data: Optional[GradeItem] = None class SchoolClassItem(BaseModel): id: int = Field(description="班级ID") name: str = Field(description="班级名称") school_id: int = Field(description="学校ID") school_name: str = Field(description="学校名称") grade_id: int = Field(description="年级ID") grade_name: str = Field(description="年纪名称") teacher_amount: int = Field(description="教师数量") student_amount: int = Field(description="学生数量") created_at: Datetime2Str = Field(description="创建时间") class Config: orm_mode = True class SchoolClassList(ListMixin): data: List[SchoolClassItem] = [] class NewClassInfo(BaseModel): name: str = Field(None, description="班级名称") school_id: int = Field(..., alias="sid", description="学校ID") grade_id: int = Field(..., alias="gid", description="年级ID") teacher_amount: Optional[int] = Field(None, alias="teacher", description="教师数量") student_amount: Optional[int] = Field(None, alias="student", description="学生数量") amount: Optional[int] = Field(None, description="班级数量,快速建班时使用") class Config: anystr_strip_whitespace = True class ClassInDB(BaseModel): name: str = Field(..., max_length=20) school_id: int school_name: str = Field(..., max_length=100) grade_id: int grade_name: str = Field(..., max_length=20) teacher_amount: int = 0 student_amount: int = 0 creator_id: int creator_name: str editor_id: int editor_name: str class SchoolClassDetail(DetailMixin): data: Union[SchoolClassItem, int] = None class UpdateClass(BaseModel): school_id: Optional[int] = Field(None, alias="sid", description="学校ID") grade_id: Optional[int] = Field(None, alias="gid", description="年级ID") teacher_amount: Optional[int] = Field(None, alias="teacher", description="教师数量") student_amount: Optional[int] = Field(None, alias="student", description="学生数量") school_name: str = Field(None, description="学校名称,后端处理,前端忽略") grade_name: str = Field(None, description="年级名称,后端处理,前端忽略") editor_id: int = Field(None, description="最后编辑人ID,后端处理,前端忽略") editor_name: str = Field(None, description="最后编辑人姓名,后端处理,前端忽略") class Config: anystr_strip_whitespace = True class SubjectItem(BaseModel): id: Optional[int] = None name: Optional[str] = None class SubjectList(ListMixin): data: List[SubjectItem] = [] class PeriodItem(BaseModel): id: Optional[int] = None name: Optional[str] = None class PeriodList(ListMixin): data: List[PeriodItem] = [] class SchoolSystemItem(BaseModel): id: Optional[int] = None name: Optional[str] = None class Config: orm_mode = True class SchoolSystemList(ListMixin): data: List[SchoolSystemItem] = [] class YearsItem(BaseModel): id: Optional[int] = None name: Optional[str] = None class YearsList(ListMixin): data: List[YearsItem] = []