Merge branch 'master' of https://github.com/sagidayan/SE-Hub into UI
This commit is contained in:
commit
a702ae9df2
17 changed files with 840 additions and 25 deletions
|
@ -29,6 +29,7 @@ from SE_API.UserRoutes import user_routes
|
|||
from SE_API.CampusRoutes import campus_routes
|
||||
from SE_API.CourseRoutes import course_routes
|
||||
from SE_API.ProjectRoutes import project_routes
|
||||
from SE_API.TaskRoutes import task_routes
|
||||
|
||||
|
||||
|
||||
|
@ -49,6 +50,7 @@ app.register_blueprint(user_routes)
|
|||
app.register_blueprint(campus_routes)
|
||||
app.register_blueprint(course_routes)
|
||||
app.register_blueprint(project_routes)
|
||||
app.register_blueprint(task_routes)
|
||||
|
||||
auto = Autodoc(app)
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ def create_campus(token):
|
|||
<br>
|
||||
<b>Response</b>
|
||||
<br>
|
||||
201 - Created
|
||||
200 - OK
|
||||
<br>
|
||||
403 - Invalid Token/Forbidden
|
||||
"""
|
||||
|
@ -66,7 +66,7 @@ def create_campus(token):
|
|||
#check if name already exists
|
||||
try:
|
||||
query = Campus.all()
|
||||
query.filter("title = ", payload['title'])
|
||||
query.filter("title =", payload['title'])
|
||||
for c in query.run(limit=1):
|
||||
return forbidden("Campus with same name already exists")
|
||||
except Exception as e:
|
||||
|
@ -86,7 +86,6 @@ def create_campus(token):
|
|||
|
||||
|
||||
|
||||
|
||||
@campus_routes.route('/api/campuses/getAll/<string:token>', methods=['GET'])
|
||||
@auto.doc()
|
||||
def get_campuses(token):
|
||||
|
@ -109,7 +108,8 @@ def get_campuses(token):
|
|||
'title': 'JCE',<br>
|
||||
'email_ending': '@post.jce.ac.il',<br>
|
||||
'master_user_id': 123453433341, (User that created the campus)<br>
|
||||
'avatar_url': 'http://some.domain.com/imagefile.jpg'<br>
|
||||
'avatar_url': 'http://some.domain.com/imagefile.jpg',<br>
|
||||
'id' : 1234567890<br>
|
||||
},<br>
|
||||
....<br>
|
||||
{<br>
|
||||
|
@ -124,7 +124,11 @@ def get_campuses(token):
|
|||
query = Campus.all()
|
||||
for c in query.run():
|
||||
arr.append(dict(json.loads(c.to_JSON())))
|
||||
print "ARR:"
|
||||
print arr
|
||||
for c in arr:
|
||||
print"c:"
|
||||
print c
|
||||
if len(arr) != 0:
|
||||
return Response(response=json.dumps(arr),
|
||||
status=200,
|
||||
|
@ -138,6 +142,55 @@ def get_campuses(token):
|
|||
|
||||
|
||||
|
||||
@campus_routes.route('/api/campuses/deleteCampus/<string:token>/<string:campusid>', methods=['DELETE'])
|
||||
@auto.doc()
|
||||
def deleteCampus(token,campusid):
|
||||
"""
|
||||
<span class="card-title">This Call will delete a specific campus</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- seToken: 'seToken'
|
||||
- campusid: 'campusid'
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
- NONE <br>
|
||||
<br>
|
||||
<br>
|
||||
<b>Response</b>
|
||||
<br>
|
||||
202 - Deleted campus
|
||||
<br>
|
||||
....<br>
|
||||
{<br>
|
||||
...<br>
|
||||
}req<br>
|
||||
|
||||
]<br>
|
||||
400 - no such campus
|
||||
<br>
|
||||
403 - Invalid token or not a lecturer or lecturer is not owner of campus!<br>
|
||||
"""
|
||||
|
||||
if not is_lecturer(token): #todo: change to lecturer id
|
||||
return forbidden("Invalid token or not a lecturer!")
|
||||
|
||||
user = get_user_by_token(token)
|
||||
camp = Campus.get_by_id(int(campusid))
|
||||
|
||||
if camp is None:
|
||||
return bad_request("no such campus")
|
||||
|
||||
|
||||
if camp.master_user_id == user.key().id():
|
||||
db.delete(camp)
|
||||
db.save
|
||||
return accepted("campus deleted")
|
||||
|
||||
return forbidden("lecturer is not owner of campus")
|
||||
|
||||
|
||||
|
||||
@campus_routes.route('/api/campuses/help')
|
||||
def documentation():
|
||||
return auto.html()
|
||||
|
|
|
@ -7,6 +7,8 @@ from GithubAPI.GithubAPI import GitHubAPI_Keys
|
|||
from google.appengine.ext import db
|
||||
import requests
|
||||
import datetime
|
||||
from operator import itemgetter
|
||||
|
||||
|
||||
from flask import Flask, request, render_template, redirect, abort, Response
|
||||
|
||||
|
@ -16,6 +18,8 @@ from flask.ext.autodoc import Autodoc
|
|||
|
||||
# DB Models
|
||||
from models.Course import Course
|
||||
from models.Campus import Campus
|
||||
from models.Message import Message
|
||||
|
||||
#Validation Utils Libs
|
||||
from SE_API.Validation_Utils import *
|
||||
|
@ -27,6 +31,10 @@ course_routes = Blueprint("course_routes", __name__)
|
|||
auto = Autodoc()
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------
|
||||
# POST
|
||||
#----------------------------------------------------------
|
||||
@course_routes.route('/api/courses/create/<string:token>', methods=['POST'])
|
||||
@auto.doc()
|
||||
def create_course(token):
|
||||
|
@ -92,8 +100,6 @@ def create_course(token):
|
|||
print e
|
||||
return bad_request()
|
||||
|
||||
|
||||
|
||||
db.put(course)
|
||||
db.save
|
||||
return Response(response=course.to_JSON(),
|
||||
|
@ -102,6 +108,63 @@ def create_course(token):
|
|||
|
||||
|
||||
|
||||
|
||||
@course_routes.route('/api/courses/createMessage/<string:token>', methods=['POST'])
|
||||
@auto.doc()
|
||||
def createMessage(token):
|
||||
"""
|
||||
<span class="card-title">This call will create a new Message in the DB</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- seToken: 'seToken'
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
- JSON Object, Example: <br>
|
||||
{<br>
|
||||
'courseName': 'Advance Math',<br>
|
||||
'message': 'The lecture today is canceled'<br>
|
||||
}<br>
|
||||
<br>
|
||||
<br>
|
||||
<b>Response</b>
|
||||
<br>
|
||||
201 - Created
|
||||
<br>
|
||||
400 - Bad Request
|
||||
<br>
|
||||
403 - Invalid token or not a lecturer
|
||||
"""
|
||||
if not request.data:
|
||||
return bad_request("no 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)
|
||||
|
||||
#try to parse payload
|
||||
try:
|
||||
payload = json.loads(request.data)
|
||||
except Exception as e:
|
||||
return bad_request("here")
|
||||
|
||||
try:
|
||||
msg = Message(courseName=payload['courseName'], message=payload['message'], msgDate=datetime.datetime.now())
|
||||
except Exception as e:
|
||||
print e
|
||||
return bad_request("there")
|
||||
|
||||
db.save(msg)
|
||||
db.save
|
||||
return created()
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------
|
||||
# GET
|
||||
#----------------------------------------------------------
|
||||
|
||||
|
||||
@course_routes.route('/api/courses/getCourseByCampusName/<string:name>', methods=["GET"])
|
||||
@auto.doc()
|
||||
def getCourseByCampusName(name):
|
||||
|
@ -126,13 +189,15 @@ def getCourseByCampusName(name):
|
|||
'startDate': '2015-14-3'<br>
|
||||
'endDate': '2015-29-6'<br>
|
||||
'taskFlag': 'False'<br>
|
||||
'id' : 1234567890<br>
|
||||
|
||||
}
|
||||
</code>
|
||||
<br>
|
||||
"""
|
||||
arr = []
|
||||
query = Course.all()
|
||||
query.filter("campusName = ", name)
|
||||
query.filter("campusName=", name)
|
||||
|
||||
for c in query.run():
|
||||
arr.append(dict(json.loads(c.to_JSON())))
|
||||
|
@ -146,6 +211,184 @@ def getCourseByCampusName(name):
|
|||
status=200,
|
||||
mimetype="application/json")
|
||||
|
||||
@course_routes.route('/api/courses/getMessagesByCourseName/<string:name>', methods=["GET"])
|
||||
@auto.doc()
|
||||
def getMessagesByCourseName(name):
|
||||
"""
|
||||
<span class="card-title">>This Call will return an array of all courses in a given campus</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- name: 'campus name'
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
- NONE
|
||||
<br>
|
||||
<br>
|
||||
<b>Response</b>
|
||||
<br>
|
||||
200 - JSON Example:<br>
|
||||
<code>
|
||||
{<br>
|
||||
'courseName': 'Advance Math',<br>
|
||||
'campusName': 'JCE',<br>
|
||||
'startDate': '2015-14-3'<br>
|
||||
'endDate': '2015-29-6'<br>
|
||||
'taskFlag': false,<br>
|
||||
'id' : 1234567890<br>
|
||||
|
||||
}
|
||||
</code>
|
||||
<br>
|
||||
"""
|
||||
arr = []
|
||||
query = Message.all()
|
||||
query.filter("courseName = ", name)
|
||||
|
||||
for m in query.run():
|
||||
msgDic = dict(json.loads(m.to_JSON()))
|
||||
#add a key 'forSortDate' for sorting dates
|
||||
msgTime = datetime.datetime(msgDic['date']['year'], msgDic['date']['month'], msgDic['date']['day'], msgDic['date']['hour'], msgDic['date']['minute'])
|
||||
msgDic['forSortDate'] = msgTime
|
||||
arr.append(msgDic)
|
||||
|
||||
arr = sorted(arr, key=itemgetter('forSortDate'), reverse=False)
|
||||
for i in arr:
|
||||
del i['forSortDate']
|
||||
print arr
|
||||
|
||||
if len(arr) != 0:
|
||||
return Response(response=json.dumps(arr),
|
||||
status=200,
|
||||
mimetype="application/json")
|
||||
else:
|
||||
return Response(response=[],
|
||||
status=200,
|
||||
mimetype="application/json")
|
||||
|
||||
#----------------------------------------------------------
|
||||
# PUT
|
||||
#----------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------
|
||||
# DELETE
|
||||
#----------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@course_routes.route('/api/courses/deleteCourse/<string:token>/<string:courseid>', methods=['DELETE'])
|
||||
@auto.doc()
|
||||
def deleteCourse(token,courseid):
|
||||
"""
|
||||
<span class="card-title">This Call will delete a specific Course</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- seToken: 'seToken'
|
||||
- courseid: 'courseid'
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
- NONE <br>
|
||||
<br>
|
||||
<br>
|
||||
<b>Response</b>
|
||||
<br>
|
||||
202 - Deleted Course
|
||||
<br>
|
||||
....<br>
|
||||
{<br>
|
||||
...<br>
|
||||
}req<br>
|
||||
|
||||
]<br>
|
||||
400 - no such Course
|
||||
<br>
|
||||
403 - Invalid token or not a lecturer or lecturer is not owner of Course!<br>
|
||||
"""
|
||||
|
||||
if not is_lecturer(token): #todo: change to lecturer id
|
||||
return forbidden("Invalid token or not a lecturer!")
|
||||
|
||||
user = get_user_by_token(token)
|
||||
c = Course.get_by_id(int(courseid))
|
||||
|
||||
if c is None:
|
||||
return bad_request("no such course")
|
||||
|
||||
|
||||
if c.master_id == user.key().id():
|
||||
db.delete(c)
|
||||
db.save
|
||||
return accepted("course deleted")
|
||||
|
||||
return forbidden("lecturer is not owner of course")
|
||||
|
||||
|
||||
@course_routes.route('/api/courses/deleteCoursesByCampus/<string:token>/<string:campusName>', methods=['DELETE'])
|
||||
@auto.doc()
|
||||
def deleteCoursesByCampus(token,campusName):
|
||||
"""
|
||||
<span class="card-title">This Call will delete a specific campus's courses</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- seToken: 'seToken'
|
||||
- title: 'campusName'
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
- NONE <br>
|
||||
<br>
|
||||
<br>
|
||||
<b>Response</b>
|
||||
<br>
|
||||
202 - Deleted campus
|
||||
<br>
|
||||
204 - No Matching Campus Found
|
||||
<br>
|
||||
....<br>
|
||||
{<br>
|
||||
...<br>
|
||||
}req<br>
|
||||
|
||||
]<br>
|
||||
400 - Bad Request
|
||||
<br>
|
||||
403 - Invalid token or not a lecturer!<br>
|
||||
"""
|
||||
|
||||
if not is_lecturer(token): #todo: change to lecturer id
|
||||
return forbidden("Invalid token or not a lecturer!")
|
||||
|
||||
|
||||
user = get_user_by_token(token)
|
||||
campus = get_campus_by_campusName(campusName)
|
||||
if campus is None:
|
||||
return bad_request("Not a campus!")
|
||||
|
||||
#check user is owner of campus
|
||||
if campus.master_user_id != user.key().id():
|
||||
return forbidden("lecturer is not owner of campus!")
|
||||
|
||||
query = Course.all()
|
||||
|
||||
try:
|
||||
query.filter('campusName =', campusName)
|
||||
except Exception as e:
|
||||
print e
|
||||
return bad_request("invalid course title attribute")
|
||||
|
||||
for c in query.run():
|
||||
db.delete(c)
|
||||
db.save
|
||||
|
||||
return no_content()
|
||||
|
||||
|
||||
@course_routes.route('/api/courses/help')
|
||||
def documentation():
|
||||
|
|
|
@ -41,7 +41,7 @@ def create_project(token):
|
|||
{<br>
|
||||
'projectName': 'Advance Math',<br>
|
||||
'courseName': 'JCE',<br>
|
||||
'logo_url': 'http://location.domain.com/image.jpg'<br>
|
||||
'logo_url': 'http://location.domain.com/image.jpg',<br>
|
||||
'gitRepository': 'http://location.git.com/somthing'<br>
|
||||
}<br>
|
||||
<br>
|
||||
|
@ -57,10 +57,12 @@ def create_project(token):
|
|||
if not request.data:
|
||||
return bad_request()
|
||||
payload = json.loads(request.data)
|
||||
if not is_lecturer(token): #todo: change to lecturer id
|
||||
return forbidden("Invalid token or not a lecturer!")
|
||||
#if not is_lecturer(token): #todo: change to lecturer id
|
||||
# return forbidden("Invalid token or not a lecturer!")
|
||||
|
||||
user = get_user_by_token(token)
|
||||
if user is None:
|
||||
return bad_request("Wrong user Token")
|
||||
|
||||
#todo: check legality
|
||||
|
||||
|
@ -104,7 +106,8 @@ def getProjectsByCourseName(name):
|
|||
'grade': 98,<br>
|
||||
'logo_url': 'http://location.domain.com/image.jpg',<br>
|
||||
'gitRepository': 'http://location.git.com/somthing',<br>
|
||||
'membersId': ['bob', 'dylan', 'quentin', 'terentino']<br>
|
||||
'membersId': ['bob', 'dylan', 'quentin', 'terentino'],<br>
|
||||
'id' : 1234567890<br>
|
||||
}
|
||||
</code>
|
||||
<br>
|
||||
|
@ -128,6 +131,53 @@ def getProjectsByCourseName(name):
|
|||
|
||||
|
||||
|
||||
@project_routes.route('/api/projects/deleteProject/<string:token>/<string:projectid>', methods=['DELETE'])
|
||||
@auto.doc()
|
||||
def deleteProject(token,projectid):
|
||||
"""
|
||||
<span class="card-title">This Call will delete a specific Project</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- seToken: 'seToken'
|
||||
- courseid: 'projectid'
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
- NONE <br>
|
||||
<br>
|
||||
<br>
|
||||
<b>Response</b>
|
||||
<br>
|
||||
202 - Deleted Project
|
||||
<br>
|
||||
....<br>
|
||||
{<br>
|
||||
...<br>
|
||||
}req<br>
|
||||
|
||||
]<br>
|
||||
400 - no such Project
|
||||
<br>
|
||||
403 - Invalid token or not the owner of Project!<br>
|
||||
"""
|
||||
|
||||
# if not is_lecturer(token): #todo: change to lecturer id
|
||||
# return forbidden("Invalid token or not a lecturer!")
|
||||
|
||||
user = get_user_by_token(token)
|
||||
p = Project.get_by_id(int(projectid))
|
||||
|
||||
if p is None:
|
||||
return bad_request("no such Project")
|
||||
|
||||
if p.master_id == user.key().id():
|
||||
db.delete(p)
|
||||
db.save
|
||||
return accepted("Project deleted")
|
||||
|
||||
return forbidden("user is not owner of Project")
|
||||
|
||||
|
||||
|
||||
@project_routes.route('/api/projects/help')
|
||||
def documentation():
|
||||
|
|
324
SE_API/TaskRoutes.py
Normal file
324
SE_API/TaskRoutes.py
Normal file
|
@ -0,0 +1,324 @@
|
|||
__author__ = 'Aran'
|
||||
|
||||
from flask import Blueprint
|
||||
import json
|
||||
from GithubAPI.GithubAPI import GitHubAPI_Keys
|
||||
|
||||
from google.appengine.ext import db
|
||||
import requests
|
||||
import datetime
|
||||
from operator import itemgetter
|
||||
|
||||
from flask import Flask, request, render_template, redirect, abort, Response
|
||||
|
||||
from flask.ext.github import GitHub
|
||||
from flask.ext.cors import CORS, cross_origin
|
||||
from flask.ext.autodoc import Autodoc
|
||||
|
||||
# DB Models
|
||||
from models.Task import Task
|
||||
from models.Course import Course
|
||||
from models.TaskComponent import TaskComponent
|
||||
|
||||
#Validation Utils Libs
|
||||
from SE_API.Validation_Utils import *
|
||||
from SE_API.Respones_Utils import *
|
||||
|
||||
|
||||
|
||||
|
||||
task_routes = Blueprint("task_routes", __name__)
|
||||
auto = Autodoc()
|
||||
|
||||
@task_routes.route('/api/tasks/create/<string:token>', methods=['POST'])
|
||||
@auto.doc()
|
||||
def create_task(token):
|
||||
"""
|
||||
<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>
|
||||
"courseName":"aran",<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
|
||||
"""
|
||||
if not request.data:
|
||||
return bad_request()
|
||||
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
|
||||
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
|
||||
except Exception as e:
|
||||
print e
|
||||
return bad_request()
|
||||
db.put(task)
|
||||
db.save
|
||||
|
||||
#create components
|
||||
for c in payload['components']:
|
||||
try:
|
||||
component = TaskComponent(taskId=task.key().id(), userId=-1, type=c['type'], label=c['label'], isMandatory=c['isMandatory'], order=c['order'])
|
||||
except Exception as e:
|
||||
print e
|
||||
return bad_request("Bad component")
|
||||
db.put(component)
|
||||
db.save
|
||||
|
||||
|
||||
|
||||
return created()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@task_routes.route('/api/tasks/getAllTasks/<string:courseName>', methods=["GET"])
|
||||
@auto.doc()
|
||||
def getAllTasks(courseName):
|
||||
"""
|
||||
<span class="card-title">>This Call will return an array of all Tasks in a course by date</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- name: 'course name'
|
||||
<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>
|
||||
"""
|
||||
|
||||
arr = []
|
||||
query = Task.all()
|
||||
query.filter("courseName = ", courseName)
|
||||
|
||||
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'])
|
||||
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:taskId>', methods=["GET"])
|
||||
@auto.doc()
|
||||
def getTaskComponents(taskId):
|
||||
"""
|
||||
<span class="card-title">>This Call will return an array of all components for a given task</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- taskId: integer
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
- NONE
|
||||
<br>
|
||||
<br>
|
||||
<b>Response</b>
|
||||
<br>
|
||||
200 - JSON Example:<br>
|
||||
<code>
|
||||
[
|
||||
{<br>
|
||||
'taskId' : 7589454894,
|
||||
'userId' : -1,
|
||||
'type' : 'kindOfType',
|
||||
'label' : 'kindOfLabel',
|
||||
'isMandatory' : true,
|
||||
'order' : 2
|
||||
}<br>
|
||||
{<br>
|
||||
'taskId' : 7589454894,
|
||||
'userId' : yossi,
|
||||
'type' : 'otherKindOfType',
|
||||
'label' : 'otherKindOfLabel',
|
||||
'isMandatory' : false,
|
||||
'order' : 4
|
||||
}<br>
|
||||
]
|
||||
</code>
|
||||
<br>
|
||||
"""
|
||||
|
||||
arr = []
|
||||
query = TaskComponent.all()
|
||||
query.filter("taskId = ", taskId)
|
||||
|
||||
for tc in query.run():
|
||||
arr.append(dict(json.loads(tc.to_JSON())))
|
||||
|
||||
#sort array by order, and remove added key
|
||||
arr = sorted(arr, key=itemgetter('order'), reverse=False)
|
||||
|
||||
if len(arr) != 0:
|
||||
return Response(response=json.dumps(arr),
|
||||
status=200,
|
||||
mimetype="application/json")
|
||||
else:
|
||||
return no_content()
|
||||
|
||||
|
||||
|
||||
@task_routes.route('/api/tasks/help')
|
||||
def documentation():
|
||||
return auto.html()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# @task_routes.route('/api/tasks/getClosestTask/<string:courseName>', methods=["GET"])
|
||||
# @auto.doc()
|
||||
# def getClosestTask(courseName):
|
||||
# """
|
||||
# <span class="card-title">>This Call will return an array of all projects in a given course</span>
|
||||
# <br>
|
||||
# <b>Route Parameters</b><br>
|
||||
# - name: 'course name'
|
||||
# <br>
|
||||
# <br>
|
||||
# <b>Payload</b><br>
|
||||
# - NONE
|
||||
# <br>
|
||||
# <br>
|
||||
# <b>Response</b>
|
||||
# <br>
|
||||
# 200 - JSON Example:<br>
|
||||
# <code>
|
||||
# {<br>
|
||||
# 'projectName': 'Advance Math',<br>
|
||||
# 'courseName': 'JCE',<br>
|
||||
# 'grade': 98,<br>
|
||||
# 'logo_url': 'http://location.domain.com/image.jpg',<br>
|
||||
# 'gitRepository': 'http://location.git.com/somthing',<br>
|
||||
# 'membersId': ['bob', 'dylan', 'quentin', 'terentino']<br>
|
||||
# }
|
||||
# </code>
|
||||
# <br>
|
||||
# """
|
||||
# #get all tasks for a specific course
|
||||
# arr = []
|
||||
# query = Task.all()
|
||||
# query.filter("courseName =", courseName)
|
||||
# for t in query.run():
|
||||
# count+=1
|
||||
# if t.dueDate < closestDate:
|
||||
# closestDate = t.dueDate
|
||||
# index = count
|
||||
# arr.append(dict(json.loads(t.to_JSON())))
|
||||
#
|
||||
# print arr
|
||||
# if len(arr) != 0:
|
||||
# return Response(response=json.dumps(arr[index]),
|
||||
# status=200,
|
||||
# mimetype="application/json")
|
||||
# else:
|
||||
# return no_content("no Tasks")
|
||||
#
|
|
@ -13,6 +13,14 @@ def get_user_by_token(token):
|
|||
return u
|
||||
return None
|
||||
|
||||
def get_campus_by_campusName(campusName):
|
||||
query = Campus.all()
|
||||
query.filter("title = ", campusName)
|
||||
|
||||
for u in query.run(limit = 1):
|
||||
return u
|
||||
return None
|
||||
|
||||
def get_campus_by_suffix(suffix):
|
||||
query = Campus.all()
|
||||
query.filter("email_ending = ", suffix)
|
||||
|
|
|
@ -14,7 +14,8 @@ class Campus(db.Model):
|
|||
data = {'title': self.title,
|
||||
'email_ending': self.email_ending,
|
||||
'master_user_id': self.master_user_id,
|
||||
'avatar_url': self.avatar_url
|
||||
'avatar_url': self.avatar_url,
|
||||
'id' : self.key().id()
|
||||
}
|
||||
return json.dumps(data)
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ class Course(db.Model):
|
|||
'year': self.endDate.year,
|
||||
'month': self.endDate.month,
|
||||
'day': self.endDate.day,
|
||||
}
|
||||
}
|
||||
},
|
||||
'id' : self.key().id()
|
||||
}
|
||||
return json.dumps(data)
|
||||
|
|
24
models/Message.py
Normal file
24
models/Message.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
import json
|
||||
|
||||
__author__ = 'Aran'
|
||||
from google.appengine.ext import db
|
||||
|
||||
class Message(db.Model):
|
||||
courseName = db.StringProperty(required=True)
|
||||
message = db.StringProperty(required=True)
|
||||
msgDate = db.DateTimeProperty(required=True)
|
||||
|
||||
def to_JSON(self):
|
||||
data = {
|
||||
'courseName' : self.courseName,
|
||||
'message' : self.message,
|
||||
'date' : {
|
||||
'year': self.msgDate.year,
|
||||
'month': self.msgDate.month,
|
||||
'day': self.msgDate.day,
|
||||
'hour': self.msgDate.hour,
|
||||
'minute': self.msgDate.minute
|
||||
},
|
||||
'id' : self.key().id()
|
||||
}
|
||||
return json.dumps(data)
|
|
@ -20,5 +20,6 @@ class Project(db.Model):
|
|||
'logo_url' : self.logo_url,
|
||||
'gitRepository' : self.gitRepository,
|
||||
'membersId' : self.membersId,
|
||||
'id' : self.key().id()
|
||||
}
|
||||
return json.dumps(data)
|
||||
|
|
|
@ -1,24 +1,27 @@
|
|||
import json
|
||||
|
||||
import time
|
||||
__author__ = 'Aran'
|
||||
from google.appengine.ext import db
|
||||
|
||||
|
||||
class Task(db.Model):
|
||||
title = db.StringProperty(required=True)
|
||||
description = db.StringProperty(required=True)
|
||||
courseName = db.StringProperty(required=True)
|
||||
description = db.StringProperty(required=True,default=" ")
|
||||
dueDate = db.DateProperty(required=True)
|
||||
isProject = db.BooleanProperty(required=True)
|
||||
isClose = db.BooleanProperty(required=True)
|
||||
isDone = db.BooleanProperty(required=True)
|
||||
taskGrade = db.IntegerProperty(required=True)
|
||||
isPersonal = db.BooleanProperty(required=True, default=True)
|
||||
|
||||
def to_JSON(self):
|
||||
data = {'title' : self.title,
|
||||
'courseName' : self.courseName,
|
||||
'description' : self.description,
|
||||
'dueDate' : self.dueDate,
|
||||
'isProject' : self.isProject,
|
||||
'isClose' : self.membersId,
|
||||
'isDone' : self.isDone,
|
||||
'taskGrade' : self.taskGrade,
|
||||
'dueDate' : {
|
||||
'year': self.dueDate.year,
|
||||
'month': self.dueDate.month,
|
||||
'day': self.dueDate.day
|
||||
},
|
||||
'isPersonal' : self.isPersonal,
|
||||
'id' : self.key().id()
|
||||
}
|
||||
return json.dumps(data)
|
||||
|
||||
|
|
25
models/TaskComponent.py
Normal file
25
models/TaskComponent.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
__author__ = 'Aran'
|
||||
|
||||
|
||||
import json
|
||||
from google.appengine.ext import db
|
||||
|
||||
|
||||
class TaskComponent(db.Model):
|
||||
taskId = db.IntegerProperty(required=True)
|
||||
userId = db.IntegerProperty(required=True, default = -1)
|
||||
type = db.StringProperty(required=True,default=" ")
|
||||
label = db.StringProperty(required=True,default=" ")
|
||||
isMandatory = db.BooleanProperty(required=True, default=True)
|
||||
order = db.IntegerProperty(required=True)
|
||||
|
||||
def to_JSON(self):
|
||||
data = {'taskId' : self.taskId,
|
||||
'userId' : self.userId,
|
||||
'type' : self.type,
|
||||
'label' : self.label,
|
||||
'isMandatory' : self.isMandatory,
|
||||
'order' : self.order,
|
||||
'id' : self.key().id()
|
||||
}
|
||||
return json.dumps(data)
|
|
@ -49,6 +49,10 @@ app.config(['$routeProvider', '$locationProvider',
|
|||
.when('/myClasses', {
|
||||
templateUrl: 'templates/views/myClasses.html',
|
||||
controller: 'myClassesController'
|
||||
})
|
||||
.when('/tasks/new', {
|
||||
templateUrl: 'templates/views/newTask.html',
|
||||
controller: 'newTasksController'
|
||||
});
|
||||
}
|
||||
]);
|
||||
|
|
23
templates/js/controllers/newTasksController.js
Normal file
23
templates/js/controllers/newTasksController.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
angular.module('SeHub').controller('newTasksController', ['$scope',
|
||||
function($scope) {
|
||||
|
||||
|
||||
|
||||
$scope.componentTypes = [{
|
||||
"type": "textbox"
|
||||
}, {
|
||||
"type": "textarea"
|
||||
}, {
|
||||
"type": "checkbox"
|
||||
}];
|
||||
|
||||
|
||||
|
||||
$scope.task = [];
|
||||
|
||||
$scope.addComponent = function(){
|
||||
$scope.task.push($scope.newComp);
|
||||
$scope.newComp = {};
|
||||
}
|
||||
}
|
||||
]);
|
|
@ -102,6 +102,7 @@
|
|||
<script src="templates/js/controllers/registerController.js"></script>
|
||||
<script src="templates/js/controllers/tasksController.js"></script>
|
||||
<script src="templates/js/controllers/myClassesController.js"></script>
|
||||
<script src="templates/js/controllers/newTasksController.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
48
templates/views/newTask.html
Normal file
48
templates/views/newTask.html
Normal file
|
@ -0,0 +1,48 @@
|
|||
<div layout-padding>
|
||||
<div layout="row">
|
||||
<div flex="20" layout-padding>
|
||||
<h2>
|
||||
<i class="fa fa-info-circle"></i> Task Info:
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
<div layout="column" flex="30" layout-padding>
|
||||
|
||||
<div>
|
||||
<h2>
|
||||
<i class="fa fa-cubes"></i> Add A component:
|
||||
</h2>
|
||||
</div>
|
||||
<div>
|
||||
Select Type:
|
||||
<md-select placeholder="Component Type" ng-model="newComp.type">
|
||||
<md-option ng-repeat="component in componentTypes" value="{{component.type}}">{{component.type}}</md-option>
|
||||
</md-select>
|
||||
</div>
|
||||
<div>
|
||||
<md-input-container>
|
||||
<label>Label</label>
|
||||
<input ng-model="newComp.label" required>
|
||||
</md-input-container>
|
||||
</div>
|
||||
<div>
|
||||
<md-switch ng-model="newComp.isMandatory" aria-label="Switch 1">
|
||||
Mandatory?: {{ newComp.isMandatory}}
|
||||
</md-switch>
|
||||
</div>
|
||||
<div layout="row">
|
||||
<div flex="70"></div>
|
||||
<md-button class="md-primary" ng-click="addComponent()">Add Component</md-button>
|
||||
</div>
|
||||
|
||||
</div flex="50" layout-padding>
|
||||
<!-- <md-card style="background-image: url('http://www.stationeryhq.com/content/images/thumbs/0000324_clipboard_500.png')">
|
||||
|
||||
</md-card> -->
|
||||
<h2>
|
||||
<i class="fa fa-eye"></i> Task Preview:
|
||||
</h2>
|
||||
<p>{{task.toString()}}</p>
|
||||
</div>
|
||||
|
||||
</div>
|
|
@ -55,6 +55,10 @@
|
|||
</div>
|
||||
</div>
|
||||
<!-- End Edit Div -->
|
||||
<!-- Chart -->
|
||||
<h4>
|
||||
<i class="fa fa-bar-chart"></i> Statistics:
|
||||
</h4>
|
||||
<canvas id="bar" class="chart chart-bar" data="data"
|
||||
labels="labels" series="series"></canvas>
|
||||
</md-card>
|
||||
|
|
Loading…
Reference in a new issue