コード例 #1
0
ファイル: app.py プロジェクト: kylepotts/droptak-web
def newTak():
	name = getValue(request, "name", None)
	uid = getValue(request, "userid", None)
	lat = getValue(request, "lat", None)
	lng = getValue(request, "lng", None)
	if not ( name and lat and lng and uid):
		return json_response(code=400)
	mapid = getValue(request, "mapid", None)
	map = None
	if uid is not None:
		user = Account.get_by_id(int(uid))
		if user is None:
			return json_response(code=400)
	if mapid is not None:
		map = Map.get_by_id(int(mapid))
	if map is None:
		map = Map(creator=user.name,creatorId=int(uid),name='Untitled',adminIds=[int(uid)])
		key = map.put()
		mapid = key.id()
		account = Account.get_by_id(int(uid))
		account.adminMaps.append(int(mapid))
		account.put()
	tak  = Tak(lng=lng,lat=lat, creator=user.name, name=name,mapId=int(mapid),creatorId=int(uid))
	key = tak.put()
	map.takIds.append(key.integer_id())
	map.put();
	return json_success(tak.Get())
コード例 #2
0
def newTak():
    name = getValue(request, "name", None)
    uid = getValue(request, "userid", None)
    lat = getValue(request, "lat", None)
    lng = getValue(request, "lng", None)
    if not (name and lat and lng and uid):
        return json_response(code=400)
    mapid = getValue(request, "mapid", None)
    map = None
    if uid is not None:
        user = Account.get_by_id(int(uid))
        if user is None:
            return json_response(code=400)
    if mapid is not None:
        map = Map.get_by_id(int(mapid))
    if map is None:
        map = Map(creator=user.name,
                  creatorId=int(uid),
                  name='Untitled',
                  adminIds=[int(uid)])
        key = map.put()
        mapid = key.id()
        account = Account.get_by_id(int(uid))
        account.adminMaps.append(int(mapid))
        account.put()
    tak = Tak(lng=lng,
              lat=lat,
              creator=user.name,
              name=name,
              mapId=int(mapid),
              creatorId=int(uid))
    key = tak.put()
    map.takIds.append(key.integer_id())
    map.put()
    return json_success(tak.Get())
コード例 #3
0
def newMap(userid='', name='', public=''):
    if not (name and public and userid):
        return json_response(code=400)
    user = Account.get_by_id(int(userid))
    if user is None:
        return json_response(code=400)
    if public == 'true':
        public = True
    else:  # default false if not set
        public = False
    for mapid in user.adminMaps:
        map = Map.get_by_id(int(mapid))
        if map is not None and map.creatorId == int(
                userid) and map.name == name:
            return json_response(message="You already have a map of that name",
                                 code=400)
    map = Map(creator=user.name,
              creatorId=int(userid),
              name=name,
              adminIds=[int(userid)],
              public=public)
    key = map.put()
    # add map to user's list of maps
    user.adminMaps.append(key.integer_id())
    user.put()
    #return map json
    return json_success(map.to_dict())
コード例 #4
0
def favorite_mapsForUser(userid=-1):
    if userid <= 0:
        return json_response(code=400)
    user = Account.get_by_id(userid)
    if user is None:
        return json_response(code=400)

    if request.method == 'GET':  # done
        #	GET: returns json array of information about user's map objects
        return json_success(user.getFavorites())

    mapid = getValue(request, "mapid", "")
    if not mapid:
        return json_response(code=400)
    map = Map.get_by_id(int(mapid))
    if map is None:
        return json_response(code=400)
    if request.method == 'POST':
        if not map.key.integer_id() in user.favoriteMaps:
            user.favoriteMaps.append(map.key.integer_id())
            user.put()
        return json_response(code=200)

    if request.method == 'DELETE':
        if map.key.integer_id() in user.favoriteMaps:
            user.favoriteMaps.remove(map.key.integer_id())
            user.put()
        return json_response(code=200)
コード例 #5
0
ファイル: app.py プロジェクト: kylepotts/droptak-web
def favorite_mapsForUser(userid = -1):
	if userid <= 0:
		return json_response(code=400)
	user = Account.get_by_id(userid)
	if user is None:
		return json_response(code=400)

	if request.method == 'GET': # done
		#	GET: returns json array of information about user's map objects
		return json_success(user.getFavorites())

	mapid = getValue(request, "mapid", "")
	if not mapid:
		return json_response(code=400)
	map = Map.get_by_id(int(mapid))
	if map is None:
		return json_response(code=400)
	if request.method == 'POST':
		if not map.key.integer_id() in user.favoriteMaps:
			user.favoriteMaps.append(map.key.integer_id())
			user.put()
		return json_response(code=200)
	
	if request.method == 'DELETE':
		if map.key.integer_id() in user.favoriteMaps:
			user.favoriteMaps.remove(map.key.integer_id())
			user.put()
		return json_response(code=200)
コード例 #6
0
def mapInfoForUser(userid=-1):
    if userid <= 0:
        return json_response(code=400)
    user = Account.get_by_id(userid)
    if user is None:
        return json_response(code=400)

    if request.method == 'GET':  # done
        #	GET: returns json array of information about user's map objects
        return json_success(user.getMapsInfo())
コード例 #7
0
def userData(userid=-1):
    if userid <= 0:
        return json_response(code=400)
    user = Account.get_by_id(userid)
    if user is None:
        return json_response(code=400)

    if request.method == 'GET':  # done
        #	GET: returns json object of user
        return json_success(user.Get())
コード例 #8
0
ファイル: app.py プロジェクト: kylepotts/droptak-web
def userData(userid = -1):
	if userid <= 0:
		return json_response(code=400)
	user = Account.get_by_id(userid)
	if user is None:
		return json_response(code=400)

	if request.method == 'GET': # done
#	GET: returns json object of user
		return json_success(user.Get())
コード例 #9
0
ファイル: app.py プロジェクト: kylepotts/droptak-web
def mapInfoForUser(userid = -1):
	if userid <= 0:
		return json_response(code=400)
	user = Account.get_by_id(userid)
	if user is None:
		return json_response(code=400)

	if request.method == 'GET': # done
		#	GET: returns json array of information about user's map objects
		return json_success(user.getMapsInfo())
コード例 #10
0
def index():
    if "userId" in session:
        #logging.info("loggedIn=" + str(session['loggedIn']))
        account = Account.get_by_id(session['userId'])
        if account is None:  # prevent interal error
            return render_template('index.html')
        lin = account.loggedIn
        if lin == False:
            return render_template('index.html')
        if lin == True:
            return render_template('dashboard.html')

    if session:
        return render_template('dashboard.html')
    else:
        return render_template('index.html')
コード例 #11
0
ファイル: app.py プロジェクト: kylepotts/droptak-web
def index():
	if "userId" in session:
		#logging.info("loggedIn=" + str(session['loggedIn']))
		account = Account.get_by_id(session['userId'])
		if account is None: # prevent interal error
			return render_template('index.html')
		lin = account.loggedIn
		if lin == False:
			return render_template('index.html')
		if lin == True:
			return render_template('dashboard.html')

	if session:
		return render_template('dashboard.html')
	else:
		return render_template('index.html')
コード例 #12
0
ファイル: app.py プロジェクト: kylepotts/droptak-web
def newMap(userid='', name='', public=''):
	if not (name and public and userid):
		return json_response(code=400);
	user = Account.get_by_id(int(userid))
	if user is None:
		return json_response(code=400);
	if public == 'true':
		public = True
	else: # default false if not set
		public = False
	for mapid in user.adminMaps:
			map = Map.get_by_id(int(mapid))
			if map is not None and map.creatorId == int(userid) and map.name == name:
				return json_response(message="You already have a map of that name", code=400);
	map = Map(creator=user.name,creatorId=int(userid),name=name,adminIds=[int(userid)], public=public)
	key = map.put()
	# add map to user's list of maps
	user.adminMaps.append(key.integer_id())
	user.put()
	#return map json
	return json_success(map.to_dict());
コード例 #13
0
def search():
    if request.method == 'GET':
        maps = []
        mapIds = []
        queryType = request.args.get("queryType", "")
        query = request.args.get("query", "")
        uid = session['userId']
        account = Account.get_by_id(uid)
        logging.info("searching for " + queryType + " " + query)
        mapQuery = Map.query(Map.public == True)
        for map in mapQuery:
            if queryType == 'searchMaps':
                if (query.lower() == map.name.lower()):
                    logging.info("match!")
                    maps.append(map)
                    mapIds.append(map.key.integer_id())
        for mapId in account.adminMaps:
            m = Map.get_by_id(mapId)
            if (query.lower() == m.name.lower()):
                if mapId not in mapIds:
                    maps.append(m)
        logging.info(len(maps))
        return render_template('search.html', maps=maps)
コード例 #14
0
ファイル: app.py プロジェクト: kylepotts/droptak-web
def search():
	if request.method == 'GET':
		maps = []
		mapIds = []
		queryType=request.args.get("queryType","")
		query = request.args.get("query","")
		uid = session['userId']
		account = Account.get_by_id(uid) 
		logging.info("searching for " + queryType + " " + query)
		mapQuery = Map.query(Map.public == True)
		for map in mapQuery:
			if queryType == 'searchMaps':
				if(query.lower() == map.name.lower()):
					logging.info("match!")
					maps.append(map)
					mapIds.append(map.key.integer_id())
		for mapId in account.adminMaps:
			m = Map.get_by_id(mapId)
			if (query.lower() == m.name.lower()):
				if mapId not in mapIds:
					maps.append(m)
		logging.info(len(maps))
		return render_template('search.html',maps=maps)
コード例 #15
0
def favorites():
    user = Account.get_by_id(int(session['userId']))
    if user is None:
        return json_response(code=400)
    return json_success(user.getFavorites())
コード例 #16
0
ファイル: app.py プロジェクト: kylepotts/droptak-web
def getMaps(id):
	account = Account.get_by_id(id)
	return account.adminMaps
コード例 #17
0
def getMaps(id):
    account = Account.get_by_id(id)
    return account.adminMaps
コード例 #18
0
ファイル: app.py プロジェクト: kylepotts/droptak-web
def favorites():
	user = Account.get_by_id(int( session['userId'] ))
	if user is None:
		return json_response(code=400)
	return json_success(user.getFavorites())