From e558b9e23820bb28c99b9288be677f969fa23556 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Sun, 2 Aug 2015 16:33:28 +0300 Subject: [PATCH] added value to componenets and submitTask method --- SE_API/TaskRoutes.py | 23 +++++++++++++++++++++-- models/TaskComponent.py | 2 ++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/SE_API/TaskRoutes.py b/SE_API/TaskRoutes.py index e4c0296..12965d5 100644 --- a/SE_API/TaskRoutes.py +++ b/SE_API/TaskRoutes.py @@ -20,6 +20,7 @@ from models.Task import Task from models.Course import Course from models.TaskComponent import TaskComponent from models.TaskGrade import TaskGrade +from models.Project import Project #Validation Utils Libs from SE_API.Validation_Utils import * @@ -200,13 +201,25 @@ def submitTask(token, taskId, ownerId): payload = json.loads(request.data) 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(ownerId) is None: + return bad_request("no such user") + else: + if Project.get_by_id(ownerId) is None: + return bad_request("no such project") + #create components - for c in payload['components']: + for c in payload: try: - component = TaskComponent(taskId=task.key().id(), userId=(int(ownerId)), type=c['type'], label=c['label'], isMandatory=c['isMandatory'], order=c['order']) + component = TaskComponent(taskId=task.key().id(), userId=(int(ownerId)), type=c['type'], label=c['label'], value=c['value'], isMandatory=c['isMandatory'], order=c['order']) except Exception as e: print e return bad_request("Bad component") @@ -678,6 +691,12 @@ def getTaskById(token, taskId, ownerId): task = Task.get_by_id(int(taskId)) if task is None: return bad_request("Bad Task id") + if task.isPersonal: + if User.get_by_id(ownerId) is None: + return bad_request("no such user") + else: + if Project.get_by_id(ownerId) is None: + return bad_request("no such project") task = json.loads(task.to_JSON()) task['components'] = [] diff --git a/models/TaskComponent.py b/models/TaskComponent.py index 161cfcc..f220b97 100644 --- a/models/TaskComponent.py +++ b/models/TaskComponent.py @@ -10,6 +10,7 @@ class TaskComponent(db.Model): userId = db.IntegerProperty(required=True, default = -1) type = db.StringProperty(required=True,default=" ") label = db.StringProperty(required=True,default=" ") + value = db.StringProperty(required=True, default=" ") isMandatory = db.BooleanProperty(required=True, default=True) order = db.IntegerProperty(required=True) @@ -18,6 +19,7 @@ class TaskComponent(db.Model): 'userId' : self.userId, 'type' : self.type, 'label' : self.label, + 'value' : self.value, 'isMandatory' : self.isMandatory, 'order' : self.order, 'id' : self.key().id()