def addHouseNumber(self, number, points): """ Add housenumber for street :param number: housenumber as string :param points: list of points for housenumber """ if number not in [hn.number for hn in self.housenumbers]: db.session.add(Housenumber(self.id, number, yaml.dump(points))) db.session.commit()
def get_housenumber(self): if self.get('id.streetno', '') != '': return Housenumber.getHousenumbers(self.get('id.streetno')) try: n = [n for n in self.street.housenumbers if u'{}'.format(n.number) == self.get('streetno').split(' ')[0]] if len(n) == 1: return n[0] else: return None except: return None
def getAdminData(self): """ Deliver admin content of module streets (ajax) :return: rendered template as string or json dict """ if request.args.get('action') == 'loadcitiesfromosm': # get city list from osm return loadCitiesFromOsm() elif request.args.get('action') == 'createcity': # create cities from osm osmids = [c[0] for c in db.get(City.osmid).all()] i = 0 for c in request.args.get('values').split(","): _id, name = c.split('|') if int(_id) not in osmids: # add city db.session.add(City(name, 1, '', 0, '', '', int(_id), '')) db.session.commit() i += 1 flash(babel.gettext('%(i)s admin.streets.cities.osmcitiesadded', i=i)) self.updateAdminSubNavigation() return '1' elif request.args.get('action') == 'loadstreetsfromosm': # get street list from osm return loadStreetsFromOsm(City.getCities(id=request.args.get('cityid'))) elif request.args.get('action') == 'createstreet': # create streets from osm city = City.getCities(id=request.args.get('cityid')) ids = [int(i) for i in request.args.get('values').split(",")] # ids to create osmdata = loadStreetsFromOsm(city=city, format='data') i = 0 for sname in osmdata: if len(set(osmdata[sname]['osmids']).intersection(set(ids))) > 0: # add street _s = osmdata[sname] city.addStreet( Street(sname, '', int(request.args.get('cityid')), '', _s['center'][0], _s['center'][1], 17, 1, _s['osmids'][0])) i += 1 flash(babel.gettext('%(i)s admin.streets.osmstreetsadded', i=i)) return '1' elif request.args.get('action') == 'loadhnumbersfromosm': if 'streetid' in request.args: streets = Street.getStreets(id=int(request.args.get('streetid'))) elif 'cityid' in request.args: streets = [City.getCities(id=request.args.get('cityid'))] else: streets = Street.getStreets() return str(scheduler.add_job(loadHousenumbersFromOsm, args=[streets])) elif request.args.get('action') == 'loadhnumbers': # load all housenumbers for street street = Street.getStreets(id=request.args.get('streetid')) ret = dict() for hn in street.housenumbers: ret[hn.id] = hn.points return ret elif request.args.get('action') == 'delhousenumber': # delete housenumber hn = Housenumber.getHousenumbers(id=request.args.get('housenumberid')) street = hn.street db.session.delete(hn) db.session.commit() return render_template('admin.streets.housenumber.html', hnumbers=street.housenumbers) elif request.args.get('action') == 'addhousenumber': # add housenumber street = Street.getStreets(id=request.args.get('streetid')) points = [] p = request.args.get('points').split(';') points.append((float(p[0]), float(p[1]))) street.addHouseNumber(request.args.get('hnumber'), points) return render_template('admin.streets.housenumber.html', hnumbers=street.housenumbers) return "NONE"
def getAdminData(self): """ Deliver admin content of module streets (ajax) :return: rendered template as string or json dict """ if request.args.get('action') == 'loadcitiesfromosm': # get city list from osm return loadCitiesFromOsm() elif request.args.get('action') == 'createcity': # create cities from osm osmids = [c[0] for c in db.get(City.osmid).all()] i = 0 for c in request.args.get('values').split(","): _id, name = c.split('|') if int(_id) not in osmids: # add city db.session.add(City(name, 1, '', 0, '', '', int(_id), '')) db.session.commit() i += 1 flash(babel.gettext('%(i)s admin.streets.cities.osmcitiesadded', i=i)) self.updateAdminSubNavigation() return '1' elif request.args.get('action') == 'loadstreetsfromosm': # get street list from osm return loadStreetsFromOsm(City.getCities(id=request.args.get('cityid'))) elif request.args.get('action') == 'createstreet': # create streets from osm city = City.getCities(id=request.args.get('cityid')) ids = [int(i) for i in request.args.get('values').split(",")] # ids to create osmdata = loadStreetsFromOsm(city=city, format='data') i = 0 for sname in osmdata: if len(set(osmdata[sname]['osmids']).intersection(set(ids))) > 0: # add street _s = osmdata[sname] city.addStreet( Street(sname, '', int(request.args.get('cityid')), '', _s['center'][0], _s['center'][1], 17, 1, _s['osmids'][0])) i += 1 flash(babel.gettext('%(i)s admin.streets.osmstreetsadded', i=i)) return '1' elif request.args.get('action') == 'loadhnumbersfromosm': if 'streetid' in request.args: streets = [Street.getStreets(id=int(request.args.get('streetid')))] elif 'cityid' in request.args: #streets = list(City.getCities(id=request.args.get('cityid')).streets) streets = Street.getStreets(cityid=int(request.args.get('cityid'))) else: streets = Street.getStreets() return str(scheduler.add_job(loadHousenumbersFromOsm, args=[streets])) elif request.args.get('action') == 'loadhnumbers': # load all housenumbers for street street = Street.getStreets(id=request.args.get('streetid')) ret = dict() for hn in street.housenumbers: ret[hn.id] = hn.points return ret elif request.args.get('action') == 'delhousenumber': # delete housenumber hn = Housenumber.getHousenumbers(id=request.args.get('housenumberid')) street = hn.street db.session.delete(hn) db.session.commit() return render_template('admin.streets.housenumber.html', hnumbers=street.housenumbers) elif request.args.get('action') == 'addhousenumber': # add housenumber street = Street.getStreets(id=request.args.get('streetid')) points = [] p = request.args.get('points').split(';') points.append((float(p[0]), float(p[1]))) street.addHouseNumber(request.args.get('hnumber'), points) return render_template('admin.streets.housenumber.html', hnumbers=street.housenumbers) return "NONE"