def getMap(): """ Returns default map defined in eMonitor :return: :py:class:`emonitor.modules.maps.map.Map` """ return Map.getDefaultMap()
def action(**kwargs): """ implementation of map-message specific actions :param kwargs: list of parameters: action, mid and all arguments of ajax requests :return: results of action """ if kwargs.get('action') == 'render': """ render string with restructured text engine """ return getreStructuredText(kwargs.get('text')) elif kwargs.get('action') == 'mapconfig': """ open overlay map with config values """ try: config = json.loads(kwargs.get('config', '')) except ValueError: config = {} if not config.get('lat'): config['lat'] = Settings.get('defaultLat') if not config.get('lng'): config['lng'] = Settings.get('defaultLng') config['map'] = Map.getDefaultMap() kwargs.update(**config) #print ">>>>>", kwargs return render_template("frontend.messages_map.html", **kwargs) return ""
def getFrontendData(self): """ Deliver frontend content of module streets (ajax) :return: rendered template as string or json dict """ if request.args.get('action') == 'streetcoords': # get map parameter for given streetid if request.args.get('id') not in ['', 'None']: street = Street.getStreets(id=request.args.get('id')) return {'lat': street.lat, 'lng': street.lng, 'zoom': street.zoom, 'way': street.navigation, 'cityid': street.cityid, 'cityname': street.city.name} elif request.args.get('action') == 'housecoords': # deliver center of housenumbers if request.args.get('streetid') != '' and request.args.get('housenumber') != '': street = Street.getStreet(id=request.args.get('streetid')) hnumber = street.getHouseNumber(number=request.args.get('housenumber').split()[0]) if hnumber: return hnumber.getPosition(0) return {'lat': street.lat, 'lng': street.lng} return {} elif request.args.get('action') == 'defaultposition': return {'defaultlat': float(Settings.get('defaultLat')), 'defaultlng': float(Settings.get('defaultLng')), 'defaultzoom': int(Settings.get('defaultZoom'))} elif request.args.get('action') == 'alarmposition': alarm = Alarm.getAlarms(id=request.args.get('alarmid')) if alarm: return {'id': request.args.get('alarmid'), 'alarmlat': alarm.lat, 'alarmlng': alarm.lng, 'alarmzoom': alarm.zoom, 'marker': alarm.marker, 'alarmprio': alarm.priority, 'alarmstreet': alarm.street.name, 'alarmstreetno': alarm.get('streetno'), 'alarmstreet2': alarm.get('address2'), 'alarmcity': alarm.city.name, 'alarmsubcity': alarm.street.subcity} else: return {'id': '0'} elif request.args.get('action') == 'streetslookup': streets = {} cities = {} for c in City.getCities(): cities[c.id] = c.name for k, street in c.streets.iteritems(): if street.active: try: streets[str(street.id)] = '%s (%s)' % (street.name, c.name) except: streets[str(street.id)] = '%s (-%s-)' % (street.name, street.cityid) return streets elif request.args.get('action') == 'defaultmap': dmap = Map.getDefaultMap() return {'tileserver': dmap.tileserver, 'name': dmap.name} return ""
def addParameters(self, **kwargs): """ Add special parameters for map widget *messages.map.\** :param kwargs: list of parameters for update """ if 'message' in kwargs: text = kwargs['message'].get('text') template = kwargs['message'].get('template') # todo: define templates mapconfig = kwargs['message'].get('mapconfig') map = Map.getDefaultMap() else: text = "" template = "" # todo define templates mapconfig = "" map = None kwargs.update({'map': map, 'text': text, 'mapconfig': mapconfig, 'template': template}) self.params = kwargs
def getAdminContent(self, **params): """ Deliver admin content of module alarmobjects :param params: use given parameters of request :return: rendered template as string """ module = request.view_args['module'].split('/') def chunks(l, n): return [l[i:i + n] for i in range(0, len(l), n)] if len(module) > 1: # type definition if module[1] == 'types': if request.method == 'POST': if request.form.get( 'action') == 'createalarmobjecttype': # add type params.update({'alarmobjecttype': AlarmObjectType('', '')}) return render_template( 'admin.alarmobjects.types_action.html', **params) elif request.form.get( 'action') == 'savealarmobjecttype': # save type if request.form.get( 'alarmobjecttype_id') == 'None': # add new type alarmobjecttype = AlarmObjectType('', '') db.session.add(alarmobjecttype) else: # update existing alarmobjecttype = AlarmObjectType.getAlarmObjectTypes( id=int(request.form.get('alarmobjecttype_id'))) alarmobjecttype.name = request.form.get( 'alarmobjecttype_name') alarmobjecttype.remark = request.form.get( 'alarmobjecttype_remark') db.session.commit() elif request.form.get('action').startswith( 'detailobjecttype'): # edit type alarmobjecttype = AlarmObjectType.getAlarmObjectTypes( id=int(request.form.get('action').split('_')[-1])) params.update({'alarmobjecttype': alarmobjecttype}) return render_template( 'admin.alarmobjects.types_action.html', **params) elif request.form.get('action').startswith( 'deleteobjecttype_'): # delete type db.session.delete( AlarmObjectType.getAlarmObjectTypes( id=int(request.form.get('action').split('_')[-1]))) db.session.commit() params.update( {'alarmobjecttypes': AlarmObjectType.getAlarmObjectTypes()}) return render_template('admin.alarmobjects.types.html', **params) elif module[1] == 'fields': if request.method == 'POST': if request.form.get( 'action') == 'updatefield': # update fields Settings.set('alarmobjectfields', [ i for i in chunks(request.form.getlist('fieldname'), 2) if i[0] != '' ]) db.session.commit() params.update({'fields': Settings.get('alarmobjectfields', [])}) return render_template('admin.alarmobjects.fields.html', **params) else: # base view if request.method == 'POST': streets = Street.getStreets() if request.form.get( 'action') == 'createalarmobject': # add alarmobject params.update({ 'alarmobject': AlarmObject('', 0, '', Settings.get('defaultLat'), Settings.get('defaultLng'), Settings.get('defaultZoom'), '', '', '', 0, 0), 'streets': streets, 'selectedstreet': '', 'map': Map.getDefaultMap(), 'alarmobjecttypes': AlarmObjectType.getAlarmObjectTypes() }) return render_template('admin.alarmobjects_actions.html', **params) elif request.form.get('action') == 'savealarmobject': # save if request.form.get('alarmobject_id') == 'None': # add new alarmobject = AlarmObject('', 0, '', 0, 0, 0, '', '', '', 0, 0) db.session.add(alarmobject) else: # update existing alarmobject = AlarmObject.getAlarmObjects( id=request.form.get('alarmobject_id')) alarmobject.name = request.form.get('edit_name') alarmobject._streetid = request.form.get('streetid') alarmobject._objecttype = int( request.form.get('edit_objecttype')) alarmobject.remark = request.form.get('edit_remark') if request.form.get('edit_position') == '1': alarmobject.lat = request.form.get('edit_lat') alarmobject.lng = request.form.get('edit_lng') alarmobject.zoom = request.form.get('edit_zoom') alarmobject.streetno = request.form.get('edit_streetno') alarmobject.alarmplan = request.form.get('edit_alarmplan') alarmobject.bma = request.form.get('edit_bma') alarmobject.active = int(request.form.get('edit_active', '0')) db.session.commit() elif request.form.get( 'action' ) == 'savealarmobjectattributes': # save attributes alarmobject = AlarmObject.getAlarmObjects( id=request.form.get('alarmobject_id')) for field in Settings.get('alarmobjectfields', []): # store attributes if 'edit_%s' % field[0] in request.form: alarmobject.set(field[0], request.form.get('edit_%s' % field[0])) db.session.commit() elif request.form.get( 'action') == 'savealarmobjectaao': # save aao alarmobject = AlarmObject.getAlarmObjects( id=request.form.get('alarmobject_id')) if alarmobject: alarmobject.set('cars1', [ c for c in request.form.get('cars1').split(';') if c != '' ]) alarmobject.set('cars2', [ c for c in request.form.get('cars2').split(';') if c != '' ]) alarmobject.set('material', [ c for c in request.form.get('material').split(';') if c != '' ]) db.session.commit() elif request.form.get('action').startswith( 'editalarmobject_'): # edit alarmobject alarmobject = AlarmObject.getAlarmObjects( id=int(request.form.get('action').split('_')[-1])) params.update({ 'alarmobject': alarmobject, 'streets': streets, 'selectedstreet': '%s (%s)' % (alarmobject.street.name, alarmobject.street.city.name), 'map': Map.getDefaultMap(), 'alarmobjecttypes': AlarmObjectType.getAlarmObjectTypes(), 'fields': Settings.get('alarmobjectfields', []), 'cars': Car.getCars(deptid=Department.getDefaultDepartment().id) }) return render_template('admin.alarmobjects_actions.html', **params) elif request.form.get('action').startswith( 'deletealarmobject_'): # delete alarmobject db.session.delete( AlarmObject.getAlarmObjects( id=int(request.form.get('action').split('_')[-1]))) db.session.commit() params.update({ 'alarmobjects': AlarmObject.getAlarmObjects(active=0), 'alarmobjecttypes': AlarmObjectType.getAlarmObjectTypes() }) return render_template('admin.alarmobjects.html', **params)
def getFrontendData(self): """ Deliver frontend content of module streets (ajax) :return: rendered template as string or json dict """ if request.args.get( 'action' ) == 'streetcoords': # get map parameter for given streetid if request.args.get('id') not in ['', 'None']: street = Street.getStreets(id=request.args.get('id')) return { 'lat': street.lat, 'lng': street.lng, 'zoom': street.zoom, 'way': street.navigation, 'cityid': street.cityid, 'cityname': street.city.name } elif request.args.get( 'action') == 'housecoords': # deliver center of housenumbers if request.args.get('streetid') != '' and request.args.get( 'housenumber') != '': street = Street.getStreet(id=request.args.get('streetid')) hnumber = street.getHouseNumber( number=request.args.get('housenumber').split()[0]) if hnumber: return hnumber.getPosition(0) return {'lat': street.lat, 'lng': street.lng} return {} elif request.args.get('action') == 'defaultposition': return { 'defaultlat': float(Settings.get('defaultLat')), 'defaultlng': float(Settings.get('defaultLng')), 'defaultzoom': int(Settings.get('defaultZoom')) } elif request.args.get('action') == 'alarmposition': alarm = Alarm.getAlarms(id=request.args.get('alarmid')) if alarm: return { 'id': request.args.get('alarmid'), 'alarmlat': alarm.lat, 'alarmlng': alarm.lng, 'alarmzoom': alarm.zoom, 'marker': alarm.marker, 'alarmprio': alarm.priority, 'alarmstreet': alarm.street.name, 'alarmstreetno': alarm.get('streetno'), 'alarmstreet2': alarm.get('address2'), 'alarmcity': alarm.city.name, 'alarmsubcity': alarm.street.subcity } else: return {'id': '0'} elif request.args.get('action') == 'streetslookup': streets = {} cities = {} for c in City.getCities(): cities[c.id] = c.name for k, street in c.streets.iteritems(): if street.active: try: streets[str( street.id)] = '%s (%s)' % (street.name, c.name) except: streets[str(street.id)] = '%s (-%s-)' % (street.name, street.cityid) return streets elif request.args.get('action') == 'defaultmap': dmap = Map.getDefaultMap() return {'tileserver': dmap.tileserver, 'name': dmap.name} return ""
def getAdminContent(self, **params): """ Deliver admin content of module streets :param params: use given parameters of request :return: rendered template as string """ module = request.view_args['module'].split('/') if len(module) < 2: if City.getDefaultCity(): module.append(u'{}'.format(City.getDefaultCity().id)) else: module.append(u'1') if len(module) == 2: # cities if module[1] == '0': # city list if request.method == 'POST': if request.form.get('action').startswith('detailcity_'): # edit city params.update({'city': City.getCities(id=request.form.get('action').split('_')[-1]), 'departments': Department.getDepartments(), 'maps': Map.getMaps()}) return render_template('admin.streets.city_edit.html', **params) elif request.form.get('action') == 'updatecity': # update existing city if request.form.get('city_id') != 'None': # update city city = City.getCities(id=request.form.get('city_id')) city.name = request.form.get('cityname') city.subcity = request.form.get('subcity') city._dept = request.form.get('department') city.mapname = request.form.get('citymap') city.color = request.form.get('colorname') city.default = request.form.get('citydefault') city.osmid = request.form.get('osmid') city.osmname = request.form.get('osmname') else: # add city city = City(request.form.get('cityname'), request.form.get('department'), request.form.get('citymap'), request.form.get('citydefault'), request.form.get('subcity'), request.form.get('colorname'), request.form.get('osmid'), request.form.get('osmname')) db.session.add(city) db.session.commit() cache.clear() elif request.form.get('action') == 'createcity': # add city params.update({'city': City('', '', '', '', '', '', 0, ''), 'departments': Department.getDepartments(), 'maps': Map.getMaps()}) return render_template('admin.streets.city_edit.html', **params) elif request.form.get('action').startswith('deletecity_'): # delete city db.session.delete(City.getCities(id=request.form.get('action').split('_')[-1])) db.session.commit() self.updateAdminSubNavigation() cache.clear() params.update({'cities': City.getCities()}) return render_template('admin.streets.city_list.html', **params) else: # show city details if request.method == 'POST': if request.form.get('action').startswith('detailstreet_'): # edit street tileserver = {'lat': Settings.get('defaultLat'), 'lng': Settings.get('defaultLng'), 'zoom': Settings.get('defaultZoom'), 'map': Map.getDefaultMap()} params.update({'street': Street.getStreets(id=request.form.get('action').split('_')[-1]), 'cities': City.getCities(), 'maps': Map.getMaps(), 'tileserver': tileserver}) return render_template('admin.streets_edit.html', **params) elif request.form.get('action') == 'createstreet': # add street tileserver = {'lat': Settings.get('defaultLat'), 'lng': Settings.get('defaultLng'), 'zoom': Settings.get('defaultZoom'), 'map': Map.getDefaultMap()} params.update({'street': Street('', '', int(module[1]), '', '', '', '', '', ''), 'cities': City.getCities(), 'maps': Map.getMaps(), 'tileserver': tileserver}) return render_template('admin.streets_edit.html', **params) elif request.form.get('action').startswith('deletestreets_'): # delete street db.session.delete(Street.getStreets(id=request.form.get('action').split('_')[-1])) db.session.commit() cache.clear() elif request.form.get('action') == 'savestreet': # save street if request.form.get('street_id') != 'None': # update existing street street = Street.getStreets(id=request.form.get('street_id')) street.name = request.form.get('edit_name') street.navigation = request.form.get('edit_navigation') c = request.form.get('edit_cityid').split('_') if len(c) < 2: c.append('') street.cityid = c[0] street.subcity = c[1] street.lat = request.form.get('edit_lat') street.lng = request.form.get('edit_lng') street.zoom = request.form.get('edit_zoom') street.active = request.form.get('edit_active') db.session.commit() #cache.delete_memoized(City.streets) else: # add street c = request.form.get('edit_cityid').split('_') if len(c) < 2: c.append('') # subcity city = [ct for ct in City.getCities() if str(ct.id) == c[0]][0] city.addStreet(Street(request.form.get('edit_name'), request.form.get('edit_navigation'), int(c[0]), c[1], request.form.get('edit_lat'), request.form.get('edit_lng'), request.form.get('edit_zoom'), request.form.get('edit_active'), '')) db.session.commit() cache.clear() try: streets = Street.getStreets(cityid=module[-1]) except AttributeError: streets = [] chars = {} for s in streets: chars[s.name[0].upper()] = 0 params.update({'streets': streets, 'chars': sorted(chars.keys()), 'city': City.getCities(id=module[-1])}) return render_template('admin.streets.html', **params) return "streets"
def getFrontendContent(**params): """ Deliver frontend content of module maps :return: data of maps """ if 'area' not in params.keys() and request.args.get('area', '') != '': params['area'] = request.args.get('area') if 'area' in params.keys() and params['area'] in ['west', 'center', 'east']: # select view tiledefs = [d for d in Settings.get('mapitemdefinition') if d['parameters']['tileserver'] == '1'] return render_template('frontend.map.html', maps=Map.getMaps(), defaultlat=Settings.get('defaultLat'), defaultlng=Settings.get('defaultLng'), defaultzoom=Settings.get('defaultZoom'), maptype="" or Map.getDefaultMap(), tiledefs=tiledefs) return "default"
def loadStreetsFromOsm(city=None, format="html"): """ Load all Streets from OpenStreetMap :param optional city: :py:class:`emonitor.modules.streets.city.City` :param optional format: return format, *html*=rendered template, streets as OrderedDict :return: rendered template or dict """ global URL if not city: city = City.getDefaultCity() map_details = Map.getDefaultMap().getMapBox(tilepath=current_app.config.get("PATH_TILES")) SEARCHSTRING = 'area[name~"%s"];way(%s,%s,%s,%s)(area)[highway][name];(._;>;);out;' % ( city.name, map_details["min_latdeg"], map_details["min_lngdeg"], map_details["max_latdeg"], map_details["max_lngdeg"], ) # search all streets for given city r = requests.post(URL, data={"data": SEARCHSTRING}) xmldoc = minidom.parseString(r.content) nodes = xmldoc.getElementsByTagName("node") ways = xmldoc.getElementsByTagName("way") dbosmids = [int(s.osmid or 0) for s in city.getCities()] streets = OrderedDict() n = {} for node in nodes: n[int(node.attributes["id"].value)] = (float(node.attributes["lat"].value), float(node.attributes["lon"].value)) for way in ways: nds = [] osmids = [] name = "" for tag in way.childNodes: if tag.nodeName == "tag" and tag.attributes["k"].value == "name": name = tag.attributes["v"].value osmids.append(int(way.attributes["id"].value)) if tag.nodeName == "nd": _nid = int(tag.attributes["ref"].value) if _nid in n.keys(): nds.append(n[_nid]) if name not in streets.keys(): streets[name] = {"osmids": osmids, "nodes": nds, "indb": False} else: streets[name]["osmids"].extend(osmids) streets[name]["nodes"].extend(nds) if len(set(osmids).intersection(set(dbosmids))) > 0: streets[name]["indb"] = True streets = OrderedDict(sorted(streets.items(), key=lambda t: t[0])) if format == "html": # html output return render_template("admin.streets_osm.html", streets=streets, city=city) else: # data output for name in streets: points = streets[name]["nodes"] if len(points) > 2: cent = centroid_of_polygon(points) streets[name]["center"] = cent elif len(points) == 2: streets[name]["center"] = (((points[0][0] + points[1][0]) / 2), ((points[0][1] + points[1][1]) / 2)) else: streets[name]["center"] = (0.0, 0.0) return streets
def getAdminContent(self, **params): """ Deliver admin content of module streets :param params: use given parameters of request :return: rendered template as string """ module = request.view_args['module'].split('/') if len(module) < 2: if City.getDefaultCity(): module.append(u'{}'.format(City.getDefaultCity().id)) else: module.append(u'1') if len(module) == 2: # cities if module[1] == '0': # city list if request.method == 'POST': if request.form.get('action').startswith('detailcity_'): # edit city params.update({'city': City.getCities(id=request.form.get('action').split('_')[-1]), 'departments': Department.getDepartments(), 'maps': Map.getMaps()}) return render_template('admin.streets.city_edit.html', **params) elif request.form.get('action') == 'updatecity': # update existing city if request.form.get('city_id') != 'None': # update city city = City.getCities(id=request.form.get('city_id')) city.name = request.form.get('cityname') city.subcity = request.form.get('subcity') city.dept = request.form.get('department') city.mapname = request.form.get('citymap') city.color = request.form.get('colorname') city.default = request.form.get('citydefault') city.osmid = request.form.get('osmid') city.osmname = request.form.get('osmname') else: # add city city = City(request.form.get('cityname'), request.form.get('department'), request.form.get('citymap'), request.form.get('citydefault'), request.form.get('subcity'), request.form.get('colorname'), request.form.get('osmid'), request.form.get('osmname')) db.session.add(city) db.session.commit() cache.clear() elif request.form.get('action') == 'createcity': # add city params.update({'city': City('', '', '', '', '', '', 0, ''), 'departments': Department.getDepartments(), 'maps': Map.getMaps()}) return render_template('admin.streets.city_edit.html', **params) elif request.form.get('action').startswith('deletecity_'): # delete city db.session.delete(City.getCities(id=request.form.get('action').split('_')[-1])) db.session.commit() self.updateAdminSubNavigation() cache.clear() params.update({'cities': City.getCities()}) return render_template('admin.streets.city_list.html', **params) else: # show city details if request.method == 'POST': if request.form.get('action').startswith('detailstreet_'): # edit street tileserver = {'lat': Settings.get('defaultLat'), 'lng': Settings.get('defaultLng'), 'zoom': Settings.get('defaultZoom'), 'map': Map.getDefaultMap()} params.update({'street': Street.getStreets(id=request.form.get('action').split('_')[-1]), 'cities': City.getCities(), 'maps': Map.getMaps(), 'tileserver': tileserver}) return render_template('admin.streets_edit.html', **params) elif request.form.get('action') == 'createstreet': # add street tileserver = {'lat': Settings.get('defaultLat'), 'lng': Settings.get('defaultLng'), 'zoom': Settings.get('defaultZoom'), 'map': Map.getDefaultMap()} params.update({'street': Street('', '', int(module[1]), '', '', '', '', '', ''), 'cities': City.getCities(), 'maps': Map.getMaps(), 'tileserver': tileserver}) return render_template('admin.streets_edit.html', **params) elif request.form.get('action').startswith('deletestreets_'): # delete street db.session.delete(Street.getStreets(id=request.form.get('action').split('_')[-1])) db.session.commit() cache.clear() elif request.form.get('action', '').startswith('deleteallsteets_'): print "delete all streets of", request.form.get('action').split('_')[-1] for s in Street.getStreets(cityid=request.form.get('action').split('_')[-1]): db.session.delete(s) db.session.commit() cache.clear() elif request.form.get('action') == 'savestreet': # save street if request.form.get('street_id') != 'None': # update existing street street = Street.getStreets(id=request.form.get('street_id')) street.name = request.form.get('edit_name') street.navigation = request.form.get('edit_navigation') c = request.form.get('edit_cityid').split('_') if len(c) < 2: c.append('') street.cityid = c[0] street.subcity = c[1] street.lat = request.form.get('edit_lat') street.lng = request.form.get('edit_lng') street.zoom = request.form.get('edit_zoom') street.active = request.form.get('edit_active') db.session.commit() #cache.delete_memoized(City.streets) else: # add street c = request.form.get('edit_cityid').split('_') if len(c) < 2: c.append('') # subcity city = [ct for ct in City.getCities() if str(ct.id) == c[0]][0] city.addStreet(Street(request.form.get('edit_name'), request.form.get('edit_navigation'), int(c[0]), c[1], request.form.get('edit_lat'), request.form.get('edit_lng'), request.form.get('edit_zoom'), request.form.get('edit_active'), 0)) db.session.commit() cache.clear() try: streets = Street.getStreets(cityid=module[-1]) except AttributeError: streets = [] chars = {} for s in streets: chars[s.name[0].upper()] = 0 params.update({'streets': streets, 'chars': sorted(chars.keys()), 'city': City.getCities(id=module[-1])}) return render_template('admin.streets.html', **params) return "streets"
def getAdminContent(self, **params): """ Deliver admin content of module alarmobjects :param params: use given parameters of request :return: rendered template as string """ module = request.view_args['module'].split('/') def chunks(l, n): return [l[i:i + n] for i in range(0, len(l), n)] if len(module) > 1: # type definition if module[1] == 'types': if request.method == 'POST': if request.form.get('action') == 'createalarmobjecttype': # add type params.update({'alarmobjecttype': AlarmObjectType('', '')}) return render_template('admin.alarmobjects.types_action.html', **params) elif request.form.get('action') == 'savealarmobjecttype': # save type if request.form.get('alarmobjecttype_id') == 'None': # add new type alarmobjecttype = AlarmObjectType('', '') db.session.add(alarmobjecttype) else: # update existing alarmobjecttype = AlarmObjectType.getAlarmObjectTypes(id=int(request.form.get('alarmobjecttype_id'))) alarmobjecttype.name = request.form.get('alarmobjecttype_name') alarmobjecttype.remark = request.form.get('alarmobjecttype_remark') db.session.commit() elif request.form.get('action').startswith('detailobjecttype'): # edit type alarmobjecttype = AlarmObjectType.getAlarmObjectTypes(id=int(request.form.get('action').split('_')[-1])) params.update({'alarmobjecttype': alarmobjecttype}) return render_template('admin.alarmobjects.types_action.html', **params) elif request.form.get('action').startswith('deleteobjecttype_'): # delete type db.session.delete(AlarmObjectType.getAlarmObjectTypes(id=int(request.form.get('action').split('_')[-1]))) db.session.commit() params.update({'alarmobjecttypes': AlarmObjectType.getAlarmObjectTypes()}) return render_template('admin.alarmobjects.types.html', **params) elif module[1] == 'fields': if request.method == 'POST': if request.form.get('action') == 'updatefield': # update fields Settings.set('alarmobjectfields', [i for i in chunks(request.form.getlist('fieldname'), 2) if i[0] != '']) db.session.commit() params.update({'fields': Settings.get('alarmobjectfields', [])}) return render_template('admin.alarmobjects.fields.html', **params) else: # base view if request.method == 'POST': streets = Street.getStreets() if request.form.get('action') == 'createalarmobject': # add alarmobject params.update({'alarmobject': AlarmObject('', 0, '', Settings.get('defaultLat'), Settings.get('defaultLng'), Settings.get('defaultZoom'), '', '', '', 0, 0), 'streets': streets, 'selectedstreet': '', 'map': Map.getDefaultMap(), 'alarmobjecttypes': AlarmObjectType.getAlarmObjectTypes()}) return render_template('admin.alarmobjects_actions.html', **params) elif request.form.get('action') == 'savealarmobject': # save if request.form.get('alarmobject_id') == 'None': # add new alarmobject = AlarmObject('', 0, '', 0, 0, 0, '', '', '', 0, 0) db.session.add(alarmobject) else: # update existing alarmobject = AlarmObject.getAlarmObjects(id=request.form.get('alarmobject_id')) alarmobject.name = request.form.get('edit_name') alarmobject._streetid = request.form.get('streetid') alarmobject._objecttype = int(request.form.get('edit_objecttype')) alarmobject.remark = request.form.get('edit_remark') if request.form.get('edit_position') == '1': alarmobject.lat = request.form.get('edit_lat') alarmobject.lng = request.form.get('edit_lng') alarmobject.zoom = request.form.get('edit_zoom') alarmobject.streetno = request.form.get('edit_streetno') alarmobject.alarmplan = request.form.get('edit_alarmplan') alarmobject.bma = request.form.get('edit_bma') alarmobject.active = int(request.form.get('edit_active', '0')) db.session.commit() elif request.form.get('action') == 'savealarmobjectattributes': # save attributes alarmobject = AlarmObject.getAlarmObjects(id=request.form.get('alarmobject_id')) for field in Settings.get('alarmobjectfields', []): # store attributes if 'edit_%s' % field[0] in request.form: alarmobject.set(field[0], request.form.get('edit_%s' % field[0])) db.session.commit() elif request.form.get('action') == 'savealarmobjectaao': # save aao alarmobject = AlarmObject.getAlarmObjects(id=request.form.get('alarmobject_id')) if alarmobject: alarmobject.set('cars1', [c for c in request.form.get('cars1').split(';') if c != '']) alarmobject.set('cars2', [c for c in request.form.get('cars2').split(';') if c != '']) alarmobject.set('material', [c for c in request.form.get('material').split(';') if c != '']) db.session.commit() elif request.form.get('action').startswith('editalarmobject_'): # edit alarmobject alarmobject = AlarmObject.getAlarmObjects(id=int(request.form.get('action').split('_')[-1])) params.update({'alarmobject': alarmobject, 'streets': streets, 'selectedstreet': '%s (%s)' % (alarmobject.street.name, alarmobject.street.city.name), 'map': Map.getDefaultMap(), 'alarmobjecttypes': AlarmObjectType.getAlarmObjectTypes(), 'fields': Settings.get('alarmobjectfields', []), 'cars': Car.getCars(deptid=Department.getDefaultDepartment().id)}) return render_template('admin.alarmobjects_actions.html', **params) elif request.form.get('action').startswith('deletealarmobject_'): # delete alarmobject db.session.delete(AlarmObject.getAlarmObjects(id=int(request.form.get('action').split('_')[-1]))) db.session.commit() params.update({'alarmobjects': AlarmObject.getAlarmObjects(active=0), 'alarmobjecttypes': AlarmObjectType.getAlarmObjectTypes()}) return render_template('admin.alarmobjects.html', **params)