added Campus create method

This commit is contained in:
Aran Zaiger 2015-06-11 21:03:00 +03:00
parent 628aad5e03
commit d015986dfc

View file

@ -1,3 +1,4 @@
__author__ = 'sagi' __author__ = 'sagi'
import json import json
from GithubAPI.GithubAPI import GitHubAPI_Keys from GithubAPI.GithubAPI import GitHubAPI_Keys
@ -20,6 +21,7 @@ from models.Campus import Campus
#Validation Utils Libs #Validation Utils Libs
from SE_API.Validation_Utils import * from SE_API.Validation_Utils import *
from SE_API.Respones_Utils import *
@ -130,7 +132,7 @@ def oauth(oauth_token):
print user_data["login"] print user_data["login"]
for u in resault.run(limit=5): for u in resault.run():
print "Exists!!!" print "Exists!!!"
u.seToken = str(uuid.uuid4()) u.seToken = str(uuid.uuid4())
u.accessToken = oauth_token u.accessToken = oauth_token
@ -146,12 +148,58 @@ def oauth(oauth_token):
else: else:
tempEmail = user_data["email"] tempEmail = user_data["email"]
user = User(username=user_data["login"], name=tempName, avatar_url=user_data["avatar_url"], email=tempEmail, isLecturer=False, accsessToken=oauth_token, seToken=str(uuid.uuid4())) user = User(username=user_data["login"], name=tempName, avatar_url=user_data["avatar_url"], email=tempEmail, isLecturer=False, accessToken=oauth_token, seToken=str(uuid.uuid4()))
db.put(user) db.put(user)
db.save db.save
return cookieMonster(user.seToken) return cookieMonster(user.seToken)
@app.route('/api/Campuses/create/<string:token>', methods=['POST'])
@auto.doc()
def create_campus(token):
"""
This call will create a new campus in the DB
:param token: user seToken
Payload
{'title': self.title,
'email_ending': self.email_ending,
'avatar_url': self.avatar_url
}
:return:
code 200
"""
print "1\n"
if not request.data:
return Response(response=json.dumps({'message': 'Bad Request0'}),
status=400,
mimetype="application/json")
payload = json.loads(request.data)
if not is_lecturer(token): #todo: change to lecturer id
return Response(response=json.dumps({'message': 'Invalid token or not a lecturer!'}),
status=403,
mimetype="application/json")
user = get_user_by_token(token)
#todo: check legality
try:
campus = Campus(title=payload['title'], email_ending=payload['email_ending'], master_user_id=user.key().id(), avatar_url=payload['avatar_url'])
except Exception:
return Response(response=json.dumps({'message': 'Bad Request1'}),
status=400,
mimetype="application/json")
db.put(campus)
db.save
return Response(response=json.dumps(campus.to_JSON()),
status=200,
mimetype="application/json")
@app.route('/api/Campuses/<string:token>', methods=['GET']) @app.route('/api/Campuses/<string:token>', methods=['GET'])
@auto.doc() @auto.doc()
def get_campuses(token): def get_campuses(token):