school.py 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from typing import List, Optional, Union
  4. from pydantic import Field
  5. from pydantic.main import BaseModel
  6. from schemas.base import ListMixin, DetailMixin, Datetime2Str
  7. class SchoolItem(BaseModel):
  8. id: Optional[int] = None
  9. name: Optional[str] = None
  10. area: Optional[Union[str, List[str]]] = None
  11. category: Optional[int] = None
  12. contact_name: Optional[str] = None
  13. contact_phone: Optional[str] = None
  14. created_at: Datetime2Str = None
  15. class Config:
  16. orm_mode = True
  17. class SchoolItemList(ListMixin):
  18. data: List[SchoolItem] = []
  19. class NewSchoolInfo(BaseModel):
  20. category: int = Field(..., description="学制")
  21. name: str = Field(..., max_length=100, description="学校名称")
  22. area_code: List[str] = Field(...,
  23. alias="area",
  24. min_items=3,
  25. max_items=3,
  26. description="区域code,逗号分隔,顺序:省市区")
  27. contact_name: str = Field(..., max_length=20, description="联系人姓名")
  28. contact_phone: str = Field(..., max_length=20, description="联系人电话")
  29. class Config:
  30. anystr_strip_whitespace = True
  31. class SchoolInDB(NewSchoolInfo):
  32. area_code: str = Field(..., description="区域code,逗号分隔,顺序:省市区")
  33. area_name: str = Field(..., description="区域名称,逗号分隔,顺序:省市区")
  34. creator_id: int = Field(..., description="创建人ID")
  35. creator_name: str = Field(..., description="创建人姓名")
  36. editor_id: int = Field(..., description="最后编辑人ID")
  37. editor_name: str = Field(..., description="最后编辑人姓名")
  38. class UpdateSchool(BaseModel):
  39. category: Optional[int] = Field(None, description="学制")
  40. area_code: Optional[Union[str, List[str]]] = Field(
  41. None, alias="area", description="区域code,逗号分隔,顺序:省市区")
  42. area_name: Optional[str] = Field(None, description="区域名称,后端处理,前端忽略")
  43. contact_name: Optional[str] = Field(None,
  44. max_length=20,
  45. description="联系人姓名")
  46. contact_phone: Optional[str] = Field(None,
  47. max_length=20,
  48. description="联系人电话")
  49. editor_id: Optional[int] = Field(None, description="最后编辑人ID,后端处理,前端忽略")
  50. editor_name: Optional[int] = Field(None, description="最后编辑人姓名,后端处理,前端忽略")
  51. class Config:
  52. anystr_strip_whitespace = True
  53. class SchoolDetail(DetailMixin):
  54. data: Optional[SchoolItem] = None
  55. class NewGrade(BaseModel):
  56. name: str = Field(..., description="年级名称")
  57. school_id: int = Field(..., alias="sid", description="年级ID")
  58. teacher_amount: int = Field(0, alias="teacher", description="教师数量")
  59. student_amount: int = Field(0, alias="student", description="学生数量")
  60. class Config:
  61. anystr_strip_whitespace = True
  62. class UpdateGrade(BaseModel):
  63. teacher_amount: Optional[int] = Field(None,
  64. alias="teacher",
  65. description="教师数量")
  66. student_amount: Optional[int] = Field(None,
  67. alias="student",
  68. description="学生数量")
  69. class Config:
  70. anystr_strip_whitespace = True
  71. class GradeItem(BaseModel):
  72. id: int
  73. name: str
  74. class Config:
  75. orm_mode = True
  76. class GradeItemList(ListMixin):
  77. data: List[GradeItem] = []
  78. class GradeDetail(DetailMixin):
  79. data: Optional[GradeItem] = None
  80. class SchoolClassItem(BaseModel):
  81. id: int = Field(description="班级ID")
  82. name: str = Field(description="班级名称")
  83. school_id: int = Field(description="学校ID")
  84. school_name: str = Field(description="学校名称")
  85. grade_id: int = Field(description="年级ID")
  86. grade_name: str = Field(description="年纪名称")
  87. teacher_amount: int = Field(description="教师数量")
  88. student_amount: int = Field(description="学生数量")
  89. created_at: Datetime2Str = Field(description="创建时间")
  90. class Config:
  91. orm_mode = True
  92. class SchoolClassList(ListMixin):
  93. data: List[SchoolClassItem] = []
  94. class NewClassInfo(BaseModel):
  95. name: str = Field(None, description="班级名称")
  96. school_id: int = Field(..., alias="sid", description="学校ID")
  97. grade_id: int = Field(..., alias="gid", description="年级ID")
  98. teacher_amount: Optional[int] = Field(None,
  99. alias="teacher",
  100. description="教师数量")
  101. student_amount: Optional[int] = Field(None,
  102. alias="student",
  103. description="学生数量")
  104. amount: Optional[int] = Field(None, description="班级数量,快速建班时使用")
  105. class Config:
  106. anystr_strip_whitespace = True
  107. class ClassInDB(BaseModel):
  108. name: str = Field(..., max_length=20)
  109. school_id: int
  110. school_name: str = Field(..., max_length=100)
  111. grade_id: int
  112. grade_name: str = Field(..., max_length=20)
  113. teacher_amount: int = 0
  114. student_amount: int = 0
  115. creator_id: int
  116. creator_name: str
  117. editor_id: int
  118. editor_name: str
  119. class SchoolClassDetail(DetailMixin):
  120. data: Union[SchoolClassItem, int] = None
  121. class UpdateClass(BaseModel):
  122. school_id: Optional[int] = Field(None, alias="sid", description="学校ID")
  123. grade_id: Optional[int] = Field(None, alias="gid", description="年级ID")
  124. teacher_amount: Optional[int] = Field(None,
  125. alias="teacher",
  126. description="教师数量")
  127. student_amount: Optional[int] = Field(None,
  128. alias="student",
  129. description="学生数量")
  130. school_name: str = Field(None, description="学校名称,后端处理,前端忽略")
  131. grade_name: str = Field(None, description="年级名称,后端处理,前端忽略")
  132. editor_id: int = Field(None, description="最后编辑人ID,后端处理,前端忽略")
  133. editor_name: str = Field(None, description="最后编辑人姓名,后端处理,前端忽略")
  134. class Config:
  135. anystr_strip_whitespace = True
  136. class SubjectItem(BaseModel):
  137. id: Optional[int] = None
  138. name: Optional[str] = None
  139. class SubjectList(ListMixin):
  140. data: List[SubjectItem] = []
  141. class PeriodItem(BaseModel):
  142. id: Optional[int] = None
  143. name: Optional[str] = None
  144. class PeriodList(ListMixin):
  145. data: List[PeriodItem] = []
  146. class SchoolSystemItem(BaseModel):
  147. id: Optional[int] = None
  148. name: Optional[str] = None
  149. class Config:
  150. orm_mode = True
  151. class SchoolSystemList(ListMixin):
  152. data: List[SchoolSystemItem] = []
  153. class YearsItem(BaseModel):
  154. id: Optional[int] = None
  155. name: Optional[str] = None
  156. class YearsList(ListMixin):
  157. data: List[YearsItem] = []