Coverage for gws-app/gws/plugin/gekos/action.py: 0%
48 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-24 12:46 +0200
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-24 12:46 +0200
1"""GekoS action."""
3from typing import Optional, cast
5import gws
6import gws.lib.crs
7import gws.base.feature
8import gws.base.shape
9import gws.base.action
10import gws.base.database
12import gws.plugin.alkis.action as alkis_action
14from . import core, index
16gws.ext.new.action('gekos')
19class GetXyRequest(gws.Request):
20 """Request to get XY coordinates from a GekoS feature."""
22 fs: Optional[str]
23 """Combined flurstueck code."""
24 ad: Optional[str]
25 """Combined adresse code."""
28class GetFsResponse(gws.Response):
29 feature: gws.FeatureProps
32class Config(gws.base.action.Config):
33 """GekoS action configuration."""
35 index: Optional[core.IndexConfig]
36 """GekoS index configuration."""
37 templates: Optional[list[gws.ext.config.template]]
38 """Feature templates."""
41_DEFAULT_TEMPLATES = [
42 gws.Config(subject='feature.title', type='html', text='{vollnummer}'),
43 gws.Config(
44 subject='feature.teaser',
45 type='html',
46 text='Flurstück {vollnummer}',
47 ),
48]
51class Object(gws.base.action.Object):
52 idx: index.Object
53 templates: list[gws.Template]
55 def configure(self):
56 self.idx = self.create_child_if_configured(index.Object, self.cfg('index'))
57 p = self.cfg('templates', default=[]) + _DEFAULT_TEMPLATES
58 self.templates = [self.create_child(gws.ext.object.template, c) for c in p]
60 @gws.ext.command.get('gekosGetXY')
61 def get_xy(self, req: gws.WebRequester, p: GetXyRequest) -> gws.ContentResponse:
62 project = None
63 if p.projectUid:
64 project = req.user.require_project(p.projectUid)
66 alkis = cast(alkis_action.Object, self.root.app.actionMgr.find_action(project, 'alkis', req.user))
67 if not alkis:
68 gws.log.error(f'gekos: alkis action not found, {p.projectUid=}')
69 return gws.ContentResponse(mime='text/plain', content='error:')
71 lst = None
72 if p.fs:
73 lst, _ = alkis.find_flurstueck_objects(req, alkis_action.FindFlurstueckRequest(combinedFlurstueckCode=p.fs))
74 elif p.ad:
75 lst, _ = alkis.find_adresse_objects(req, alkis_action.FindAdresseRequest(combinedAdresseCode=p.ad))
77 if not lst:
78 gws.log.error(f'gekos: not found, {p.fs=} {p.ad=}')
79 return gws.ContentResponse(mime='text/plain', content='error:')
81 return gws.ContentResponse(mime='text/plain', content='{:.3f};{:.3f}'.format(lst[0].x, lst[0].y))