Coverage for gws-app/gws/base/project/core.py: 100%

87 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-24 12:46 +0200

1from typing import Optional 

2 

3import gws 

4import gws.base.action 

5import gws.base.client 

6import gws.base.map 

7import gws.base.printer 

8import gws.base.template 

9import gws.base.web 

10import gws.base.metadata 

11 

12gws.ext.new.project('default') 

13 

14 

15class Config(gws.ConfigWithAccess): 

16 """Project configuration""" 

17 

18 type: str = 'default' 

19 

20 actions: Optional[list[gws.ext.config.action]] 

21 """Project-specific actions.""" 

22 assets: Optional[gws.base.web.site.WebDirConfig] 

23 """Project-specific assets options.""" 

24 client: Optional[gws.base.client.Config] 

25 """Project-specific gws client configuration.""" 

26 exporters: Optional[list[gws.ext.config.exporter]] 

27 """Project-specific exporters.""" 

28 finders: Optional[list[gws.ext.config.finder]] 

29 """Search providers.""" 

30 locales: Optional[list[gws.LocaleUid]] 

31 """Project locales.""" 

32 map: Optional[gws.base.map.Config] 

33 """Map configuration.""" 

34 metadata: Optional[gws.base.metadata.Config] 

35 """Project metadata.""" 

36 models: Optional[list[gws.ext.config.model]] 

37 """Data models.""" 

38 overviewMap: Optional[gws.base.map.Config] 

39 """Overview map configuration.""" 

40 owsServices: Optional[list[gws.ext.config.owsService]] 

41 """OWS services configuration.""" 

42 printers: Optional[list[gws.base.printer.Config]] 

43 """Print configurations.""" 

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

45 """Project info templates.""" 

46 title: str = '' 

47 """Project title.""" 

48 vars: Optional[dict] 

49 """Custom variables.""" 

50 

51 

52class Props(gws.Props): 

53 actions: list[gws.ext.props.action] 

54 client: Optional[gws.base.client.Props] 

55 description: str 

56 locales: list[str] 

57 map: gws.ext.props.map 

58 exporters: list[gws.ext.props.exporter] 

59 models: list[gws.ext.props.model] 

60 metadata: gws.base.metadata.Props 

61 overviewMap: gws.ext.props.map 

62 printers: list[gws.base.printer.Props] 

63 title: str 

64 uid: str 

65 

66 

67class Object(gws.Project): 

68 overviewMap: gws.base.map.Object 

69 title: str 

70 

71 def configure(self): 

72 gws.log.info(f'configuring project {self.uid!r}') 

73 

74 self.vars = self.cfg('vars') or {} 

75 

76 self.metadata = gws.base.metadata.from_args( 

77 self.root.app.metadata, 

78 self.cfg('metadata'), 

79 ) 

80 

81 title = self.cfg('title') or self.metadata.get('title') or self.cfg('uid') 

82 # title at the top level config preferred to metadata 

83 self.title = self.metadata.title = title 

84 

85 p = self.cfg('assets') 

86 self.assetsRoot = gws.WebDocumentRoot(p) if p else None 

87 

88 self.localeUids = self.cfg('locales') or self.root.app.localeUids 

89 

90 self.actions = self.create_children(gws.ext.object.action, self.cfg('actions')) 

91 self.map = self.create_child_if_configured(gws.ext.object.map, self.cfg('map'), _defaultTitle=self.title) 

92 self.overviewMap = self.create_child_if_configured(gws.base.map.Object, self.cfg('overviewMap')) 

93 self.printers = self.create_children(gws.ext.object.printer, self.cfg('printers')) 

94 self.models = self.create_children(gws.ext.object.model, self.cfg('models')) 

95 self.finders = self.create_children(gws.ext.object.finder, self.cfg('finders')) 

96 self.templates = self.create_children(gws.ext.object.template, self.cfg('templates')) 

97 self.exporters = self.create_children(gws.ext.object.exporter, self.cfg('exporters')) 

98 self.client = self.create_child_if_configured(gws.base.client.Object, self.cfg('client')) 

99 self.owsServices = self.create_children(gws.ext.object.owsService, self.cfg('owsServices')) 

100 

101 def props(self, user): 

102 desc = None 

103 tpl = self.root.app.templateMgr.find_template('project.description', where=[self], user=user) 

104 if tpl: 

105 desc = tpl.render(gws.TemplateRenderInput(args={'project': self}, user=user)) 

106 

107 printers = [p for p in self.printers if user.can_use(p)] 

108 printers.extend(p for p in self.root.app.printers if user.can_use(p)) 

109 if not printers: 

110 printers = [self.root.app.defaultPrinter] 

111 

112 return gws.Props( 

113 actions=self.root.app.actionMgr.actions_for_project(self, user), 

114 client=self.client or self.root.app.client, 

115 description=desc.content if desc else '', 

116 map=self.map, 

117 metadata=gws.base.metadata.props(self.metadata), 

118 exporters=self.root.app.exporterMgr.list_exporters([self, self.root.app], user=user), 

119 models=[], 

120 overviewMap=self.overviewMap, 

121 printers=printers, 

122 title=self.title, 

123 uid=self.uid, 

124 )