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())
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())