_paper.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from typing import List, Optional, Dict, Union, Any
  4. from pydantic import BaseModel, Field
  5. from schemas.base import ListMixin, DetailMixin, Str2List, Datetime2Str
  6. class PaperBaseItem(BaseModel):
  7. id: int
  8. name: str
  9. pno: str
  10. pages: int
  11. score: int
  12. uploaded: bool
  13. cut: bool
  14. attached: bool
  15. creator_name: str
  16. points: List[Any] = None
  17. created_at: Datetime2Str
  18. class Config:
  19. orm_mode = True
  20. class PaperList(ListMixin):
  21. data: List[PaperBaseItem] = []
  22. class PaperItem4Detail(PaperBaseItem):
  23. imgs: Str2List
  24. attach_url: str
  25. questions: Optional[List[Any]] = []
  26. class PaperDetail(DetailMixin):
  27. data: Union[Dict[str, Any], PaperItem4Detail] = None
  28. class NewPaperInfo(BaseModel):
  29. name: str = Field(..., min_length=1, max_length=255, description="试卷名称")
  30. pno: str = Field(..., min_length=1, max_length=32, description="试卷编号")
  31. pages: int = Field(..., gt=0, description="试卷页数")
  32. ctgid: int = Field(..., description="试卷分类ID")
  33. imgs: Optional[List[str]] = Field(None, description="试卷图片")
  34. attachments: Optional[List[str]] = Field(None, description="电子卷附件")
  35. class PaperInDB(BaseModel):
  36. category_id: int = Field(..., alias="ctgid")
  37. name: str
  38. pno: str
  39. pages: int
  40. imgs: str = ""
  41. uploaded: bool = False
  42. points: str = ""
  43. attach_url: str = ""
  44. attached: bool = False
  45. cut: bool = False
  46. score: int = 100
  47. creator_id: int
  48. creator_name: str
  49. editor_id: int
  50. editor_name: str
  51. class Config:
  52. anystr_strip_whitespace = True
  53. class UpdatePaperInfo(BaseModel):
  54. category_id: Optional[int] = Field(None, alias="ctgid")
  55. name: Optional[str] = None
  56. pages: Optional[int] = None
  57. imgs: Optional[List[str]] = None
  58. uploaded: Optional[bool] = None
  59. points: Optional[str] = None
  60. attachments: Optional[List[str]] = None
  61. attached: Optional[bool] = None
  62. cut: Optional[bool] = None
  63. score: Optional[int] = None
  64. class Config:
  65. anystr_strip_whitespace = True
  66. class UpdatePaper(UpdatePaperInfo):
  67. imgs: Optional[str] = None
  68. attach_url: Optional[str] = None
  69. editor_id: int
  70. editor_name: str
  71. class Config:
  72. anystr_strip_whitespace = True