Merge pull request #137 from sagidayan/API_Dev
added value to componenets and submitTask method
This commit is contained in:
commit
f2d646d596
2 changed files with 23 additions and 2 deletions
|
@ -20,6 +20,7 @@ from models.Task import Task
|
||||||
from models.Course import Course
|
from models.Course import Course
|
||||||
from models.TaskComponent import TaskComponent
|
from models.TaskComponent import TaskComponent
|
||||||
from models.TaskGrade import TaskGrade
|
from models.TaskGrade import TaskGrade
|
||||||
|
from models.Project import Project
|
||||||
|
|
||||||
#Validation Utils Libs
|
#Validation Utils Libs
|
||||||
from SE_API.Validation_Utils import *
|
from SE_API.Validation_Utils import *
|
||||||
|
@ -200,13 +201,25 @@ def submitTask(token, taskId, ownerId):
|
||||||
payload = json.loads(request.data)
|
payload = json.loads(request.data)
|
||||||
|
|
||||||
user = get_user_by_token(token)
|
user = get_user_by_token(token)
|
||||||
|
if user is None:
|
||||||
|
bad_request("bad user Token")
|
||||||
|
|
||||||
task = Task.get_by_id(int(taskId))
|
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
|
#create components
|
||||||
for c in payload['components']:
|
for c in payload:
|
||||||
try:
|
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:
|
except Exception as e:
|
||||||
print e
|
print e
|
||||||
return bad_request("Bad component")
|
return bad_request("Bad component")
|
||||||
|
@ -678,6 +691,12 @@ def getTaskById(token, taskId, ownerId):
|
||||||
task = Task.get_by_id(int(taskId))
|
task = Task.get_by_id(int(taskId))
|
||||||
if task is None:
|
if task is None:
|
||||||
return bad_request("Bad Task id")
|
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 = json.loads(task.to_JSON())
|
||||||
task['components'] = []
|
task['components'] = []
|
||||||
|
|
|
@ -10,6 +10,7 @@ class TaskComponent(db.Model):
|
||||||
userId = db.IntegerProperty(required=True, default = -1)
|
userId = db.IntegerProperty(required=True, default = -1)
|
||||||
type = db.StringProperty(required=True,default=" ")
|
type = db.StringProperty(required=True,default=" ")
|
||||||
label = db.StringProperty(required=True,default=" ")
|
label = db.StringProperty(required=True,default=" ")
|
||||||
|
value = db.StringProperty(required=True, default=" ")
|
||||||
isMandatory = db.BooleanProperty(required=True, default=True)
|
isMandatory = db.BooleanProperty(required=True, default=True)
|
||||||
order = db.IntegerProperty(required=True)
|
order = db.IntegerProperty(required=True)
|
||||||
|
|
||||||
|
@ -18,6 +19,7 @@ class TaskComponent(db.Model):
|
||||||
'userId' : self.userId,
|
'userId' : self.userId,
|
||||||
'type' : self.type,
|
'type' : self.type,
|
||||||
'label' : self.label,
|
'label' : self.label,
|
||||||
|
'value' : self.value,
|
||||||
'isMandatory' : self.isMandatory,
|
'isMandatory' : self.isMandatory,
|
||||||
'order' : self.order,
|
'order' : self.order,
|
||||||
'id' : self.key().id()
|
'id' : self.key().id()
|
||||||
|
|
Loading…
Reference in a new issue