teacher.py 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from typing import List, Optional, Union, Any, Dict
  4. from pydantic import BaseModel, Field
  5. from schemas.base import Datetime2Str, ListMixin, DetailMixin
  6. class TeacherItem(BaseModel):
  7. id: int
  8. name: str
  9. sex: Optional[int] = None
  10. age: Optional[int] = None
  11. phone: Optional[str] = None
  12. school_id: Optional[int] = None
  13. school_name: Optional[str] = None
  14. grade_id: Optional[int] = None
  15. grade_name: Optional[str] = None
  16. class_id: Optional[int] = None
  17. class_name: Optional[str] = None
  18. role_id: Optional[int] = None
  19. role_name: Optional[str] = None
  20. subject_id: Optional[int] = None
  21. subject: Optional[str] = None
  22. created_at: Optional[Datetime2Str] = None
  23. class Config:
  24. orm_mode = True
  25. class TeacherList(ListMixin):
  26. data: List[TeacherItem] = []
  27. class TeacherDetail(DetailMixin):
  28. data: Union[Dict[str, Any], TeacherItem] = None
  29. class NewTeacher(BaseModel):
  30. name: str = Field(..., max_lenght=20, description="教师名称")
  31. sex: int = Field(0, ge=0, le=1, description="性别, 0:女,1:男")
  32. age: int = Field(0, description="年龄")
  33. phone: str = Field(..., max_length=11, description="手机号")
  34. school_id: int = Field(..., alias="sid", description="学校ID")
  35. grade_id: int = Field(..., alias="gid", description="年级ID")
  36. class_id: str = Field(..., alias="cid", description="班级ID,用逗号分隔")
  37. role_id: int = Field(..., alias="rid", description="职务ID")
  38. subject: str = Field(..., max_length=10, alias="sub", description="任教学科")
  39. class Config:
  40. anystr_strip_whitespace = True
  41. class TeacherInDB(NewTeacher):
  42. role_name: str = Field(..., description="角色名称,前端忽略,后端处理")
  43. class_name: str = Field(..., description="班级名称,前端忽略,后端处理")
  44. grade_name: str = Field(..., description="年级名称,前端忽略,后端处理")
  45. school_name: str = Field(..., description="学校名称,前端忽略,后端处理")
  46. username: str = Field(..., description="用户名")
  47. password: str = Field(..., max_length=64, description="密码")
  48. creator_id: int = Field(..., description="创建人ID")
  49. creator_name: str = Field(..., description="创建人姓名")
  50. editor_id: int = Field(..., description="最后编辑人ID")
  51. editor_name: str = Field(..., description="最后编辑人姓名")
  52. class UpdateTeacher(BaseModel):
  53. username: Optional[str] = Field(None, max_length=11, description="用户名")
  54. name: Optional[str] = Field(None, max_lenght=20, description="教师名称")
  55. sex: Optional[int] = Field(None, ge=0, le=1, description="性别, 0:女,1:男")
  56. age: Optional[int] = Field(None, description="年龄")
  57. phone: Optional[str] = Field(None, max_length=11, description="手机号")
  58. school_id: Optional[int] = Field(None, alias="sid", description="学校ID")
  59. school_name: Optional[str] = Field(None, description="学校名称,前端忽略,后端处理")
  60. grade_id: Optional[int] = Field(None, alias="gid", description="年级ID")
  61. grade_name: Optional[str] = Field(None, description="年级名称,前端忽略,后端处理")
  62. class_id: Optional[str] = Field(None, alias="cid", description="班级ID")
  63. class_name: Optional[str] = Field(None, description="班级名称,前端忽略,后端处理")
  64. role_id: Optional[int] = Field(None, alias="rid", description="职务ID")
  65. role_name: Optional[str] = Field(None, description="角色名称,前端忽略,后端处理")
  66. subject: Optional[str] = Field(None,
  67. max_length=10,
  68. alias="sub",
  69. description="任教学科")
  70. editor_id: int = Field(None, description="最后编辑人ID,后端戳i,前端忽略")
  71. editor_name: str = Field(None, description="最后编辑人姓名,后端戳i,前端忽略")
  72. class Config:
  73. anystr_strip_whitespace = True