添加剩余所有功能
This commit is contained in:
+39
-12
@@ -13,7 +13,7 @@ from django.shortcuts import render
|
||||
|
||||
from server.taskform import TaskForm
|
||||
from django.utils import timezone
|
||||
from server.models import Task,StudentandTercher,MindUser
|
||||
from server.models import Task,StudentandTercher,MindUser,Liuyan
|
||||
from server.serializers import *
|
||||
import json
|
||||
|
||||
@@ -59,6 +59,11 @@ class LoginView(APIView):
|
||||
# 记住登录状态
|
||||
login(request, user)
|
||||
return build_response(msg='学生端登录成功')
|
||||
elif user.is_active and user.type_t_or_s == 3:
|
||||
# 记住登录状态
|
||||
# 记住登录状态
|
||||
login(request, user)
|
||||
return build_response(msg='管理员登录成功')
|
||||
else:
|
||||
return build_response(code=CODE_FAILED, msg='登录失败')
|
||||
else:
|
||||
@@ -134,10 +139,8 @@ class TeacherView(LoginRequiredJSONMixin,APIView):
|
||||
|
||||
|
||||
def post_task(request):
|
||||
if request.method == 'POST':
|
||||
if request.user.type_t_or_s == 2:
|
||||
return render(request, 'html/error.html')
|
||||
else:
|
||||
if request.user.type_t_or_s == 1:
|
||||
if request.method == 'POST':
|
||||
start_time = timezone.now()
|
||||
title = request.POST.get("title")
|
||||
description = request.POST.get("description")
|
||||
@@ -145,26 +148,29 @@ def post_task(request):
|
||||
rengwu = Task(title=title, description=description, publish_time=start_time, deadline=end_time,publisher=request.user)
|
||||
rengwu.save()
|
||||
return http.JsonResponse({'code': CODE_SUCCESS, 'msg': '发布成功'})
|
||||
else:
|
||||
return render(request, 'html/post_task.html')
|
||||
else:
|
||||
return render(request, 'html/post_task.html')
|
||||
return render(request, 'html/dashboard.html')
|
||||
|
||||
def post_kecheng(request):
|
||||
if request.method == 'POST':
|
||||
if request.user.type_t_or_s == 2:
|
||||
return render(request, 'html/error.html')
|
||||
else:
|
||||
if request.user.type_t_or_s == 1:
|
||||
if request.method == 'POST':
|
||||
add_time = timezone.now()
|
||||
class_id = request.POST.get("class_id")
|
||||
class_name = request.POST.get("class_name")
|
||||
tercher_name = request.POST.get("tercher_name")
|
||||
class_info = request.POST.get("class_info")
|
||||
class_status = request.POST.get("class_status")
|
||||
rengwu = StudentandTercher(add_time=add_time,class_id=class_id, class_name=class_name,
|
||||
rengwu = StudentandTercher(add_time=add_time, class_id=class_id, class_name=class_name,
|
||||
tercher_name=tercher_name, class_info=class_info, class_status=class_status)
|
||||
rengwu.save()
|
||||
return http.JsonResponse({'code': CODE_SUCCESS, 'msg': '发布成功'})
|
||||
else:
|
||||
return render(request, 'html/post_kecheng.html')
|
||||
else:
|
||||
return render(request, 'html/post_kecheng.html')
|
||||
return render(request, 'html/dashboard.html')
|
||||
|
||||
|
||||
def come_kecheng(request):
|
||||
if request.method == 'POST':
|
||||
@@ -206,4 +212,25 @@ def comment_control(request): # 提交评论的处理函数
|
||||
|
||||
return JsonResponse(article, safe=False) # JsonResponse返回JSON字符串,自动序列化,如果不是字典类型,则需要添加safe参数为False
|
||||
|
||||
def admin_fun(request): # 提交评论的处理函数
|
||||
if request.method == 'POST':
|
||||
id = request.POST.get('user_id')
|
||||
MindUser.objects.filter(id=id).update(type_t_or_s=1)
|
||||
print(id)
|
||||
return http.JsonResponse({'code': CODE_SUCCESS, 'msg': '修改成功'})
|
||||
else:
|
||||
return http.JsonResponse({'code': CODE_FAILED, 'msg': '修改失败'})
|
||||
|
||||
def liuyan_fun(request): # 提交留言的处理函数
|
||||
if request.method == 'POST':
|
||||
username = request.user.username
|
||||
userid = MindUser.objects.get(username=username).id
|
||||
print("-----------------")
|
||||
print(userid)
|
||||
id = request.POST.get('user_id')
|
||||
liuyan = request.POST.get('liuyan_con')
|
||||
Liuyan.objects.create(liuyan_id=id,user_id=userid,liuyan_content=liuyan,liuyan_time=timezone.now())
|
||||
return http.JsonResponse({'code': CODE_SUCCESS, 'msg': '留言成功'})
|
||||
else:
|
||||
return http.JsonResponse({'code': CODE_FAILED, 'msg': '修改失败'})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user