added submitGrade

This commit is contained in:
Aran Zaiger 2015-08-02 19:35:08 +03:00
parent 23ebadc347
commit 8bb73c7bc7

View file

@ -230,6 +230,95 @@ def submitTask(token, taskId, ownerId):
return Response(response=task.to_JSON(), return Response(response=task.to_JSON(),
status=200, status=200,
mimetype="application/json") mimetype="application/json")
@task_routes.route('/api/tasks/submitGrade/<string:token>/<string:taskId>/<string:ownerId>/<string:grade>', methods=['POST'])
@auto.doc()
def submitTask(token, taskId, ownerId, grade):
"""
<span class="card-title">This call will create a new Task in the DB</span>
<br>
<b>Route Parameters</b><br>
- seToken: 'seToken'
<br>
<br>
<b>Payload</b><br>
- JSON Object, Example: <br>
{<br>
"title":"task1",<br>
"courseId":1234567890,<br>
"description":"pls fddfsdfdsk",<br>
"dueDate":{"year":2010,<br>
"month":2,<br>
"day":4<br>
},
"isPersonal":true,<br>
"components":[<br>
{<br>
"type" : "should be type1",<br>
"label" : "should be label1",<br>
"isMandatory" : true,<br>
"order" : 1<br>
},<br>
{<br>
"type" : "should be type2",<br>
"label" : "should be label2",<br>
"isMandatory" : true,<br>
"order" : 2<br>
},<br>
{<br>
"type" : "should be type3",<br>
"label" : "should be label3",<br>
"isMandatory" : false,<br>
"order" : 3<br>
}<br>
]<br>
}
<br>
<br>
<b>Response</b>
<br>
201 - Created
<br>
400 - Bad Request
<br>
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 # PUT
#---------------------------------------------------------- #----------------------------------------------------------