Coverage for gws-app/gws/plugin/nominatim/finder.py: 0%

23 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-05 13:35 +0200

1"""Nominatim finder.""" 

2 

3from typing import Optional 

4 

5import gws 

6import gws.base.search 

7import gws.base.template 

8import gws.config.util 

9import gws.lib.net 

10 

11 

12_DEFAULT_TEMPLATES = [ 

13 gws.Config( 

14 subject='feature.teaser', 

15 type='html', 

16 text=''' 

17 <p class="head">{name|html}</p> 

18 <p>{osm_class}: {osm_type}</p> 

19 ''' 

20 ), 

21 gws.Config( 

22 subject='feature.description', 

23 type='html', 

24 text=''' 

25 <p class="head">{name|html}</p> 

26 <p class="head2">{osm_class}: {osm_type}</p> 

27 <p class="text2">{address_road} {address_building} 

28 <br>{address_postcode} {address_city} 

29 <br>{address_country} 

30 </p> 

31 ''' 

32 ), 

33] 

34 

35 

36@gws.ext.config.finder('nominatim') 

37class Config(gws.base.search.finder.Config): 

38 """Search for places and addresses in OpenStreetMap via Nominatim.""" 

39 

40 country: Optional[str] 

41 """Countries to limit the results to.""" 

42 language: Optional[str] 

43 """Preferred language of the results.""" 

44 

45 

46@gws.ext.object.finder('nominatim') 

47class Object(gws.base.search.finder.Object): 

48 """Nominatim finder object. 

49 

50 Searches places and addresses in OpenStreetMap by keyword through a 

51 ``nominatim`` model. 

52 """ 

53 

54 supportsKeywordSearch = True 

55 

56 def configure(self): 

57 self.configure_models() 

58 self.configure_templates() 

59 

60 def configure_templates(self): 

61 return gws.config.util.configure_templates_for(self, extra=_DEFAULT_TEMPLATES) 

62 

63 def configure_models(self): 

64 return gws.config.util.configure_models_for(self, with_default=True) 

65 

66 def create_model(self, cfg): 

67 """Create a ``nominatim`` model with the country and language of the finder. 

68 

69 Args: 

70 cfg: Model configuration, or None for the default model. 

71 

72 Returns: 

73 The model object. 

74 """ 

75 return self.create_child( 

76 gws.ext.object.model, 

77 cfg, 

78 type=self.extType, 

79 country=self.cfg('country'), 

80 language=self.cfg('language') 

81 )