resource.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import datetime
  4. from sqlalchemy import Column, Integer, String, BOOLEAN, DateTime, SmallInteger, UniqueConstraint,TEXT
  5. from db import BaseORMModel
  6. class WorkCategory(BaseORMModel):
  7. """作业资源分类
  8. """
  9. __tablename__ = "work_categories"
  10. id = Column(Integer, primary_key=True, autoincrement=True)
  11. name = Column(String(64), nullable=False, comment="分类名称")
  12. pid = Column(Integer, default=0, comment="上级分类ID")
  13. pname = Column(String(64), default="", comment="上级分类名称")
  14. period = Column(String(20), nullable=False, comment="学段")
  15. subject = Column(String(20), nullable=False, comment="学科")
  16. __table_args__ = (UniqueConstraint("name",
  17. "pid",
  18. "subject",
  19. "period",
  20. name="uix_work_name_pid_subject_period"),)
  21. class WorkResource(BaseORMModel):
  22. """作业资源
  23. """
  24. __tablename__ = "work_resources"
  25. id = Column(Integer, primary_key=True, autoincrement=True)
  26. category_id = Column(Integer, nullable=False, comment="资源分类id")
  27. category_name = Column(String(64), nullable=False, comment="分类名称")
  28. name = Column(String(255), nullable=False, comment="资源名称")
  29. subject = Column(String(10), nullable=False, comment="所属科目")
  30. area = Column(String(20), nullable=False, comment="地区")
  31. year = Column(String(20), nullable=False, comment="年份")
  32. visit = Column(Integer, default=0, comment="浏览量")
  33. collect = Column(Integer, default=0, comment="收藏量")
  34. download = Column(Integer, default=0, comment="下载量")
  35. rtype = Column(String(16), default="", comment="资源类型")
  36. hot = Column(BOOLEAN(), default=False, comment="是否热点资源")
  37. attach_url = Column(String(1000), default="", comment="资源附件")
  38. creator_id = Column(Integer, nullable=False, comment="创建人ID")
  39. creator_name = Column(String(32), nullable=False, comment="创建人名称")
  40. created_at = Column(DateTime, default=datetime.datetime.now)
  41. editor_id = Column(Integer, nullable=False, comment="最后编辑人ID")
  42. editor_name = Column(String(32), nullable=False, comment="最后编辑人名称")
  43. updated_at = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now)
  44. class ExamCategory(BaseORMModel):
  45. """考试资源分类
  46. """
  47. __tablename__ = "exam_categories"
  48. id = Column(Integer, primary_key=True, autoincrement=True)
  49. name = Column(String(64), nullable=False, comment="用户名")
  50. pid = Column(Integer, default=0, comment="上级分类ID")
  51. pname = Column(String(64), default="", comment="上级名称")
  52. period = Column(String(20), nullable=False, comment="学段")
  53. subject = Column(String(20), nullable=False, comment="学科")
  54. __table_args__ = (UniqueConstraint("name",
  55. "pid",
  56. "subject",
  57. "period",
  58. name="uix_exam_name_pid_subject_period"),)
  59. class ExamResource(BaseORMModel):
  60. """考试资源
  61. """
  62. __tablename__ = "exam_resources"
  63. id = Column(Integer, primary_key=True, autoincrement=True)
  64. category_id = Column(Integer, nullable=False, comment="资源分类id")
  65. category_name = Column(String(64), nullable=False, comment="分类名称")
  66. name = Column(String(255), nullable=False, comment="资源名称")
  67. subject = Column(String(10), nullable=False, comment="所属科目")
  68. area = Column(String(20), nullable=False, comment="地区")
  69. year = Column(String(20), nullable=False, comment="年份")
  70. visit = Column(Integer, default=0, comment="浏览量")
  71. collect = Column(Integer, default=0, comment="收藏量")
  72. download = Column(Integer, default=0, comment="下载量")
  73. attach_url = Column(String(1000), default="", comment="资源附件")
  74. school_id = Column(Integer, nullable=False, comment="学校ID")
  75. school_name = Column(String(64), nullable=False, comment="学校名称")
  76. hot = Column(BOOLEAN(), default=False)
  77. creator_id = Column(Integer, nullable=False, comment="创建人ID")
  78. creator_name = Column(String(32), nullable=False, comment="创建人名称")
  79. created_at = Column(DateTime, default=datetime.datetime.now)
  80. editor_id = Column(Integer, nullable=False, comment="最后编辑人ID")
  81. editor_name = Column(String(32), nullable=False, comment="最后编辑人名称")
  82. updated_at = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now)
  83. # 资源收藏表
  84. class ResourceCollectInfo(BaseORMModel):
  85. id = Column(Integer, primary_key=True, autoincrement=True)
  86. ctype = Column(String(4), nullable=False, comment="资源分类")
  87. rid = Column(Integer, nullable=False, comment="资源ID")
  88. uid = Column(Integer, nullable=False, comment="用户ID")
  89. utype = Column(SmallInteger, nullable=False, comment="用户类型,1:教师,2:学生")
  90. created_at = Column(DateTime, default=datetime.datetime.now)
  91. __tablename__ = "resource_collect_info"
  92. __table_args__ = (UniqueConstraint("uid",
  93. "utype",
  94. "rid",
  95. "ctype",
  96. name="uix_collect_uid_utype_rid_ctype"),)
  97. class ResourceQuestions(BaseORMModel):
  98. """
  99. """
  100. id = Column(Integer, primary_key=True, autoincrement=True)
  101. rid = Column(Integer, nullable=False, comment="资源ID")
  102. rtype = Column(String(4), nullable=False,default="work",comment="资源类型,work/exam")
  103. qno = Column(String(32), nullable=False, comment="题号")
  104. qtype = Column(String(6), default="", comment="单选题/多选题/判断题/主观题")
  105. answer = Column(String(200), default="", comment="标准答案")
  106. analysis = Column(TEXT, default="", comment="答案解析")
  107. level = Column(String(50), default="", comment="难度,简单/中等/困难")
  108. lpoints = Column(String(1000), default="", comment="知识点")
  109. stem = Column(TEXT, default="", comment="试题题干")
  110. __tablename__ = "resource_questions"
  111. CATEGORY_MODES = {"work": WorkCategory, "exam": ExamCategory}
  112. RESOURCE_MODES = {"work": WorkResource, "exam": ExamResource}