Coverage for gws-app/gws/plugin/gekos/action.py: 0%
45 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-05 13:35 +0200
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-05 13:35 +0200
1"""The ``gekos`` action."""
3from typing import Optional, cast
5import gws
6import gws.lib.crs
7import gws.base.feature
8import gws.lib.shape
9import gws.base.action
10import gws.base.database
12import gws.plugin.alkis.action as alkis_action
14from . import core, index
17class GetXyRequest(gws.Request):
18 """Request for the coordinates of a parcel or an address."""
20 fs: Optional[str]
21 """Combined parcel (Flurstueck) code."""
22 ad: Optional[str]
23 """Combined address code."""
26class GetFsResponse(gws.Response):
27 """Response with a parcel feature."""
29 feature: gws.FeatureProps
30 """The parcel feature."""
33@gws.ext.config.action('gekos')
34class Config(gws.base.action.Config):
35 """Integration with the GekoS-Bau software."""
37 index: Optional[core.IndexConfig]
38 """Index of GekoS records loaded from gek-online."""
39 templates: Optional[list[gws.ext.config.template]]
40 """Templates for GekoS features."""
43_DEFAULT_TEMPLATES = [
44 gws.Config(subject='feature.title', type='html', text='{vollnummer}'),
45 gws.Config(
46 subject='feature.teaser',
47 type='html',
48 text='Flurstück {vollnummer}',
49 ),
50]
53@gws.ext.object.action('gekos')
54class Object(gws.base.action.Object):
55 """GekoS action."""
57 idx: index.Object
58 """The GekoS index, or ``None`` if not configured."""
59 templates: list[gws.Template]
60 """Feature templates."""
62 def configure(self):
63 self.idx = self.create_child_if_configured(index.Object, self.cfg('index'))
64 p = self.cfg('templates', default=[]) + _DEFAULT_TEMPLATES
65 self.templates = [self.create_child(gws.ext.object.template, c) for c in p]
67 @gws.ext.command.get('gekosGetXY')
68 def get_xy(self, req: gws.WebRequester, p: GetXyRequest) -> gws.ContentResponse:
69 """Return the coordinates of a parcel or an address."""
70 project = None
71 if p.projectUid:
72 project = req.user.require_project(p.projectUid)
74 alkis = cast(alkis_action.Object, self.root.app.actionMgr.find_action(project, 'alkis', req.user))
75 if not alkis:
76 gws.log.error(f'gekos: alkis action not found, {p.projectUid=}')
77 return gws.ContentResponse(mimeType='text/plain', content='error:')
79 lst = None
80 if p.fs:
81 lst, _ = alkis.find_flurstueck_objects(req, alkis_action.FindFlurstueckRequest(combinedFlurstueckCode=p.fs))
82 elif p.ad:
83 lst, _ = alkis.find_adresse_objects(req, alkis_action.FindAdresseRequest(combinedAdresseCode=p.ad))
85 if not lst:
86 gws.log.error(f'gekos: not found, {p.fs=} {p.ad=}')
87 return gws.ContentResponse(mimeType='text/plain', content='error:')
89 return gws.ContentResponse(mimeType='text/plain', content='{:.3f};{:.3f}'.format(lst[0].x, lst[0].y))