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

1"""GekoS action.""" 

2 

3from typing import Optional, cast 

4 

5import gws 

6import gws.lib.crs 

7import gws.base.feature 

8import gws.base.shape 

9import gws.base.action 

10import gws.base.database 

11 

12import gws.plugin.alkis.action as alkis_action 

13 

14from . import core, index 

15 

16gws.ext.new.action('gekos') 

17 

18 

19class GetXyRequest(gws.Request): 

20 """Request to get XY coordinates from a GekoS feature.""" 

21 

22 fs: Optional[str] 

23 """Combined flurstueck code.""" 

24 ad: Optional[str] 

25 """Combined adresse code.""" 

26 

27 

28class GetFsResponse(gws.Response): 

29 feature: gws.FeatureProps 

30 

31 

32class Config(gws.base.action.Config): 

33 """GekoS action configuration.""" 

34 

35 index: Optional[core.IndexConfig] 

36 """GekoS index configuration.""" 

37 templates: Optional[list[gws.ext.config.template]] 

38 """Feature templates.""" 

39 

40 

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] 

49 

50 

51class Object(gws.base.action.Object): 

52 idx: index.Object 

53 templates: list[gws.Template] 

54 

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] 

59 

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) 

65 

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:') 

70 

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)) 

76 

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:') 

80 

81 return gws.ContentResponse(mime='text/plain', content='{:.3f};{:.3f}'.format(lst[0].x, lst[0].y))