diff --git a/SE_API/TaskRoutes.py b/SE_API/TaskRoutes.py index 5c05723..e2f8a15 100644 --- a/SE_API/TaskRoutes.py +++ b/SE_API/TaskRoutes.py @@ -19,6 +19,7 @@ from flask.ext.autodoc import Autodoc from models.Task import Task from models.Course import Course from models.TaskComponent import TaskComponent +from models.TaskGrade import TaskGrade #Validation Utils Libs from SE_API.Validation_Utils import * @@ -350,6 +351,155 @@ def getTaskComponents(token, taskId): else: return no_content() +@task_routes.route('/api/tasks/getAllUserTasks/', methods=["GET"]) +@auto.doc() +def getAllTasksByUser(token): + """ + >This Call will return an array of all of the User's Tasks +
+ Route Parameters
+ - SeToken: token
+
+
+ Payload
+ - NONE +
+
+ Response +
+ 200 - JSON Example:
+ + {
+ 'title' : 'Task1',
+ 'courseId' : 12345678,
+ 'description' : 'prepare by sunday',
+ 'dueDate' : { + 'year' : 2015, + 'month' : 12, + 'day' : 23 + }
+ 'isPersonal' : true,
+ 'task_id' : 589689456894
+ }
+
+
+ """ + user = get_user_by_token(token) + if user is None: + return bad_request("Bad User Token") + + arr = [] + for c in user.courses_id_list: + + dic = {} + course = Course.get_by_id(int(c)) + dic['courseName'] = course.courseName + dic['courseId'] = course.key().id() + courseTasks = Task.all().filter("courseId = ", course.key().id()) + taskArr = [] + for t in courseTasks.run(): + taskDic =dict(json.loads(t.to_JSON())) + #add a key 'forSortDate' for sorting dates + taskTime = datetime.datetime(taskDic['dueDate']['year'], taskDic['dueDate']['month'], taskDic['dueDate']['day']) + taskDic['forSortDate'] = taskTime + grade = TaskGrade.all().filter("taskId = ", t.key().id()).filter("userId = ", user.key().id()) + for g in grade.run(): + taskDic['grade'] = g.grade + if grade.count() == 0: + taskDic['grade'] = 0 + taskArr.append(taskDic) + + taskArr = sorted(taskArr, key=itemgetter('forSortDate'), reverse=False) + for i in taskArr: + del i['forSortDate'] + + userTaskArr = [] + projectTaskArr = [] + for t in taskArr: + if t['isPersonal']: + userTaskArr.append(t) + else: + projectTaskArr.append(t) + + + dic['PersonalTasks'] = userTaskArr + dic['projectTasks'] = projectTaskArr + arr.append(dic) + + #sort array by date, and remove added key + + + return Response(response=json.dumps(arr), + status=200, + mimetype="application/json") + + + +# @task_routes.route('/api/tasks/getUserFullTasksById//', methods=["GET"]) +# @auto.doc() +# def getFullTasksById(token, taskId): +# """ +# >This Call will return an array of all components for a given task +#
+# Route Parameters
+# - SeToken: token
+# - taskId: 1234567890 +#
+#
+# Payload
+# - NONE +#
+#
+# Response +#
+# 200 - JSON Example:
+# +# [ +# {
+# 'taskId' : 7589454894, +# 'userId' : -1, +# 'type' : 'kindOfType', +# 'label' : 'kindOfLabel', +# 'isMandatory' : true, +# 'order' : 2 +# }
+# {
+# 'taskId' : 7589454894, +# 'userId' : yossi, +# 'type' : 'otherKindOfType', +# 'label' : 'otherKindOfLabel', +# 'isMandatory' : false, +# 'order' : 4 +# }
+# ] +#
+#
+# """ +# 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") +# +# taskCompQuery = TaskComponent.all() +# taskCompQuery.filter("taskId = ", task.key().id()) +# +# if task.isPersonal: +# taskCompQuery.filter("userId = ", user.key().id()) +# else: +# taskCompQuery.filter("userId = ", user.key().id()) +# +# if taskCompQuery.count() == 0: +# #create componenets and Score for user +# +# +# for i in taskCompQuery.run(): +# print i.to_JSON() +# +# return no_content() + #---------------------------------------------------------- diff --git a/models/TaskGrade.py b/models/TaskGrade.py new file mode 100644 index 0000000..83cc304 --- /dev/null +++ b/models/TaskGrade.py @@ -0,0 +1,20 @@ +__author__ = 'Aran' + + +import json +from google.appengine.ext import db + + +class TaskGrade(db.Model): + taskId = db.IntegerProperty(required=True) + userId = db.IntegerProperty(required=True) + grade = db.IntegerProperty(required=False,default=0) + + + def to_JSON(self): + data = {'taskId' : self.taskId, + 'userId' : self.userId, + 'grade' : self.grade, + 'id' : self.key().id() + } + return json.dumps(data)