Coverage for gws-app/gws/base/project/core.py: 0%
76 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 01:37 +0200
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 01:37 +0200
1from typing import Optional
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.lib.metadata
12gws.ext.new.project('default')
15class Config(gws.ConfigWithAccess):
16 """Project configuration"""
18 type: str = 'default'
20 actions: Optional[list[gws.ext.config.action]]
21 """project-specific actions"""
22 assets: Optional[gws.base.web.site.WebDocumentRootConfig]
23 """project-specific assets options"""
24 client: Optional[gws.base.client.Config]
25 """project-specific gws client configuration"""
26 finders: Optional[list[gws.ext.config.finder]]
27 """search providers"""
28 locales: Optional[list[str]]
29 """project locales"""
30 map: Optional[gws.base.map.Config]
31 """Map configuration"""
32 metadata: Optional[gws.Metadata]
33 """project metadata"""
34 models: Optional[list[gws.ext.config.model]]
35 """data models"""
36 overviewMap: Optional[gws.base.map.Config]
37 """Overview map configuration"""
38 owsServices: Optional[list[gws.ext.config.owsService]]
39 """OWS services configuration"""
40 printers: Optional[list[gws.base.printer.Config]]
41 """print configurations"""
42 templates: Optional[list[gws.ext.config.template]]
43 """project info templates"""
44 title: str = ''
45 """project title"""
48class Props(gws.Props):
49 actions: list[gws.ext.props.action]
50 client: Optional[gws.base.client.Props]
51 description: str
52 locales: list[str]
53 map: gws.ext.props.map
54 models: list[gws.ext.props.model]
55 metadata: gws.lib.metadata.Props
56 overviewMap: gws.ext.props.map
57 printers: list[gws.base.printer.Props]
58 title: str
59 uid: str
62class Object(gws.Project):
63 overviewMap: gws.base.map.Object
64 title: str
66 def configure(self):
67 gws.log.info(f'configuring project {self.uid!r}')
69 self.metadata = gws.lib.metadata.merge(
70 self.root.app.metadata,
71 gws.lib.metadata.from_config(self.cfg('metadata')))
73 title = self.cfg('title') or self.metadata.get('title') or self.cfg('uid')
74 # title at the top level config preferred to metadata
75 self.title = self.metadata.title = title
77 p = self.cfg('assets')
78 self.assetsRoot = gws.WebDocumentRoot(p) if p else None
80 self.localeUids = self.cfg('locales') or self.root.app.localeUids
82 self.actions = self.create_children(gws.ext.object.action, self.cfg('actions'))
83 self.map = self.create_child_if_configured(gws.ext.object.map, self.cfg('map'), _defaultTitle=self.title)
84 self.overviewMap = self.create_child_if_configured(gws.base.map.Object, self.cfg('overviewMap'))
85 self.printers = self.create_children(gws.ext.object.printer, self.cfg('printers'))
86 self.models = self.create_children(gws.ext.object.model, self.cfg('models'))
87 self.finders = self.create_children(gws.ext.object.finder, self.cfg('finders'))
88 self.templates = self.create_children(gws.ext.object.template, self.cfg('templates'))
89 self.client = self.create_child_if_configured(gws.base.client.Object, self.cfg('client'))
90 self.owsServices = self.create_children(gws.ext.object.owsService, self.cfg('owsServices'))
92 def props(self, user):
93 desc = None
94 tpl = self.root.app.templateMgr.find_template('project.description', where=[self], user=user)
95 if tpl:
96 desc = tpl.render(gws.TemplateRenderInput(args={'project': self}, user=user))
98 return gws.Props(
99 actions=self.root.app.actionMgr.actions_for_project(self, user),
100 client=self.client or self.root.app.client,
101 description=desc.content if desc else '',
102 map=self.map,
103 metadata=gws.lib.metadata.props(self.metadata),
104 models=[],
105 overviewMap=self.overviewMap,
106 printers=self.root.app.printerMgr.printers_for_project(self, user),
107 title=self.title,
108 uid=self.uid,
109 )