예제 #1
0
파일: admin.py 프로젝트: NestDream/server
 def get(self, request):
     teacher_number = request.GET.get('teacherNumber')
     if not teacher_number:
         #not found
         return self.error(msg=f"teacher_number key is None", err=request.GET)
     try:
         teacher = Teacher.objects.get(teacher_number=teacher_number)
         courses_teacher = CourseTeacher.objects.filter(teacher=teacher)
         courses = []
         cur_time = datetime.date.today()
         for course_teacher in courses_teacher:
             cur_course = course_teacher.course
             s_time = cur_course.start_time
             e_time = cur_course.end_time
             if cur_time.le(e_time) and cur_time.ge(s_time): 
                 courses.append(
                     {
                         'course_id' : cur_course.code,
                         'name' : cur_course.name,
                         'start_time' : cur_course.start_time,
                         'end_time' : cur_course.end_time,
                         'description' : cur_course.description
                     }
                 )
         return self.success(JSONResponse(courses))
     except Exception as e:
         # not found
         return self.error(msg=str(e), err=e.args)
예제 #2
0
 def process_request(self, request):
     path = request.path_info
     if path.startswith("/admin/") or path.startswith("/api/admin/"):
         if not (request.user.is_authenticated
                 and request.user.is_admin_role()):
             return JSONResponse.response({
                 "error": "login-required",
                 "data": "Please login in first"
             })
예제 #3
0
 def error(self, data):
     return JSONResponse.response({'error': 'permission-denied', 'data': data})
예제 #4
0
 def error(self, data):
     return JSONResponse.response({
         "error": "permission-denied",
         "data": data
     })
예제 #5
0
 def error(self, data):
     return JSONResponse.response({"error": "permission-denied", "data": data})