def info(self, req: gws.IWebRequest, p: gws.Params) -> InfoResponse: """Return the project configuration""" project = req.require_project(p.projectUid) locale_uid = p.localeUid if locale_uid not in project.locale_uids: locale_uid = project.locale_uids[0] return InfoResponse( project=gws.props(project, req.user), locale=gws.lib.intl.locale(locale_uid), user=None if req.user.is_guest else gws.props(req.user, req.user))
def test_basic_props(): class A(gws.Object): def props_for(self, user): return {'b': b, 'c': c} class B(gws.Object): def props_for(self, user): return {'me': 'B'} class C(gws.Object): def props_for(self, user): return {'me': 'C'} a, b, c = _objects(A, B, C) a.access = _access('X allow') b.parent = a c.parent = a assert test.dict_of(gws.props(a, _user('X'))) == { 'b': { 'me': 'B' }, 'c': { 'me': 'C' } }
def http_get_features(self, req: gws.IWebRequest, p: GetFeaturesParams) -> gws.ContentResponse: # @TODO the response should be geojson FeatureCollection found = self._get_features(req, p) js = gws.lib.json2.to_string({ 'features': [gws.props(f, req.user, context=self) for f in found] }) return gws.ContentResponse(mime=gws.lib.mime.JSON, content=js)
def _find_and_format(self, req, p: FindFlurstueckParams, template_subjects: t.List[str], soft_limit, hard_limit) -> FindFlurstueckResponse: feature_props_list = [] res = self._find(req, p, soft_limit, hard_limit) for feature in res.features: feature.apply_templates(self.templates, subjects=template_subjects) f = gws.props(feature, req.user, context=self) if f: gws.pop(f, 'attributes') feature_props_list.append(f) return FindFlurstueckResponse(total=res.total, features=sorted( feature_props_list, key=lambda f: f.elements['title']))
def find_features(self, req: gws.IWebRequest, p: Params) -> Response: """Perform a search""" project = req.require_project(p.projectUid) bounds = gws.Bounds( crs=p.crs or project.map.crs, extent=p.bbox or project.map.extent, ) limit = self.limit if p.limit: limit = min(int(p.limit), self.limit) shapes = [] if p.shapes: shapes = [gws.gis.shape.from_props(s) for s in p.shapes] tolerance = None if p.tolerance: tolerance = gws.lib.units.parse(p.tolerance, default=gws.lib.units.PX) args = gws.SearchArgs( bounds=bounds, keyword=(p.keyword or '').strip(), layers=gws.compact( req.acquire('gws.ext.layer', uid) for uid in p.layerUids), limit=limit, project=project, resolution=p.resolution, shapes=shapes, tolerance=tolerance, ) found = runner.run(req, args) for f in found: # @TODO only pull specified props from a feature f.transform_to(args.bounds.crs) f.apply_templates() f.apply_data_model() return Response( features=[gws.props(f, req.user, context=self) for f in found])
def test_props_with_implicit_access(): class A(gws.Object): def props_for(self, user): return {'b': b, 'c': c} class B(gws.Object): def props_for(self, user): return {'me': 'B'} class C(gws.Object): def props_for(self, user): return {'d': d} class D(gws.Object): def props_for(self, user): return {'me': 'D'} a, b, c, d = _objects(A, B, C, D) a.access = _access('X allow') b.access = _access('X deny') assert test.dict_of(gws.props(a, _user('X'))) == {'c': {'d': {'me': 'D'}}}
def api_get_features(self, req: gws.IWebRequest, p: GetFeaturesParams) -> GetFeaturesResponse: """Get a list of features in a bounding box""" found = self._get_features(req, p) return GetFeaturesResponse(features=[gws.props(f, req.user, context=self) for f in found])
def _resp(self, req): return Response(user=gws.props(req.user, req.user))