From 32d7f40b060283d72c4b40bf9a7dc8e51e7c8c66 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Sun, 2 Aug 2015 22:21:13 +0300 Subject: [PATCH] added getUsersStateByTask function --- SE_API/TaskRoutes.py | 132 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/SE_API/TaskRoutes.py b/SE_API/TaskRoutes.py index de1d5f3..8ee4a93 100644 --- a/SE_API/TaskRoutes.py +++ b/SE_API/TaskRoutes.py @@ -693,6 +693,7 @@ def getAllUserTasks(token): course = Course.get_by_id(int(c)) dic['courseName'] = course.courseName dic['courseId'] = course.key().id() + dic['master_id'] = course.master_id courseTasks = Task.all().filter("courseId = ", course.key().id()) taskArr = [] for t in courseTasks.run(): @@ -755,6 +756,137 @@ def getAllUserTasks(token): status=200, mimetype="application/json") +@task_routes.route('/api/tasks/getUsersStateByTask//', methods=["GET"]) +@auto.doc() +def getUsersStateByTask(token, taskId): + """ + >This Call will return an array of all of the User's Tasks +
+ Route Parameters
+ - SeToken: token
+
+
+ Payload
+ - NONE +
+
+ Response +
+ 200 - JSON Example:
+ [
+ {
+ "courseName": "Advance Math",
+ "courseId": 4762397176758272,
+ "PersonalTasks": [
+ {
+ "grade": 12,
+ "isPersonal": true,
+ "dueDate": {
+ "year": 2010,
+ "day": 4,
+ "month": 2
+ },
+ "courseId": 4762397176758272,
+ "title": "task1",
+ "description": "pls fddfsdfdsk",
+ "id": 5888297083600896
+ }
+ ],
+ "projectTasks": []
+ },
+ {
+ "courseName": "Bad Math",
+ "courseId": 5659598665023488,
+ "PersonalTasks": [
+ {
+ "grade": 12,
+ "isPersonal": true,
+ "dueDate": {
+ "year": 2010,
+ "day": 4,
+ "month": 2
+ },
+ "courseId": 5659598665023488,
+ "title": "new task1",
+ "description": "pls fddfsdfdsk",
+ "id": 5096648711602176
+ },
+ {
+ "grade": 12,
+ "isPersonal": true,
+ "dueDate": {
+ "year": 2010,
+ "day": 4,
+ "month": 2
+ },
+ "courseId": 5659598665023488,
+ "title": "new task4",
+ "description": "pls fddfsdfdsk",
+ "id": 5167017455779840
+ }
+ ],
+ "projectTasks": [
+ {
+ "grade": 12,
+ "isPersonal": false,
+ "dueDate": {
+ "year": 2010,
+ "day": 4,
+ "month": 2
+ },
+ "courseId": 5659598665023488,
+ "title": "new task3",
+ "description": "pls fddfsdfdsk",
+ "id": 5237386199957504
+ }
+ ]
+ }
+ ]
+
+
+ """ + user = get_user_by_token(token) + if user is None: + return bad_request("Bad User Token") + + task = Task.get_by_id(int(taskId)) + if task is None: + return bad_request("Bad task id") + + course = Course.get_by_id(task.courseId) + + arr = [] + if task.isPersonal: + for u in enumerate(course.membersId): + user = User.get_by_id(int(u)) + userDic = dict(json.loads(user.to_JSON())) + grade = TaskGrade.all().filter("taskId = ", task.key().id()).filter("userId = ", user.key().id()) + for g in grade.run(): + userDic['grade'] = json.loads(g.to_JSON()) + if grade.count() == 0: + userDic['grade'] = {'taskId': taskId, 'userId': user.key().id(), 'grade': None} + arr.append(userDic) + + else: + projects = Project.all().filter("courseId = ", course.key().id()) + for project in projects.run(): + projDic = dict(json.loads(project.to_JSON())) + grade = TaskGrade.all().filter("taskId = ", task.key().id()).filter("userId = ", project.key().id()) + for g in grade.run(): + projDic['grade'] = json.loads(g.to_JSON()) + if grade.count() == 0: + projDic['grade'] = {'taskId': taskId, 'userId': user.key().id(), 'grade': None} + arr.append(projDic) + + if len(arr) != 0: + return Response(response=json.dumps(arr), + status=200, + mimetype="application/json") + else: + return Response(response=[], + status=200, + mimetype="application/json") + # @task_routes.route('/api/tasks/getAllUngradedTasks///', methods=["GET"]) # @auto.doc()