From 9e5d6f91399455f026d9614fb039cfa7bd0bb23a Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Sun, 2 Aug 2015 18:41:19 +0300 Subject: [PATCH 1/2] fix --- SE_API/TaskRoutes.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/SE_API/TaskRoutes.py b/SE_API/TaskRoutes.py index 891abea..302c94d 100644 --- a/SE_API/TaskRoutes.py +++ b/SE_API/TaskRoutes.py @@ -704,9 +704,9 @@ def getTaskById(token, taskId, ownerId): task['grade'] = {} taskCompQuery = TaskComponent.all() - taskCompQuery.filter("taskId = ", taskId) + taskCompQuery.filter("taskId = ", int(taskId)) - taskCompQuery.filter("userId = ", ownerId) + taskCompQuery.filter("userId = ", int(ownerId)) # if task.isPersonal: # taskCompQuery.filter("userId = ", user.key().id()) # else: @@ -714,7 +714,6 @@ def getTaskById(token, taskId, ownerId): #check if never created a personalized task and if so, create it if taskCompQuery.count() == 0: - print "here" taskCompQuery = TaskComponent.all().filter("taskId =", int(taskId)).filter("userId =", -1) print "query count is: ", taskCompQuery.count() for tc in taskCompQuery.run(): From 8bb73c7bc7c43b556e22cb65b53eece77b84d1d6 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Sun, 2 Aug 2015 19:35:08 +0300 Subject: [PATCH 2/2] added submitGrade --- SE_API/TaskRoutes.py | 89 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/SE_API/TaskRoutes.py b/SE_API/TaskRoutes.py index 302c94d..64e04a0 100644 --- a/SE_API/TaskRoutes.py +++ b/SE_API/TaskRoutes.py @@ -230,6 +230,95 @@ def submitTask(token, taskId, ownerId): return Response(response=task.to_JSON(), status=200, mimetype="application/json") + + +@task_routes.route('/api/tasks/submitGrade////', methods=['POST']) +@auto.doc() +def submitTask(token, taskId, ownerId, grade): + """ + This call will create a new Task in the DB +
+ Route Parameters
+ - seToken: 'seToken' +
+
+ Payload
+ - JSON Object, Example:
+ {
+ "title":"task1",
+ "courseId":1234567890,
+ "description":"pls fddfsdfdsk",
+ "dueDate":{"year":2010,
+ "month":2,
+ "day":4
+ }, + "isPersonal":true,
+ "components":[
+ {
+ "type" : "should be type1",
+ "label" : "should be label1",
+ "isMandatory" : true,
+ "order" : 1
+ },
+ {
+ "type" : "should be type2",
+ "label" : "should be label2",
+ "isMandatory" : true,
+ "order" : 2
+ },
+ {
+ "type" : "should be type3",
+ "label" : "should be label3",
+ "isMandatory" : false,
+ "order" : 3
+ }
+ ]
+} +
+
+ Response +
+ 201 - Created +
+ 400 - Bad Request +
+ 403 - Invalid token or not a lecturer + """ + user = get_user_by_token(token) + if user is None: + bad_request("bad user Token") + + task = Task.get_by_id(int(taskId)) + if task is None: + bad_request("bad Task id") + + + if task.isPersonal: + if User.get_by_id(int(ownerId)) is None: + return bad_request("no such user") + else: + if Project.get_by_id(int(ownerId)) is None: + return bad_request("no such project") + + try: + tg = TaskGrade.all().filter("taskId = ", int(taskId)).filter("userId = ", int(ownerId)) + if tg.count() == 0: + grade = TaskGrade(taskId=int(taskId), userId=int(ownerId), grade=int(grade)) + else: + for g in tg.run(): + g.grade=int(grade) + g.taskId=int(taskId) + g.userId=int(ownerId) + db.put(grade) + db.save + return Response(response=grade.to_JSON(), + status=200, + mimetype="application/json") + except Exception as e: + print e.message + return bad_request("wrong format") + + #---------------------------------------------------------- # PUT #----------------------------------------------------------