fix create Task issues
This commit is contained in:
parent
fd8b7ed7e7
commit
2c646b289a
1 changed files with 33 additions and 34 deletions
|
@ -48,7 +48,7 @@ def create_task(token):
|
||||||
- JSON Object, Example: <br>
|
- JSON Object, Example: <br>
|
||||||
{<br>
|
{<br>
|
||||||
"title":"task1",<br>
|
"title":"task1",<br>
|
||||||
"courseName":"aran",<br>
|
"courseId":1234567890,<br>
|
||||||
"description":"pls fddfsdfdsk",<br>
|
"description":"pls fddfsdfdsk",<br>
|
||||||
"dueDate":{"year":2010,<br>
|
"dueDate":{"year":2010,<br>
|
||||||
"month":2,<br>
|
"month":2,<br>
|
||||||
|
@ -87,47 +87,44 @@ def create_task(token):
|
||||||
403 - Invalid token or not a lecturer
|
403 - Invalid token or not a lecturer
|
||||||
"""
|
"""
|
||||||
if not request.data:
|
if not request.data:
|
||||||
return bad_request()
|
return bad_request("no payload")
|
||||||
payload = json.loads(request.data)
|
payload = json.loads(request.data)
|
||||||
if not is_lecturer(token): #todo: change to lecturer id
|
if not is_lecturer(token): #todo: change to lecturer id
|
||||||
return forbidden("Invalid token or not a lecturer!")
|
return forbidden("Invalid token or not a lecturer!")
|
||||||
|
|
||||||
user = get_user_by_token(token)
|
user = get_user_by_token(token)
|
||||||
#TODO: add seconds and minutes
|
|
||||||
#check the user(lecturer) is owner of the course
|
|
||||||
# try:
|
|
||||||
# arr = []
|
|
||||||
# query = Course.all()
|
|
||||||
# query.filter('courseName =',payload['courseName'])
|
|
||||||
# for t in query.run():
|
|
||||||
# arr.append(dict(json.loads(t.to_JSON())))
|
|
||||||
# if len(arr) == 0:
|
|
||||||
# return bad_request("No such course")
|
|
||||||
# except Exception as e:
|
|
||||||
# print e
|
|
||||||
# return bad_request("Missing courseName")
|
|
||||||
|
|
||||||
|
#check lecturer is owner of course
|
||||||
#todo: check legality
|
|
||||||
#create Task object
|
|
||||||
try:
|
try:
|
||||||
#parse dueDate
|
courseId = payload['courseId']
|
||||||
try:
|
|
||||||
date = datetime.date(payload['dueDate']['year'],payload['dueDate']['month'],payload['dueDate']['day'])
|
|
||||||
except Exception:
|
|
||||||
return bad_request("invalid dueDate format")
|
|
||||||
|
|
||||||
task = Task(title=payload['title'], courseName=payload['courseName'], description=payload['description'], dueDate=date)
|
|
||||||
|
|
||||||
# print "id: ",task.key().id()
|
|
||||||
#parse isPersonal
|
|
||||||
try:
|
|
||||||
task.isPersonal = payload['isPersonal']
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print e
|
print e
|
||||||
return bad_request()
|
return bad_request("invalid courseId format")
|
||||||
|
|
||||||
|
course = Course.get_by_id(int(courseId))
|
||||||
|
if course is None:
|
||||||
|
return bad_request("No such Course")
|
||||||
|
|
||||||
|
if course.master_id != user.key().id():
|
||||||
|
return forbidden("Lecturer is not owner of Course")
|
||||||
|
|
||||||
|
#parse dueDate
|
||||||
|
try:
|
||||||
|
date = datetime.date(payload['dueDate']['year'],payload['dueDate']['month'],payload['dueDate']['day'])
|
||||||
|
except Exception:
|
||||||
|
return bad_request("invalid dueDate format")
|
||||||
|
#create Task object
|
||||||
|
try:
|
||||||
|
task = Task(title=payload['title'], courseId=payload['courseId'], description=payload['description'], dueDate=date)
|
||||||
|
except Exception as e:
|
||||||
|
print e
|
||||||
|
return bad_request("bad")
|
||||||
|
try:
|
||||||
|
task.isPersonal = payload['isPersonal']
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
db.put(task)
|
db.put(task)
|
||||||
db.save
|
db.save
|
||||||
|
|
||||||
|
@ -141,7 +138,9 @@ def create_task(token):
|
||||||
db.put(component)
|
db.put(component)
|
||||||
db.save
|
db.save
|
||||||
|
|
||||||
return created()
|
return Response(response=task.to_JSON(),
|
||||||
|
status=200,
|
||||||
|
mimetype="application/json")
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------
|
#----------------------------------------------------------
|
||||||
|
|
Loading…
Reference in a new issue