Main.py:WHITE_HOSTS 增 rollcall/viper/venom 主机,STATIC_SITES 增 rollcall/venom 静态根,静态站点路由下 /API/ 前缀请求转交 Django 处理。 gvsds:settings.py 注册 gvsds.apps.rollcall,urls.py 挂载 API/RollCall/;新增 rollcall 应用(模型/视图/路由/迁移 + RollCallManager 数据访问层)与 TempLate/rollcall 前端站点。 .gitignore:排除 Viper/Venom 前端工程与部署产物、TempLate/FTP 二进制分发目录。
50 lines
1.8 KiB
Python
50 lines
1.8 KiB
Python
"""RollCall API 视图——整体读写点名数据(学生/题目/课堂记录)。
|
||
|
||
- GET /API/RollCall/Data 读取全部数据(无记录返回空数组)
|
||
- POST /API/RollCall/Data 整体覆盖保存(body: {students, questions, history})
|
||
- DELETE /API/RollCall/Data 清空数据
|
||
|
||
点名站点为公开教学场景,未做登录鉴权(如需保护可在 Main.py 层或后续加 token)。
|
||
"""
|
||
|
||
from rest_framework.response import Response
|
||
from rest_framework.views import APIView
|
||
|
||
from .manager import RollCallManager
|
||
|
||
DATA_KEY = 'main'
|
||
|
||
|
||
class RollCallDataView(APIView):
|
||
authentication_classes = []
|
||
permission_classes = []
|
||
|
||
def get(self, request):
|
||
row = RollCallManager.GetData(DATA_KEY)
|
||
if row is None:
|
||
return Response({'students': [], 'questions': [], 'history': []})
|
||
return Response({
|
||
'students': row.Students or [],
|
||
'questions': row.Questions or [],
|
||
'history': row.History or [],
|
||
})
|
||
|
||
def post(self, request):
|
||
data = request.data if isinstance(request.data, dict) else {}
|
||
students = data.get('students')
|
||
questions = data.get('questions')
|
||
history = data.get('history')
|
||
if not isinstance(students, list) or not isinstance(questions, list):
|
||
return Response({'error': 'students/questions 必须为数组'}, status=400)
|
||
row = RollCallManager.SaveData(
|
||
DATA_KEY,
|
||
Students=students,
|
||
Questions=questions,
|
||
History=history if isinstance(history, list) else [],
|
||
)
|
||
return Response({'ok': True, 'updatedAt': row.UpdatedAt})
|
||
|
||
def delete(self, request):
|
||
deleted = RollCallManager.ClearData(DATA_KEY)
|
||
return Response({'ok': True, 'deleted': deleted})
|