def GetAreas(request, filter_by={}, name_like=None): """Get data for FIAS address objects filtered by 'filter_by' struct """ session = Session() if filter_by is None: filter_by = {'parentid': None} cols = set(fias_db.Addrobj({'id': -1}).collist()) for key in list(filter_by): if key not in cols: del filter_by[key] elif filter_by[key] == '': filter_by[key] = 0 filter_by['livestatus'] = True q = session.query(fias_db.Addrobj).filter_by(**filter_by) if name_like: # TODO: check MSSQL q = q.filter(fias_db.Addrobj.formalname.ilike(name_like)) if q.count() > return_limit: return "Too big list" else: res = [] for one in q.all(): ao = melt.fias_AO(one, session=session) one_ = dict( formalname=one.formalname, shortname=one.shortname, aolevel=one.aolevel, code=one.code, okato=str(one.okato) if one.okato else '', postalcode=str(one.postalcode) if one.postalcode else '', name=ao.name, fullname=ao.fullname, aoguid=str(one.aoguid)) res.append(one_) return res
def GetAreas(request, filter_by={}, name_like=None): """Get data for FIAS address objects filtered by 'filter_by' struct """ session = Session() if filter_by is None: filter_by = {'parentid': None} cols = set(fias_db.Addrobj({'id': -1}).collist()) for key in list(filter_by): if key not in cols: del filter_by[key] elif filter_by[key] == '': filter_by[key] = 0 filter_by['livestatus'] = True q = session.query(fias_db.Addrobj).filter_by(**filter_by) if name_like: # TODO: check MSSQL q = q.filter(fias_db.Addrobj.formalname.ilike(name_like)) if q.count() > return_limit: return "Too big list" else: res = [] for one in q.all(): ao = melt.fias_AO(one, session=session) one_ = dict(formalname=one.formalname, shortname=one.shortname, aolevel=one.aolevel, code=one.code, okato=str(one.okato) if one.okato else '', postalcode=str(one.postalcode) if one.postalcode else '', name=ao.name, fullname=ao.fullname, aoguid=str(one.aoguid) ) res.append(one_) return res
def GetAreaProperties(request, guid, propnames): session = Session() #one = session.query(fias_db.Addrobj).get(aid) one = melt.fias_AO(guid, session=session) res = {} for prop in propnames: res[prop] = getattr(one, prop) return res
def GetBuildings(request, ao_guid): session = Session() #one = session.query(fias_db.Addrobj).get(aid) one = melt.fias_AO(ao_guid, session=session) res = [] for bld in one.subB('all_b'): res.append({'guid': str(bld.houseguid), 'onestr': bld.onestr}) return res
def rest_buildings_view(request): #Make check for malformed guid try: ao_guid = uuid.UUID(request.matchdict["ao_guid"]) except ValueError: raise HTTPBadRequest() myself = melt.fias_AO(ao_guid) request.response.content_type = 'text/xml' return {"list": myself.subB('all_b')}
def GetBuildings(request, ao_guid): session = Session() #one = session.query(fias_db.Addrobj).get(aid) one = melt.fias_AO(ao_guid, session=session) res = [] for bld in one.subB('all_b'): res.append({'guid': str(bld.houseguid), 'onestr': bld.onestr }) return res
def GetAreaProperty(request, guid, propname): session = Session() #one = session.query(fias_db.Addrobj).get(aid) one = melt.fias_AO(guid, session=session) return getattr(one, propname)