fix function
This commit is contained in:
parent
82dd89ce8f
commit
b1f1400628
3 changed files with 109 additions and 56 deletions
|
@ -7,8 +7,11 @@ from GithubAPI.GithubAPI import GitHubAPI_Keys
|
||||||
from google.appengine.ext import db
|
from google.appengine.ext import db
|
||||||
import requests
|
import requests
|
||||||
import datetime
|
import datetime
|
||||||
|
import thread
|
||||||
|
import threading
|
||||||
|
|
||||||
from flask import Flask, request, render_template, redirect, abort, Response
|
|
||||||
|
from flask import Flask, request, render_template, redirect, abort, Response, g
|
||||||
|
|
||||||
from flask.ext.github import GitHub
|
from flask.ext.github import GitHub
|
||||||
from flask.ext.cors import CORS, cross_origin
|
from flask.ext.cors import CORS, cross_origin
|
||||||
|
@ -58,6 +61,7 @@ def create_project(token):
|
||||||
<br>
|
<br>
|
||||||
403 - Invalid token or not a lecturer
|
403 - Invalid token or not a lecturer
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not request.data:
|
if not request.data:
|
||||||
return bad_request()
|
return bad_request()
|
||||||
try:
|
try:
|
||||||
|
@ -76,17 +80,40 @@ def create_project(token):
|
||||||
print e
|
print e
|
||||||
return bad_request()
|
return bad_request()
|
||||||
|
|
||||||
db.put(project)
|
try:
|
||||||
|
project.logo_url = payload['logo_url']
|
||||||
|
except Exception as e:
|
||||||
|
print e
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# def updateProjectInfo(response):
|
||||||
|
#
|
||||||
|
# projectDic = dict(json.loads(response.data))
|
||||||
|
# project = Project.get_by_id(int(projectDic['id']))
|
||||||
|
# project.info = json.dumps(get_github_data(project.gitRepository))
|
||||||
|
# db.put(project)
|
||||||
|
# db.save
|
||||||
|
# return response
|
||||||
|
|
||||||
|
db.put(project)
|
||||||
#update user projects list
|
#update user projects list
|
||||||
user.projects_id_list.append(str(project.key().id()))
|
user.projects_id_list.append(str(project.key().id()))
|
||||||
|
|
||||||
|
print "finish project"
|
||||||
db.put(user)
|
db.put(user)
|
||||||
db.save
|
db.save
|
||||||
|
t1 = threading.Thread(target=updateProjectInfo,args=(project.key().id(),))
|
||||||
|
t1.start()
|
||||||
|
# thread.start_new_thread(updateProjectInfo, (project.key().id(),))
|
||||||
|
|
||||||
return Response(response=project.to_JSON(),
|
return Response(response=project.to_JSON(),
|
||||||
status=200,
|
status=200,
|
||||||
mimetype="application/json")
|
mimetype="application/json")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------
|
#----------------------------------------------------------
|
||||||
# PUT
|
# PUT
|
||||||
#----------------------------------------------------------
|
#----------------------------------------------------------
|
||||||
|
@ -312,4 +339,28 @@ def deleteProject(token,projectId):
|
||||||
|
|
||||||
@project_routes.route('/api/projects/help')
|
@project_routes.route('/api/projects/help')
|
||||||
def documentation():
|
def documentation():
|
||||||
return auto.html()
|
return auto.html()
|
||||||
|
|
||||||
|
|
||||||
|
# def after_this_request(func):
|
||||||
|
# if not hasattr(g, 'call_after_request'):
|
||||||
|
# g.call_after_request = []
|
||||||
|
# g.call_after_request.append(func)
|
||||||
|
# return func
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# @project_routes.after_request
|
||||||
|
# def per_request_callbacks(response):
|
||||||
|
# for func in getattr(g, 'call_after_request', ()):
|
||||||
|
# response = func(response)
|
||||||
|
# return response
|
||||||
|
#
|
||||||
|
|
||||||
|
def updateProjectInfo(projectId):
|
||||||
|
print "in updateProjectInfo"
|
||||||
|
import time
|
||||||
|
project = Project.get_by_id(int(projectId))
|
||||||
|
project.info = json.dumps(get_github_data(project.gitRepository))
|
||||||
|
db.put(project)
|
||||||
|
db.save
|
||||||
|
return
|
|
@ -89,59 +89,59 @@ def updateUser(token):
|
||||||
db.save
|
db.save
|
||||||
return ok("User updated")
|
return ok("User updated")
|
||||||
|
|
||||||
@user_routes.route('/api/users/addUserToCourse/<string:token>', methods=["PUT"])
|
# @user_routes.route('/api/users/addUserToCourse/<string:token>', methods=["PUT"])
|
||||||
@auto.doc()
|
# @auto.doc()
|
||||||
def addUserToCourse(token):
|
# def addUserToCourse(token):
|
||||||
"""
|
# """
|
||||||
<span class="card-title">>This Call will add a course to user course list</span>
|
# <span class="card-title">>This Call will add a course to user course list</span>
|
||||||
<br>
|
# <br>
|
||||||
<b>Route Parameters</b><br>
|
# <b>Route Parameters</b><br>
|
||||||
- seToken: 'seToken'
|
# - seToken: 'seToken'
|
||||||
<br>
|
# <br>
|
||||||
<br>
|
# <br>
|
||||||
<b>Payload</b><br>
|
# <b>Payload</b><br>
|
||||||
- JSON Object, Example: <br>
|
# - JSON Object, Example: <br>
|
||||||
{<br>
|
# {<br>
|
||||||
'courseId': 1234567890<br>
|
# 'courseId': 1234567890<br>
|
||||||
}<br>
|
# }<br>
|
||||||
<br>
|
# <br>
|
||||||
<b>Response</b>
|
# <b>Response</b>
|
||||||
<br>
|
# <br>
|
||||||
200 - User updated
|
# 200 - User updated
|
||||||
<br>
|
# <br>
|
||||||
400 - Bad Request
|
# 400 - Bad Request
|
||||||
"""
|
# """
|
||||||
|
#
|
||||||
if not request.data:
|
# if not request.data:
|
||||||
return bad_request()
|
# return bad_request()
|
||||||
|
#
|
||||||
try:
|
# try:
|
||||||
payload = json.loads(request.data)
|
# payload = json.loads(request.data)
|
||||||
except Exception as e:
|
# except Exception as e:
|
||||||
return bad_request()
|
# return bad_request()
|
||||||
|
#
|
||||||
#check user exists
|
# #check user exists
|
||||||
user = get_user_by_token(token)
|
# user = get_user_by_token(token)
|
||||||
if user is None:
|
# if user is None:
|
||||||
return bad_request("Not a user!")
|
# return bad_request("Not a user!")
|
||||||
|
#
|
||||||
#check course Exists
|
# #check course Exists
|
||||||
course = Course.get_by_id(payload['coursesId'])
|
# course = Course.get_by_id(payload['coursesId'])
|
||||||
if course is None:
|
# if course is None:
|
||||||
return bad_request("No such Course!")
|
# return bad_request("No such Course!")
|
||||||
|
#
|
||||||
try:
|
# try:
|
||||||
user.courses_id_list.append(payload['coursesId'])
|
# user.courses_id_list.append(payload['coursesId'])
|
||||||
except Exception as e:
|
# except Exception as e:
|
||||||
print e
|
# print e
|
||||||
return bad_request()
|
# return bad_request()
|
||||||
|
#
|
||||||
db.put(user)
|
# db.put(user)
|
||||||
db.save
|
# db.save
|
||||||
return Response(response=user.to_JSON(),
|
# return Response(response=user.to_JSON(),
|
||||||
status=200,
|
# status=200,
|
||||||
mimetype="application/json") # Real response!
|
# mimetype="application/json") # Real response!
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ class Project(db.Model):
|
||||||
logo_url = db.StringProperty(required=False)
|
logo_url = db.StringProperty(required=False)
|
||||||
gitRepository = db.StringProperty(required=True)
|
gitRepository = db.StringProperty(required=True)
|
||||||
membersId = db.StringListProperty(required=True)
|
membersId = db.StringListProperty(required=True)
|
||||||
|
info = db.TextProperty(required=False, default="{}")
|
||||||
|
|
||||||
def to_JSON(self):
|
def to_JSON(self):
|
||||||
data = {'projectName' : self.projectName,
|
data = {'projectName' : self.projectName,
|
||||||
|
@ -20,6 +21,7 @@ class Project(db.Model):
|
||||||
'logo_url' : self.logo_url,
|
'logo_url' : self.logo_url,
|
||||||
'gitRepository' : self.gitRepository,
|
'gitRepository' : self.gitRepository,
|
||||||
'membersId' : self.membersId,
|
'membersId' : self.membersId,
|
||||||
|
'info': json.loads(self.info),
|
||||||
'id' : self.key().id()
|
'id' : self.key().id()
|
||||||
}
|
}
|
||||||
return json.dumps(data)
|
return json.dumps(data)
|
||||||
|
|
Loading…
Reference in a new issue