Merge branch 'master' of https://github.com/sagidayan/SE-Hub into UI
This commit is contained in:
commit
1ec0a41463
6 changed files with 176 additions and 78 deletions
|
@ -208,7 +208,8 @@ def login():
|
||||||
|
|
||||||
debug = True # Change In Production
|
debug = True # Change In Production
|
||||||
if debug:
|
if debug:
|
||||||
counter = 300
|
import random
|
||||||
|
counter = random.randrange(300,400)
|
||||||
|
|
||||||
@auto.doc()
|
@auto.doc()
|
||||||
@app.route('/debug/login')
|
@app.route('/debug/login')
|
||||||
|
|
|
@ -145,7 +145,9 @@ def joinProject(token, projectId):
|
||||||
return bad_request("User is already member in Project")
|
return bad_request("User is already member in Project")
|
||||||
|
|
||||||
project.membersId.append(str(user.key().id()))
|
project.membersId.append(str(user.key().id()))
|
||||||
|
user.projects_id_list.append(str(project.key().id()))
|
||||||
|
|
||||||
|
db.put(user)
|
||||||
db.put(project)
|
db.put(project)
|
||||||
db.save
|
db.save
|
||||||
|
|
||||||
|
@ -370,12 +372,22 @@ def deleteProject(token,projectId):
|
||||||
if p is None:
|
if p is None:
|
||||||
return bad_request("no such Project")
|
return bad_request("no such Project")
|
||||||
|
|
||||||
if p.master_id == user.key().id():
|
if p.master_id != user.key().id():
|
||||||
db.delete(p)
|
return forbidden("user is not owner of Project")
|
||||||
db.save
|
|
||||||
return accepted("Project deleted")
|
#remove all users related to project
|
||||||
|
for uId in p.membersId:
|
||||||
|
user = User.get_by_id(uId)
|
||||||
|
if user is None:
|
||||||
|
return bad_request("trying to remove a user from project failed")
|
||||||
|
user.projects_id_list.remove(p.key().id())
|
||||||
|
db.put(user)
|
||||||
|
|
||||||
|
|
||||||
|
db.delete(p)
|
||||||
|
db.save
|
||||||
|
return accepted("Project deleted")
|
||||||
|
|
||||||
return forbidden("user is not owner of Project")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -218,9 +218,9 @@ def getAllTasksByCourse(token, courseId):
|
||||||
return no_content()
|
return no_content()
|
||||||
|
|
||||||
|
|
||||||
@task_routes.route('/api/tasks/getAllFutureTasks/<string:token>/<string:courseId>', methods=["GET"])
|
@task_routes.route('/api/tasks/getAllFutureCampusTasks/<string:token>/<string:courseId>', methods=["GET"])
|
||||||
@auto.doc()
|
@auto.doc()
|
||||||
def getAllFutureTasks(token, courseId):
|
def getAllFutureCampusTasks(token, courseId):
|
||||||
"""
|
"""
|
||||||
<span class="card-title">>This Call will return an array of all Future Tasks in a course, ordered by date</span>
|
<span class="card-title">>This Call will return an array of all Future Tasks in a course, ordered by date</span>
|
||||||
<br>
|
<br>
|
||||||
|
@ -284,6 +284,73 @@ def getAllFutureTasks(token, courseId):
|
||||||
else:
|
else:
|
||||||
return no_content()
|
return no_content()
|
||||||
|
|
||||||
|
@task_routes.route('/api/tasks/getAllFutureTasks/<string:token>', methods=["GET"])
|
||||||
|
@auto.doc()
|
||||||
|
def getAllFutureTasks(token):
|
||||||
|
"""
|
||||||
|
<span class="card-title">>This Call will return an array of all Future Tasks ordered by date</span>
|
||||||
|
<br>
|
||||||
|
<b>Route Parameters</b><br>
|
||||||
|
- SeToken: token<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<b>Payload</b><br>
|
||||||
|
- NONE
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<b>Response</b>
|
||||||
|
<br>
|
||||||
|
200 - JSON Example:<br>
|
||||||
|
<code>
|
||||||
|
{<br>
|
||||||
|
'title' : 'Task1',<br>
|
||||||
|
'courseName' : 'advance Math',<br>
|
||||||
|
'description' : 'prepare by sunday',<br>
|
||||||
|
'dueDate' : {
|
||||||
|
'year' : 2015,
|
||||||
|
'month' : 12,
|
||||||
|
'day' : 23
|
||||||
|
}<br>
|
||||||
|
'isPersonal' : true,<br>
|
||||||
|
'task_id' : 589689456894<br>
|
||||||
|
}<br>
|
||||||
|
</code>
|
||||||
|
<br>
|
||||||
|
"""
|
||||||
|
|
||||||
|
user = get_user_by_token
|
||||||
|
if user is None:
|
||||||
|
return bad_request("Bad User Token")
|
||||||
|
|
||||||
|
arr = []
|
||||||
|
|
||||||
|
for courseId in user.courses_id_list:
|
||||||
|
query = Task.all()
|
||||||
|
|
||||||
|
try:
|
||||||
|
query.filter("courseId = ", int(courseId))
|
||||||
|
except Exception as e:
|
||||||
|
return bad_request("Bad id format")
|
||||||
|
|
||||||
|
for t in query.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'])
|
||||||
|
if taskTime >= datetime.date.today():
|
||||||
|
taskDic['forSortDate'] = taskTime
|
||||||
|
arr.append(taskDic)
|
||||||
|
|
||||||
|
#sort array by date, and remove added key
|
||||||
|
arr = sorted(arr, key=itemgetter('forSortDate'), reverse=False)
|
||||||
|
for i in arr:
|
||||||
|
del i['forSortDate']
|
||||||
|
|
||||||
|
if len(arr) != 0:
|
||||||
|
return Response(response=json.dumps(arr),
|
||||||
|
status=200,
|
||||||
|
mimetype="application/json")
|
||||||
|
else:
|
||||||
|
return no_content()
|
||||||
|
|
||||||
|
|
||||||
@task_routes.route('/api/tasks/getTaskComponents/<string:token>/<string:taskId>', methods=["GET"])
|
@task_routes.route('/api/tasks/getTaskComponents/<string:token>/<string:taskId>', methods=["GET"])
|
||||||
|
@ -353,7 +420,7 @@ def getTaskComponents(token, taskId):
|
||||||
|
|
||||||
@task_routes.route('/api/tasks/getAllUserTasks/<string:token>', methods=["GET"])
|
@task_routes.route('/api/tasks/getAllUserTasks/<string:token>', methods=["GET"])
|
||||||
@auto.doc()
|
@auto.doc()
|
||||||
def getAllTasksByUser(token):
|
def getAllUserTasks(token):
|
||||||
"""
|
"""
|
||||||
<span class="card-title">>This Call will return an array of all of the User's Tasks</span>
|
<span class="card-title">>This Call will return an array of all of the User's Tasks</span>
|
||||||
<br>
|
<br>
|
||||||
|
@ -491,70 +558,81 @@ def getAllTasksByUser(token):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# @task_routes.route('/api/tasks/getUserFullTasksById/<string:token>/<string:taskId>', methods=["GET"])
|
@task_routes.route('/api/tasks/getUserTaskById/<string:token>/<string:taskId>', methods=["GET"])
|
||||||
# @auto.doc()
|
@auto.doc()
|
||||||
# def getFullTasksById(token, taskId):
|
def getUserTaskById(token, taskId):
|
||||||
# """
|
"""
|
||||||
# <span class="card-title">>This Call will return an array of all components for a given task</span>
|
<span class="card-title">>This Call will return an array of all components for a given task</span>
|
||||||
# <br>
|
<br>
|
||||||
# <b>Route Parameters</b><br>
|
<b>Route Parameters</b><br>
|
||||||
# - SeToken: token<br>
|
- SeToken: token<br>
|
||||||
# - taskId: 1234567890
|
- taskId: 1234567890
|
||||||
# <br>
|
<br>
|
||||||
# <br>
|
<br>
|
||||||
# <b>Payload</b><br>
|
<b>Payload</b><br>
|
||||||
# - NONE
|
- NONE
|
||||||
# <br>
|
<br>
|
||||||
# <br>
|
<br>
|
||||||
# <b>Response</b>
|
<b>Response</b>
|
||||||
# <br>
|
<br>
|
||||||
# 200 - JSON Example:<br>
|
200 - JSON Example:<br>
|
||||||
# <code>
|
<code>
|
||||||
# [
|
[
|
||||||
# {<br>
|
{<br>
|
||||||
# 'taskId' : 7589454894,
|
'taskId' : 7589454894,
|
||||||
# 'userId' : -1,
|
'userId' : -1,
|
||||||
# 'type' : 'kindOfType',
|
'type' : 'kindOfType',
|
||||||
# 'label' : 'kindOfLabel',
|
'label' : 'kindOfLabel',
|
||||||
# 'isMandatory' : true,
|
'isMandatory' : true,
|
||||||
# 'order' : 2
|
'order' : 2
|
||||||
# }<br>
|
}<br>
|
||||||
# {<br>
|
{<br>
|
||||||
# 'taskId' : 7589454894,
|
'taskId' : 7589454894,
|
||||||
# 'userId' : yossi,
|
'userId' : yossi,
|
||||||
# 'type' : 'otherKindOfType',
|
'type' : 'otherKindOfType',
|
||||||
# 'label' : 'otherKindOfLabel',
|
'label' : 'otherKindOfLabel',
|
||||||
# 'isMandatory' : false,
|
'isMandatory' : false,
|
||||||
# 'order' : 4
|
'order' : 4
|
||||||
# }<br>
|
}<br>
|
||||||
# ]
|
]
|
||||||
# </code>
|
</code>
|
||||||
# <br>
|
<br>
|
||||||
# """
|
"""
|
||||||
# user = get_user_by_token(token)
|
user = get_user_by_token(token)
|
||||||
# if user is None:
|
if user is None:
|
||||||
# return bad_request("Bad User Token")
|
return bad_request("Bad User Token")
|
||||||
#
|
|
||||||
# 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")
|
||||||
#
|
|
||||||
# taskCompQuery = TaskComponent.all()
|
|
||||||
# taskCompQuery.filter("taskId = ", task.key().id())
|
taskCompQuery = TaskComponent.all()
|
||||||
#
|
taskCompQuery.filter("taskId = ", task.key().id())
|
||||||
# if task.isPersonal:
|
|
||||||
# taskCompQuery.filter("userId = ", user.key().id())
|
if task.isPersonal:
|
||||||
# else:
|
taskCompQuery.filter("userId = ", user.key().id())
|
||||||
# taskCompQuery.filter("userId = ", user.key().id())
|
else:
|
||||||
#
|
taskCompQuery.filter("userId = ", user.key().id())#TODO: fix to project
|
||||||
# if taskCompQuery.count() == 0:
|
|
||||||
# #create componenets and Score for user
|
#check if never created a personalized task and if so, create it
|
||||||
#
|
if taskCompQuery.count() == 0:
|
||||||
#
|
taskCompQuery = TaskComponent.all().filter("taskId = ", task.key().id()).filter("userId = ", -1)
|
||||||
# for i in taskCompQuery.run():
|
for tc in taskCompQuery.run():
|
||||||
# print i.to_JSON()
|
tcNew = TaskComponent(taskId=tc.taskId, userId=user.key().id(), type=tc.type, label=tc.label, isMandatory=tc.isMandatory, order=tc.order)
|
||||||
#
|
db.put(tcNew)
|
||||||
# return no_content()
|
|
||||||
|
grade = TaskGrade(grade=0, taskId=task.key().id(), userId=user.key().id())
|
||||||
|
db.put(grade)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
db.save
|
||||||
|
return no_content()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -322,16 +322,15 @@ def getUserById(token, id):
|
||||||
if u is None:
|
if u is None:
|
||||||
return no_content('No user Found')
|
return no_content('No user Found')
|
||||||
|
|
||||||
|
|
||||||
for index, c in enumerate(u.campuses_id_list):
|
for index, c in enumerate(u.campuses_id_list):
|
||||||
c = json.loads(Campus.get_by_id(int(c)).to_JSON())
|
c = json.loads(Campus.get_by_id(int(c)).to_JSON())
|
||||||
u.campuses_id_list[index] = c
|
u.campuses_id_list[index] = c
|
||||||
|
|
||||||
return Response(response=u.to_JSON(),
|
return Response(response=u.to_JSON(),
|
||||||
status=200,
|
status=200,
|
||||||
mimetype="application/json") # Real response!
|
mimetype="application/json") # Real response!
|
||||||
|
|
||||||
return no_content("No User Found")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@user_routes.route('/api/users/getUsersByCampus/<string:token>/<string:campusId>', methods=["GET"])
|
@user_routes.route('/api/users/getUsersByCampus/<string:token>/<string:campusId>', methods=["GET"])
|
||||||
|
@ -579,6 +578,7 @@ def removeUserFromCampus(token, userId, campusId):
|
||||||
if requestingUser.key().id() != userToRemove.key().id():
|
if requestingUser.key().id() != userToRemove.key().id():
|
||||||
return forbidden("No permission to delete user")
|
return forbidden("No permission to delete user")
|
||||||
|
|
||||||
|
#remove campus from user campus list
|
||||||
try:
|
try:
|
||||||
userToRemove.campuses_id_list.remove(campusId)
|
userToRemove.campuses_id_list.remove(campusId)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -646,6 +646,13 @@ def removeUserFromCourse(token, userId, courseId):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return bad_request("user is not listed to this course")
|
return bad_request("user is not listed to this course")
|
||||||
|
|
||||||
|
#remove user from all projects in course
|
||||||
|
projects = Project.all().filter("courseId =", course.key().id())
|
||||||
|
for p in projects:
|
||||||
|
if p.key().id() in userToRemove.projects_id_list:
|
||||||
|
userToRemove.projects_id_list.remove(p.key().id())
|
||||||
|
p.membersId.remove(userToRemove.key().id())
|
||||||
|
db.put(p)
|
||||||
|
|
||||||
|
|
||||||
db.put(userToRemove)
|
db.put(userToRemove)
|
||||||
|
|
|
@ -8,7 +8,7 @@ from models.Course import Course
|
||||||
|
|
||||||
class Message(db.Model):
|
class Message(db.Model):
|
||||||
groupId = db.IntegerProperty(required=True)
|
groupId = db.IntegerProperty(required=True)
|
||||||
message = db.StringProperty(required=True)
|
message = db.StringProperty(required=True, multiline=True)
|
||||||
msgDate = db.DateTimeProperty(required=True)
|
msgDate = db.DateTimeProperty(required=True)
|
||||||
master_id = db.IntegerProperty(required=True)
|
master_id = db.IntegerProperty(required=True)
|
||||||
isProject = db.BooleanProperty(default=False)
|
isProject = db.BooleanProperty(default=False)
|
||||||
|
|
|
@ -15,7 +15,7 @@ class Task(db.Model):
|
||||||
data = {'title' : self.title,
|
data = {'title' : self.title,
|
||||||
'courseId' : self.courseId,
|
'courseId' : self.courseId,
|
||||||
'description' : self.description,
|
'description' : self.description,
|
||||||
'dueDate' : {
|
'dueDate' : {
|
||||||
'year': self.dueDate.year,
|
'year': self.dueDate.year,
|
||||||
'month': self.dueDate.month,
|
'month': self.dueDate.month,
|
||||||
'day': self.dueDate.day
|
'day': self.dueDate.day
|
||||||
|
|
Loading…
Reference in a new issue