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 737cc21..5942b85 100644
--- a/SE_API/MessageRoutes.py
+++ b/SE_API/MessageRoutes.py
@@ -1,3 +1,5 @@
+import copy
+
__author__ = 'Aran'
from flask import Blueprint
@@ -52,13 +54,6 @@ def createMessage(token):
{
'groupId' : 123456789,
'message' : 'Class is canceled',
- 'date' : {
- 'year': 2015,
- 'month': 3,
- 'day': 14,
- 'hour': 16,
- 'minute': 53
- },
'isProject' : true
}
@@ -252,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
@@ -262,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
diff --git a/SE_API/TaskRoutes.py b/SE_API/TaskRoutes.py
index 2dd7a06..ee3bee6 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 *
@@ -48,7 +49,7 @@ def create_task(token):
- JSON Object, Example:
{
"title":"task1",
- "courseName":"aran",
+ "courseId":1234567890,
"description":"pls fddfsdfdsk",
"dueDate":{"year":2010,
"month":2,
@@ -87,47 +88,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 +139,9 @@ def create_task(token):
db.put(component)
db.save
- return created()
+ return Response(response=task.to_JSON(),
+ status=200,
+ mimetype="application/json")
#----------------------------------------------------------
@@ -351,6 +351,211 @@ 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:
+ [
+ {
+ "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
+ }
+ ]
+ }
+ ]
+
+
+ """
+ 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)