From fd8b7ed7e7317f72208a348878d17194c576c3a6 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Thu, 2 Jul 2015 22:16:06 +0300 Subject: [PATCH 1/5] doc change --- SE_API/CourseRoutes.py | 4 ---- SE_API/MessageRoutes.py | 7 ------- 2 files changed, 11 deletions(-) diff --git a/SE_API/CourseRoutes.py b/SE_API/CourseRoutes.py index 9331a17..2f9d4b2 100644 --- a/SE_API/CourseRoutes.py +++ b/SE_API/CourseRoutes.py @@ -399,10 +399,6 @@ def getCoursesByID(token, courseId): return Response(response=course.to_JSON(), status=200, mimetype="application/json") -#---------------------------------------------------------- -# PUT -#---------------------------------------------------------- - diff --git a/SE_API/MessageRoutes.py b/SE_API/MessageRoutes.py index a181620..272fb5c 100644 --- a/SE_API/MessageRoutes.py +++ b/SE_API/MessageRoutes.py @@ -52,13 +52,6 @@ def createMessage(token): {
'groupId' : 123456789,
'message' : 'Class is canceled',
- 'date' : {
- 'year': 2015,
- 'month': 3,
- 'day': 14,
- 'hour': 16,
- 'minute': 53
- },
'isProject' : true
}

From 2c646b289aba67ceef3574a888128e9f294ac983 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Thu, 2 Jul 2015 22:48:01 +0300 Subject: [PATCH 2/5] fix create Task issues --- SE_API/TaskRoutes.py | 67 ++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/SE_API/TaskRoutes.py b/SE_API/TaskRoutes.py index 2dd7a06..5c05723 100644 --- a/SE_API/TaskRoutes.py +++ b/SE_API/TaskRoutes.py @@ -48,7 +48,7 @@ def create_task(token): - JSON Object, Example:
{
"title":"task1",
- "courseName":"aran",
+ "courseId":1234567890,
"description":"pls fddfsdfdsk",
"dueDate":{"year":2010,
"month":2,
@@ -87,47 +87,44 @@ def create_task(token): 403 - Invalid token or not a lecturer """ if not request.data: - return bad_request() + return bad_request("no payload") payload = json.loads(request.data) if not is_lecturer(token): #todo: change to lecturer id return forbidden("Invalid token or not a lecturer!") 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") - - #todo: check legality - #create Task object + #check lecturer is owner of course try: - #parse dueDate - 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 + courseId = payload['courseId'] except Exception as 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.save @@ -141,7 +138,9 @@ def create_task(token): db.put(component) db.save - return created() + return Response(response=task.to_JSON(), + status=200, + mimetype="application/json") #---------------------------------------------------------- From 55593a65429691b21e6f60932ade2bda7ac994bc Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Thu, 2 Jul 2015 23:52:22 +0300 Subject: [PATCH 3/5] copying an object instead of re-requesting from db --- SE_API/MessageRoutes.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/SE_API/MessageRoutes.py b/SE_API/MessageRoutes.py index a360da7..5942b85 100644 --- a/SE_API/MessageRoutes.py +++ b/SE_API/MessageRoutes.py @@ -1,3 +1,5 @@ +import copy + __author__ = 'Aran' from flask import Blueprint @@ -245,9 +247,11 @@ def getAllUserMessages(token): arr = [] - query = Message.all() - query.filter('isProject =', False) - for m in query.run(): + allMsgs = Message.all() + projectMsgs = copy.deepcopy(allMsgs) + + projectMsgs.filter('isProject =', False) + for m in projectMsgs.run(): if str(m.groupId) in user.courses_id_list: msgDic = dict(json.loads(m.to_JSON())) #add a key 'forSortDate' for sorting dates @@ -255,9 +259,9 @@ def getAllUserMessages(token): msgDic['forSortDate'] = msgTime arr.append(msgDic) - query = Message.all() - query.filter('isProject =', True) - for m in query.run(): + + allMsgs.filter('isProject =', True) + for m in allMsgs.run(): if str(m.groupId) in user.projects_id_list: msgDic = dict(json.loads(m.to_JSON())) #add a key 'forSortDate' for sorting dates From 8a579cfb837ba4cc5777a38c7c0552770dd80e88 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Fri, 3 Jul 2015 01:19:21 +0300 Subject: [PATCH 4/5] added TaskGrade model and getAllUserTasks function --- SE_API/TaskRoutes.py | 150 +++++++++++++++++++++++++++++++++++++++++++ models/TaskGrade.py | 20 ++++++ 2 files changed, 170 insertions(+) create mode 100644 models/TaskGrade.py diff --git a/SE_API/TaskRoutes.py b/SE_API/TaskRoutes.py index 5c05723..e2f8a15 100644 --- a/SE_API/TaskRoutes.py +++ b/SE_API/TaskRoutes.py @@ -19,6 +19,7 @@ from flask.ext.autodoc import Autodoc from models.Task import Task from models.Course import Course from models.TaskComponent import TaskComponent +from models.TaskGrade import TaskGrade #Validation Utils Libs from SE_API.Validation_Utils import * @@ -350,6 +351,155 @@ def getTaskComponents(token, taskId): else: return no_content() +@task_routes.route('/api/tasks/getAllUserTasks/', methods=["GET"]) +@auto.doc() +def getAllTasksByUser(token): + """ + >This Call will return an array of all of the User's Tasks +
+ Route Parameters
+ - SeToken: token
+
+
+ Payload
+ - NONE +
+
+ Response +
+ 200 - JSON Example:
+ + {
+ 'title' : 'Task1',
+ 'courseId' : 12345678,
+ 'description' : 'prepare by sunday',
+ 'dueDate' : { + 'year' : 2015, + 'month' : 12, + 'day' : 23 + }
+ 'isPersonal' : true,
+ 'task_id' : 589689456894
+ }
+
+
+ """ + user = get_user_by_token(token) + if user is None: + return bad_request("Bad User Token") + + arr = [] + for c in user.courses_id_list: + + dic = {} + course = Course.get_by_id(int(c)) + dic['courseName'] = course.courseName + dic['courseId'] = course.key().id() + courseTasks = Task.all().filter("courseId = ", course.key().id()) + taskArr = [] + for t in courseTasks.run(): + taskDic =dict(json.loads(t.to_JSON())) + #add a key 'forSortDate' for sorting dates + taskTime = datetime.datetime(taskDic['dueDate']['year'], taskDic['dueDate']['month'], taskDic['dueDate']['day']) + taskDic['forSortDate'] = taskTime + grade = TaskGrade.all().filter("taskId = ", t.key().id()).filter("userId = ", user.key().id()) + for g in grade.run(): + taskDic['grade'] = g.grade + if grade.count() == 0: + taskDic['grade'] = 0 + taskArr.append(taskDic) + + taskArr = sorted(taskArr, key=itemgetter('forSortDate'), reverse=False) + for i in taskArr: + del i['forSortDate'] + + userTaskArr = [] + projectTaskArr = [] + for t in taskArr: + if t['isPersonal']: + userTaskArr.append(t) + else: + projectTaskArr.append(t) + + + dic['PersonalTasks'] = userTaskArr + dic['projectTasks'] = projectTaskArr + arr.append(dic) + + #sort array by date, and remove added key + + + return Response(response=json.dumps(arr), + status=200, + mimetype="application/json") + + + +# @task_routes.route('/api/tasks/getUserFullTasksById//', methods=["GET"]) +# @auto.doc() +# def getFullTasksById(token, taskId): +# """ +# >This Call will return an array of all components for a given task +#
+# Route Parameters
+# - SeToken: token
+# - taskId: 1234567890 +#
+#
+# Payload
+# - NONE +#
+#
+# Response +#
+# 200 - JSON Example:
+# +# [ +# {
+# 'taskId' : 7589454894, +# 'userId' : -1, +# 'type' : 'kindOfType', +# 'label' : 'kindOfLabel', +# 'isMandatory' : true, +# 'order' : 2 +# }
+# {
+# 'taskId' : 7589454894, +# 'userId' : yossi, +# 'type' : 'otherKindOfType', +# 'label' : 'otherKindOfLabel', +# 'isMandatory' : false, +# 'order' : 4 +# }
+# ] +#
+#
+# """ +# user = get_user_by_token(token) +# if user is None: +# return bad_request("Bad User Token") +# +# task = Task.get_by_id(int(taskId)) +# if task is None: +# return bad_request("Bad Task id") +# +# taskCompQuery = TaskComponent.all() +# taskCompQuery.filter("taskId = ", task.key().id()) +# +# if task.isPersonal: +# taskCompQuery.filter("userId = ", user.key().id()) +# else: +# taskCompQuery.filter("userId = ", user.key().id()) +# +# if taskCompQuery.count() == 0: +# #create componenets and Score for user +# +# +# for i in taskCompQuery.run(): +# print i.to_JSON() +# +# return no_content() + #---------------------------------------------------------- diff --git a/models/TaskGrade.py b/models/TaskGrade.py new file mode 100644 index 0000000..83cc304 --- /dev/null +++ b/models/TaskGrade.py @@ -0,0 +1,20 @@ +__author__ = 'Aran' + + +import json +from google.appengine.ext import db + + +class TaskGrade(db.Model): + taskId = db.IntegerProperty(required=True) + userId = db.IntegerProperty(required=True) + grade = db.IntegerProperty(required=False,default=0) + + + def to_JSON(self): + data = {'taskId' : self.taskId, + 'userId' : self.userId, + 'grade' : self.grade, + 'id' : self.key().id() + } + return json.dumps(data) From 44f0d1705a6612148ff63d771012f285076f7df2 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Fri, 3 Jul 2015 01:26:08 +0300 Subject: [PATCH 5/5] added doc --- SE_API/TaskRoutes.py | 82 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 69 insertions(+), 13 deletions(-) diff --git a/SE_API/TaskRoutes.py b/SE_API/TaskRoutes.py index e2f8a15..ee3bee6 100644 --- a/SE_API/TaskRoutes.py +++ b/SE_API/TaskRoutes.py @@ -368,19 +368,75 @@ def getAllTasksByUser(token): Response
200 - JSON Example:
- - {
- 'title' : 'Task1',
- 'courseId' : 12345678,
- 'description' : 'prepare by sunday',
- 'dueDate' : { - 'year' : 2015, - 'month' : 12, - 'day' : 23 - }
- 'isPersonal' : true,
- 'task_id' : 589689456894
- }
+ [
+ {
+ "courseName": "Advance Math",
+ "courseId": 4762397176758272,
+ "PersonalTasks": [
+ {
+ "grade": 12,
+ "isPersonal": true,
+ "dueDate": {
+ "year": 2010,
+ "day": 4,
+ "month": 2
+ },
+ "courseId": 4762397176758272,
+ "title": "task1",
+ "description": "pls fddfsdfdsk",
+ "id": 5888297083600896
+ }
+ ],
+ "projectTasks": []
+ },
+ {
+ "courseName": "Bad Math",
+ "courseId": 5659598665023488,
+ "PersonalTasks": [
+ {
+ "grade": 12,
+ "isPersonal": true,
+ "dueDate": {
+ "year": 2010,
+ "day": 4,
+ "month": 2
+ },
+ "courseId": 5659598665023488,
+ "title": "new task1",
+ "description": "pls fddfsdfdsk",
+ "id": 5096648711602176
+ },
+ {
+ "grade": 12,
+ "isPersonal": true,
+ "dueDate": {
+ "year": 2010,
+ "day": 4,
+ "month": 2
+ },
+ "courseId": 5659598665023488,
+ "title": "new task4",
+ "description": "pls fddfsdfdsk",
+ "id": 5167017455779840
+ }
+ ],
+ "projectTasks": [
+ {
+ "grade": 12,
+ "isPersonal": false,
+ "dueDate": {
+ "year": 2010,
+ "day": 4,
+ "month": 2
+ },
+ "courseId": 5659598665023488,
+ "title": "new task3",
+ "description": "pls fddfsdfdsk",
+ "id": 5237386199957504
+ }
+ ]
+ }
+ ]

"""