From 60dba1a696a28c066d2597298a29b609848a6fd8 Mon Sep 17 00:00:00 2001 From: Monster Date: Fri, 22 May 2020 00:07:50 +0800 Subject: [PATCH] finish show_user_notification api in backend --- backend/ddl_killer/urls.py | 2 +- backend/ddl_killer/views.py | 41 +++++++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/backend/ddl_killer/urls.py b/backend/ddl_killer/urls.py index f46d85e..92a8f10 100644 --- a/backend/ddl_killer/urls.py +++ b/backend/ddl_killer/urls.py @@ -25,6 +25,7 @@ urlpatterns = [ path(r'user//course//resources/new', views.add_resources), path(r'user//courses', views.show_user_courses), path(r'user//course//tasks/new', views.admin_add_task), + path(r'user//course//notifications', views.show_course_notifications), path(r'user//tasks/new', views.add_task), path(r'course//user//appoint', views.appoint_course_admin), path(r'register', views.create_user), @@ -37,5 +38,4 @@ urlpatterns = [ path(r'modify', views.edit_user), path(r'q2l/dbchange', views.q2ldbchange), path(r'user//tasks//delete', views.delete_task), - ] diff --git a/backend/ddl_killer/views.py b/backend/ddl_killer/views.py index 7f5dfd3..ba159b0 100644 --- a/backend/ddl_killer/views.py +++ b/backend/ddl_killer/views.py @@ -313,8 +313,8 @@ def update_courses(request, uid): #从课程中心获取用户所选课程并同 else: this_note = Note.objects.create(title=note['title'], time=note['time'], url=note['url'], content=note['content'], attachments=note['attachments']) - print(this_note.title) - if not CourseNote.objects.filter(course__cid=course.cid, note__nid=this_note.nid).exists: + # print(this_note.title) + if not CourseNote.objects.filter(course__cid=course.cid, note__nid=this_note.nid).exists(): CourseNote.objects.create(course=course, note=this_note) except: traceback.print_exc() @@ -535,7 +535,7 @@ def show_course_tasks(request, uid, cid): #用户uid,相应课程cid }) # else: - print(response['data']) + # print(response['data']) return JsonResponse(response, json_dumps_params={'ensure_ascii':False}, charset='utf_8_sig') def appoint_course_admin(request, cid, uid): #授予普通用户某门课程的管理权 @@ -624,13 +624,38 @@ def show_course_resources(request, uid, cid): }) return JsonResponse(response, json_dumps_params={'ensure_ascii':False}, charset='utf_8_sig') +def show_course_notifications(request, uid, cid): + response={} + usercourse = UserCourse.objects.filter(course__cid=cid, user__uid=uid) + if not usercourse.exists(): + response['code'] = 404 + response['msg'] = 'You have no access to this course.' + else: + coursenotes = CourseNote.objects.filter(course__cid=cid) + response['data'] = [] + for cn in coursenotes: + response['data'].append({ + 'title': cn.note.title, + 'url': cn.note.url, + 'time': cn.note.time, + 'content': cn.note.content, + 'attachments': cn.note.attachments + }) + response['code'] = 200 + response['msg'] = 'Success' + + # print(json.dumps(response, ensure_ascii=False)) + return JsonResponse(response, json_dumps_params={'ensure_ascii':False}, charset='utf_8_sig') + + def q2ldbchange(request): try: - for ct in CourseTask.objects.all(): - c = ct.course - t = ct.task - t.course_name = c.name - t.save() + # for ct in CourseTask.objects.all(): + # c = ct.course + # t = ct.task + # t.course_name = c.name + # t.save() + pass except: traceback.print_exc() pass -- Gitee