def add_data_with_map(self, url_arr): ''' Add geojson from Map :param url_arr: :return: ''' post_data = self.get_post_data() geojson_str = post_data['geojson'] out_dic = self.parse_geojson(geojson_str) if len(url_arr[1]) == 4: uid = url_arr[1] return_dic = {'sig': ''} cur_info = MJson.get_by_id(uid) if cur_info.user_id == self.userinfo.uid: pass else: return_dic['status'] = 0 return json.dump(return_dic, self) else: uid = tools.get_uu4d() while MJson.get_by_id(uid): uid = tools.get_uu4d() return_dic = {'sig': uid} MJson.add_or_update(uid, self.userinfo.uid, url_arr[0], out_dic) return_dic['status'] = 1 return json.dump(return_dic, self)
def add_data(self, gson_uid): post_data = self.get_post_data() geojson_str = post_data['geojson'] out_dic = self.parse_geojson(geojson_str) if gson_uid == 'draw' or gson_uid == '': uid = tools.get_uu4d() while MJson.get_by_id(uid): uid = tools.get_uu4d() return_dic = {'uid': uid} elif len(gson_uid) == 4: uid = gson_uid return_dic = {'uid': ''} cur_info = MJson.get_by_id(uid) if cur_info.user_id == self.userinfo.uid: pass else: return_dic['status'] = 0 return json.dump(return_dic, self) else: return try: MJson.add_or_update_json(uid, self.userinfo.uid, out_dic, post_data, version=2) return_dic['status'] = 1 except: self.set_status(400) return_dic['status'] = 0 return json.dump(return_dic, self)
def j_add(self, uid=''): if self.userinfo: pass else: print('User Not Login.') print('=' * 20) print('Hello') post_data = self.get_post_data() # print(post_data) # print(post_data['geojson']['tileLayer']['high']) # print(json.dumps(post_data, indent=1)) geojson_str = post_data['geojson'] gson = json.loads(geojson_str) print(json.dumps(gson, indent=1)) maplet_map_id = 'm' + gson['tileLayer']['high']['name'].split('-')[-1] # print(maplet_map_id) # webdog_to_geojson()会导致数据被改变 # geojson_obj = webdog_to_geojson(gson) # print('=' * 100) # print(geojson_obj) # out_dic = self.parse_geojson(geojson_str) if uid: pass else: uid = tools.get_uu4d() while MJson.get_by_id(uid): uid = tools.get_uu4d() return_dic = {'uid': uid} # MJson.add_or_update_json(uid, self.userinfo.uid, out_dic) # return_dic['status'] = 1 # return json.dump(return_dic, self) try: # MJson.add_or_update_json(uid, '', geojson_str) # print('x' * 40) # print(uid) # print(self.userinfo.uid, ) # print(maplet_map_id), # print(geojson_str) # MJson.add_or_update(uid, self.userinfo.uid, maplet_map_id, geojson_str) MJson.add_or_update(uid, self.userinfo.uid, maplet_map_id, gson) return_dic['status'] = 1 # print('Saved successfully!') return json.dump(return_dic, self) except: self.set_status(400) return_dic['status'] = 0 # print('Save Error!') return json.dump(return_dic, self)
def j_add(self, uid=''): post_data = self.get_post_data() print(post_data) geojson_str = post_data['geojson'] # out_dic = self.parse_geojson(geojson_str) if uid: pass else: uid = 'x' + tools.get_uu4d()[1:] while MJson.get_by_id(uid): uid = 'x' + tools.get_uu4d()[1:] return_dic = {'uid': uid} # MJson.add_or_update_json(uid, self.userinfo.uid, out_dic) # return_dic['status'] = 1 # return json.dump(return_dic, self) try: MJson.add_or_update_json(uid, '', geojson_str, post_data) return_dic['status'] = 1 return json.dump(return_dic, self) except: self.set_status(400) return_dic['status'] = 0 return json.dump(return_dic, self)
def get(self, *args, **kwargs): url_str = args[0] url_arr = self.parse_url(url_str) if url_arr: self.index() elif url_str == 'draw': self.show_geojson('') elif url_arr[0] == 'list': self.list() elif len(url_arr) == 1 and len(url_str) == 4: self.show_geojson(url_str) elif len(url_arr) == 2: if url_arr[0] == 'gson': rec = MJson.get_by_id(url_arr[1]) if rec: return json.dump(rec.json, self) else: return False elif url_arr[0] == 'download': self.download(url_arr[1]) elif url_arr[0] == 'delete': self.delete(url_arr[1])
def get(self, *args, **kwargs): url_str = args[0] url_arr = self.parse_url(url_str) if len(url_arr) == 0: self.index() elif url_str == 'draw': self.show_geojson('') elif url_arr[0] == 'list': self.list() elif url_arr[0] == '_delete': self.delete(url_arr[1]) elif url_arr[0] == '_edit': self.edit(url_arr[1]) elif len(url_arr) == 1 and len(url_str) == 4: self.show_geojson(url_str) elif len(url_arr) == 2: if url_arr[0] == 'gson': rec = MJson.get_by_id(url_arr[1]) # print('i' * 40) # print(rec.json) if 'tileLayer' in rec.json: # if the data is webdog. uu = rec.json # print('=x' * 20) for key in uu.keys(): val = uu[key] print(key) if type(val) == type({}): for key2 in val.keys(): print(' ' * 4 + key2) val2 = val[key2] if type(val2) == type({}): for key3 in val2.keys(): print(' ' * 8 + key3 + ':' + str(val2[key3])) # print('-=' * 20) geoinfo = json.loads(webdog_to_geojson(uu)) # print(geoinfo) else: # if the old geojson data. geoinfo = {'features': rec.json} if rec: return json.dump(geoinfo['features'], self) else: return False elif url_arr[0] == 'download': self.download(url_arr[1]) elif url_arr[0] == 'delete': self.delete(url_arr[1])
def j_add(self, uid=''): if self.userinfo: pass else: print('User Not Login.') print('=' * 20) print('Hello') post_data = self.get_post_data() # print(post_data) geojson_str = post_data['geojson'] gson = json.loads(geojson_str) print(json.dumps(gson, indent=1)) # maplet_map_id = 'm' + gson['tileLayer']['high']['name'].split('-')[-1] maplet_map_id = 'mv000' if uid: pass else: uid = tools.get_uu4d() while MJson.get_by_id(uid): uid = tools.get_uu4d() return_dic = {'uid': uid} # MJson.add_or_update(uid, 'xxxx', maplet_map_id, gson) try: # MJson.add_or_update_json(uid, '', geojson_str) # print(self.userinfo.uid, ) # print(maplet_map_id), # print(geojson_str) MJson.add_or_update(uid, 'xxxx', maplet_map_id, gson, version=3) return_dic['status'] = 1 # print('Saved successfully!') return json.dump(return_dic, self) except: self.set_status(400) return_dic['status'] = 0 # print('Save Error!') return json.dump(return_dic, self)
def update_meta(self, gson_uid): post_data = self.get_post_data() out_dic = post_data['geojson'] uid = gson_uid return_dic = {'uid': ''} cur_info = MJson.get_by_id(uid) if cur_info.user_id == self.userinfo.uid: pass else: return False MJson.add_or_update_json(uid, self.userinfo.uid, out_dic, post_data) self.redirect('/geojson/')
def download(self, pa_str): ''' Download the GeoJson to file. :param pa_str: :return: ''' uid = pa_str.split('_')[-1].split('.')[0] self.set_header('Content-Type', 'application/force-download') rec = MJson.get_by_id(uid) geojson = rec.json out_arr = [] for key in geojson.keys(): out_arr = out_arr + geojson[key]['features'] out_dic = {"type": "FeatureCollection", "features": out_arr} if rec: return json.dump(out_dic, self)