예제 #1
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)
예제 #2
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)
예제 #3
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')
예제 #4
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"
예제 #5
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')
예제 #6
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"
예제 #7
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
예제 #8
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)
예제 #9
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)
예제 #10
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())
예제 #11
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)
예제 #12
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)
예제 #13
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'
예제 #14
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'
예제 #15
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())
예제 #16
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,
			}