예제 #1
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())
예제 #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 takData(takid = -1):
	if takid <= 0:
		return json_response(code=400)
	tak = Tak.get_by_id(takid)
	if tak is None:
		return json_response(code=400)

	if request.method == 'GET': # done
		# GET: returns a single json tak information
		return json_success(tak.Get())

	if request.method == 'DELETE': #todo
		# DELETE: deletes that tak
		tak.Delete()
		return json_response(code=200,message="Success")

	if request.method == 'PUT': #todo
		# PUT: updates a tak returns that object
		newName = request.args.get("name","")
		newLat = request.args.get("lat","")
		newLng = request.args.get("lng","")
		newMap = request.args.get("mapid","")
		logging.info(newMap)
		tak.Put(newName=newName,newLat=newLat,newLng=newLng, newMap = newMap)
		return json_response(code=200)
예제 #4
0
def takData(takid=-1):
    if takid <= 0:
        return json_response(code=400)
    tak = Tak.get_by_id(takid)
    if tak is None:
        return json_response(code=400)

    if request.method == 'GET':  # done
        # GET: returns a single json tak information
        return json_success(tak.Get())

    if request.method == 'DELETE':  #todo
        # DELETE: deletes that tak
        tak.Delete()
        return json_response(code=200, message="Success")

    if request.method == 'PUT':  #todo
        # PUT: updates a tak returns that object
        newName = request.args.get("name", "")
        newLat = request.args.get("lat", "")
        newLng = request.args.get("lng", "")
        newMap = request.args.get("mapid", "")
        logging.info(newMap)
        tak.Put(newName=newName, newLat=newLat, newLng=newLng, newMap=newMap)
        return json_response(code=200)
예제 #5
0
def copytak(takid = -1):
	if takid <= 0:
		return json_response(code=400)
	tak = Tak.get_by_id(takid)
	if tak is None:
		return json_response(code=400)
	mapid = getValue(request, "mapid", "")
	if mapid == '':
		return json_response(code=400)
	newmap = Map.get_by_id(int(mapid))
	if newmap is None:
		return json_response(code=400)
	newtak  = Tak(lng=tak.lng,lat=tak.lat, creator=tak.creator, name=tak.name,mapId=newmap.key.integer_id(),creatorId=tak.creatorId)
	newtak.metadata = tak.metadata
	key = newtak.put()
	newmap.takIds.append(key.integer_id())
	newmap.put();
	return json_success(newtak.Get())
예제 #6
0
def api_tak():
	if request.method == 'POST':
		userName = request.args.get("name","")
		mapId = request.args.get("mapId","")
		mapId = str(mapId.encode('utf-8').decode('ascii', 'ignore'))
		userId = request.args.get("id","")
		userId = int(str(userId.encode('utf-8').decode('ascii', 'ignore')))
		name = request.args.get("title","")
		lat = request.args.get("lat","")
		lat = str(lat.encode('utf-8').decode('ascii', 'ignore'))
		lng = request.args.get("lng","")
		lng =str(lng.encode('utf-8').decode('ascii', 'ignore'))
		tak = Tak(name=name,lat=lat,lng=lng,creator=userName,creatorId=int(userId),mapId=int(mapId))
		key = tak.put()
		logging.info("tak added")
		return json_success({"takId":key.integer_id()})
	if request.method == 'GET':
		return '200'
예제 #7
0
def create_tak():
    if request.method == 'POST':
        # login required
        mapId = getValue(request, "mapId", "")
        logging.info("mapId=" + mapId)
        map = Map.get_by_id(int(mapId))
        if map is None:
            return jsonify(message="Map does not exist", response=400)
        logging.info("mapid %s" % mapId)
        name = getValue(request, "title", "")
        lat = getValue(request, "lat", "")
        lng = getValue(request, "lng", "")
        #user = getValue(request, "user", "")
        #change form to not supply user
        user = session['username']
        uid = session['userId']

        if not (user and lat and lng):
            return jsonify(message="Bad Request", response=400)
            # check if args blank

        logging.info("Add lat %s, lng %s" % (lat, lng))
        tak = Tak(lng=lng,
                  lat=lat,
                  creator=user,
                  name=name,
                  mapId=int(mapId),
                  creatorId=int(uid))
        key = tak.put()
        map.takIds.append(int(key.id()))
        map.put()
        return json_success(tak.to_dict())

    if request.method == 'GET':
        # return list of maps too for selecting
        listOfMaps = []
        mapIds = getMaps(session['userId'])
        for mapid in mapIds:
            ownMap = Map.get_by_id(mapid)
            listOfMaps.append(ownMap)

        return render_template('create_tak.html', uid=session['userId'])
예제 #8
0
def show_taks(id=-1):
    uid = -1
    try:
        uid = session['userId']
    except Exception as e:
        logging.info('no session id on /tak/<id>')
    if request.method == 'GET':
        if id >= 0:
            tak = Tak.get_by_id(id)
            if tak is not None:
                return tak.view(uid=uid)
    return redirect('/app')
예제 #9
0
def delete_tak(mapid=-1, takid=-1):
    if request.method == 'DELETE':
        map = Map.get_by_id(mapid)
        logging.info("DELETE " + str(mapid))
        if map is not None:
            # remove taks in map
            tak = Tak.get_by_id(int(takid))
            logging.info("_DELETE sub-tak" + str(takid))
            if tak is not None:
                tak.key.delete()
            return "Success"
        return "Map does not exist"
예제 #10
0
def show_taks(id=-1):
	uid = -1
	try:
		uid = session['userId']
	except Exception as e:
		logging.info('no session id on /tak/<id>')
	if request.method == 'GET':
		if id >= 0:
			tak = Tak.get_by_id(id)
			if tak is not None:
				return tak.view(uid = uid)
	return redirect('/app')
예제 #11
0
def delete_tak(mapid=-1, takid=-1):
	if request.method == 'DELETE':
		map = Map.get_by_id(mapid)
                logging.info("DELETE " + str(mapid))
                if map is not None:
                        # remove taks in map
                        tak = Tak.get_by_id(int(takid))
                        logging.info("_DELETE sub-tak" + str(takid))
                        if tak is not None:
                     		   tak.key.delete()
                        return "Success"
                return "Map does not exist"
예제 #12
0
	def Delete(self):
		# remove taks in map
		for takid in self.takIds:
			tak = Tak.get_by_id(int(takid))
			if tak is not None:
				tak.key.delete()
		for mid in self.adminIds:
			admin = User.Account.get_by_id(mid)
			if admin is not None:
				admin.adminMaps.remove(self.key.integer_id())
				admin.put()
		self.key.delete()
		return
예제 #13
0
def api_tak():
    if request.method == 'POST':
        userName = request.args.get("name", "")
        mapId = request.args.get("mapId", "")
        mapId = str(mapId.encode('utf-8').decode('ascii', 'ignore'))
        userId = request.args.get("id", "")
        userId = int(str(userId.encode('utf-8').decode('ascii', 'ignore')))
        name = request.args.get("title", "")
        lat = request.args.get("lat", "")
        lat = str(lat.encode('utf-8').decode('ascii', 'ignore'))
        lng = request.args.get("lng", "")
        lng = str(lng.encode('utf-8').decode('ascii', 'ignore'))
        tak = Tak(name=name,
                  lat=lat,
                  lng=lng,
                  creator=userName,
                  creatorId=int(userId),
                  mapId=int(mapId))
        key = tak.put()
        logging.info("tak added")
        return json_success({"takId": key.integer_id()})
    if request.method == 'GET':
        return '200'
예제 #14
0
def create_tak():
	if request.method == 'POST':
		# login required
		mapId = getValue(request, "mapId", "")
		logging.info("mapId="+mapId)
		map = Map.get_by_id(int(mapId))
		if map is None:
			return jsonify(message="Map does not exist", response=400) 
		logging.info("mapid %s" %mapId)
		name = getValue(request, "title", "")
		lat = getValue(request, "lat", "")
		lng = getValue(request, "lng", "")
		#user = getValue(request, "user", "")
		#change form to not supply user
		user = session['username']
		uid = session['userId']
			
		if not ( user and lat and lng ):
			return jsonify(message="Bad Request", response=400)
			# check if args blank

		logging.info("Add lat %s, lng %s" %(lat, lng) )
		tak  = Tak(lng=lng,lat=lat, creator=user, name=name,mapId=int(mapId),creatorId=int(uid))
		key = tak.put()
		map.takIds.append(int(key.id()))
		map.put();
		return json_success(tak.to_dict())

	if request.method == 'GET': 
		# return list of maps too for selecting
		listOfMaps = []
		mapIds = getMaps(session['userId'])
		for mapid in mapIds:
			ownMap = Map.get_by_id(mapid)
			listOfMaps.append(ownMap)

		return render_template('create_tak.html', uid=session['userId'])
예제 #15
0
def postMetadata(takid=-1):
    if takid <= 0:
        return json_response(code=400)
    tak = Tak.get_by_id(takid)
    if tak is None:
        logging.info("tak is None")
        return json_response(code=400)
    key = getValue(request, "key", "")
    value = getValue(request, "value", "")
    if key != '' and value != '':
        for mdata in tak.metadata:
            if mdata.key == key:
                mdata.value = value
                tak.put()
                return json_response(code=200)
        metadata = Metadata(key=key, value=value)
        tak.metadata.append(metadata)
        tak.put()
        return json_response(code=200)
    else:
        if request.method == 'POST':
            try:
                logging.info("json")
                data = json.loads(request.data, object_hook=_decode_dict)
                logging.info(data)
                for datum in data:
                    # datum is a metadata object
                    logging.info(datum['key'])
                    logging.info(datum['value'])
                    found = bool(0)
                    for mdata in tak.metadata:
                        if datum['key'] == mdata.key:
                            mdata.value = datum['value']
                            found = bool(1)
                            break
                    if not found:
                        metadata = Metadata(key=datum['key'],
                                            value=datum['value'])
                        tak.metadata.append(metadata)
                tak.put()

                return json_success(data)
            except Exception as e:
                logging.info(e)
                return json_response(code=400)
        return json_response(code=400)
예제 #16
0
def postMetadata(takid = -1):
	if takid <= 0:
		return json_response(code=400)
	tak = Tak.get_by_id(takid)
	if tak is None:
		logging.info("tak is None")
		return json_response(code=400)
	key = getValue(request, "key", "")
	value = getValue(request, "value", "")
	if key != '' and value != '':
		for mdata in tak.metadata:
			if mdata.key == key:
				mdata.value = value
				tak.put()
				return json_response(code = 200)
		metadata = Metadata(key=key,value=value)
		tak.metadata.append(metadata)
		tak.put()
		return json_response(code = 200)
	else:
		if request.method == 'POST':
			try:
				logging.info("json")
				data = json.loads(request.data, object_hook=_decode_dict)
				logging.info(data)
				for datum in data:
					# datum is a metadata object 
					logging.info(datum['key'])
					logging.info(datum['value'])
					found = bool(0)
					for mdata in tak.metadata:
						if datum['key'] == mdata.key:
							mdata.value = datum['value']
							found = bool(1)
							break
					if not found:
						metadata = Metadata(key=datum['key'],value=datum['value'])
						tak.metadata.append(metadata)
				tak.put()

				return json_success(data)
			except Exception as e:
				logging.info(e)
				return json_response(code=400)
		return json_response(code=400)
예제 #17
0
def postNewMetadata(takid = -1, key = ''):
	if not key or takid <= 0:
		return json_response(code=400)
	tak = Tak.get_by_id(takid)
	if tak is None:
		logging.info("tak is None")
		return json_response(code=400)
	try:
		logging.info(key)
		found = bool(0)
		for mdata in tak.metadata:
			if mdata.key == key:
				tak.metadata.remove(mdata)
				found = bool(1)
				break
		tak.put()
		return json_response(code=200)
	except Exception as e:
		logging.info(e)
		return json_response(code=400)
예제 #18
0
def postNewMetadata(takid=-1, key=''):
    if not key or takid <= 0:
        return json_response(code=400)
    tak = Tak.get_by_id(takid)
    if tak is None:
        logging.info("tak is None")
        return json_response(code=400)
    try:
        logging.info(key)
        found = bool(0)
        for mdata in tak.metadata:
            if mdata.key == key:
                tak.metadata.remove(mdata)
                found = bool(1)
                break
        tak.put()
        return json_response(code=200)
    except Exception as e:
        logging.info(e)
        return json_response(code=400)
예제 #19
0
def api_single_tak(id=-1):
	tak = Tak.get_by_id(id)
	if tak is None:
		return '404: '

	if request.method == 'GET':
		return json_success(tak.to_dict())

	if request.method == 'DELETE':
		tak.Delete()
		return json_response(code=200,message="Success")

	if request.method == 'PUT':
		name = getValue(request, "name", "")
		logging.info("name: " + name)
		tak.update(name=name)
		tak.put()
		return '200'

	if request.method == 'POST':
		return '200'
예제 #20
0
def api_single_tak(id=-1):
    tak = Tak.get_by_id(id)
    if tak is None:
        return '404: '

    if request.method == 'GET':
        return json_success(tak.to_dict())

    if request.method == 'DELETE':
        tak.Delete()
        return json_response(code=200, message="Success")

    if request.method == 'PUT':
        name = getValue(request, "name", "")
        logging.info("name: " + name)
        tak.update(name=name)
        tak.put()
        return '200'

    if request.method == 'POST':
        return '200'
예제 #21
0
	def to_dict(self):
		owner = User.Account.get_by_id(int(self.creatorId))
		ownerdata = {}
		if owner is not None:
			ownerdata = owner.to_dict()
		taks = []
		for takid in self.takIds:
			tak = Tak.get_by_id(int(takid))
			if tak is not None:
				taks.append(tak.to_dict())
		admins = []
		for adminid in self.adminIds:
			user = User.Account.get_by_id(int(adminid))
			if user is not None:
				admins.append(user.to_dict())
		return {
			'name' : self.name,
			'id': self.key.id(),
			'owner': ownerdata,
			'taks': taks,
			'public': str(self.public),
			'admins': admins,
			}
예제 #22
0
def copytak(takid=-1):
    if takid <= 0:
        return json_response(code=400)
    tak = Tak.get_by_id(takid)
    if tak is None:
        return json_response(code=400)
    mapid = getValue(request, "mapid", "")
    if mapid == '':
        return json_response(code=400)
    newmap = Map.get_by_id(int(mapid))
    if newmap is None:
        return json_response(code=400)
    newtak = Tak(lng=tak.lng,
                 lat=tak.lat,
                 creator=tak.creator,
                 name=tak.name,
                 mapId=newmap.key.integer_id(),
                 creatorId=tak.creatorId)
    newtak.metadata = tak.metadata
    key = newtak.put()
    newmap.takIds.append(key.integer_id())
    newmap.put()
    return json_success(newtak.Get())
예제 #23
0
def getMapTaks(id):
	query = Tak.query(Tak.mapId == int(id))
	return query
예제 #24
0
def getMapTaks(id):
    query = Tak.query(Tak.mapId == int(id))
    return query