Coverage for gws-app/gws/base/project/core.py: 100%
63 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"""Project object."""
3from typing import Optional
5import gws
6import gws.base.action
7import gws.base.client
8import gws.base.map
9import gws.base.printer
10import gws.base.template
11import gws.base.web
12import gws.base.metadata
15@gws.ext.config.project('default')
16class Config(gws.ConfigWithAccess):
17 """Project with its own map, actions, templates and services."""
19 type: str = 'default'
21 actions: Optional[list[gws.ext.config.action]]
22 """Actions available only in this project."""
23 assets: Optional[gws.base.web.site.WebDirConfig]
24 """Directory with project assets, checked before the global assets directory."""
25 client: Optional[gws.base.client.Config]
26 """Client UI for this project, replacing the application client."""
27 exporters: Optional[list[gws.ext.config.exporter]]
28 """Exporters for this project, offered along with the global ones."""
29 finders: Optional[list[gws.ext.config.finder]]
30 """Search providers available in this project."""
31 locales: Optional[list[gws.LocaleUid]]
32 """Locales for this project."""
33 map: Optional[gws.base.map.Config]
34 """Main map of the project."""
35 metadata: Optional[gws.base.metadata.Config]
36 """Project metadata, merged with the application metadata."""
37 models: Optional[list[gws.ext.config.model]]
38 """Data models."""
39 overviewMap: Optional[gws.base.map.Config]
40 """Overview map, showing the current view on a smaller scale."""
41 owsServices: Optional[list[gws.ext.config.owsService]]
42 """OWS services published for this project."""
43 printers: Optional[list[gws.base.printer.Config]]
44 """Printers for this project, offered along with the global ones."""
45 templates: Optional[list[gws.ext.config.template]]
46 """Templates for this project."""
47 title: str = ''
48 """Project title."""
49 vars: Optional[dict]
50 """Custom variables."""
53@gws.ext.props.project('default')
54class Props(gws.Props):
55 actions: list[gws.ext.props.action]
56 client: Optional[gws.base.client.Props]
57 description: str
58 locales: list[str]
59 map: gws.ext.props.map
60 exporters: list[gws.ext.props.exporter]
61 models: list[gws.ext.props.model]
62 metadata: gws.base.metadata.Props
63 overviewMap: gws.ext.props.map
64 printers: list[gws.base.printer.Props]
65 title: str
66 uid: str
69@gws.ext.object.project('default')
70class Object(gws.Project):
71 """Default project."""
73 overviewMap: gws.base.map.Object
74 """Overview map, if configured."""
75 title: str
76 """Project title."""
78 def configure(self):
79 gws.log.info(f'configuring project {self.uid!r}')
81 self.vars = self.cfg('vars') or {}
83 self.metadata = gws.base.metadata.from_args(
84 self.root.app.metadata,
85 self.cfg('metadata'),
86 )
88 title = self.cfg('title') or self.metadata.get('title') or self.cfg('uid')
89 # title at the top level config preferred to metadata
90 self.title = self.metadata.title = title
92 p = self.cfg('assets')
93 self.assetsRoot = gws.WebDocumentRoot(p) if p else None
95 self.localeUids = self.cfg('locales') or self.root.app.localeUids
97 self.actions = self.create_children(gws.ext.object.action, self.cfg('actions'))
98 self.map = self.create_child_if_configured(gws.ext.object.map, self.cfg('map'), _defaultTitle=self.title)
99 self.overviewMap = self.create_child_if_configured(gws.base.map.Object, self.cfg('overviewMap'))
100 self.printers = self.create_children(gws.ext.object.printer, self.cfg('printers'))
101 self.models = self.create_children(gws.ext.object.model, self.cfg('models'))
102 self.finders = self.create_children(gws.ext.object.finder, self.cfg('finders'))
103 self.templates = self.create_children(gws.ext.object.template, self.cfg('templates'))
104 self.exporters = self.create_children(gws.ext.object.exporter, self.cfg('exporters'))
105 self.client = self.create_child_if_configured(gws.base.client.Object, self.cfg('client'))
106 self.owsServices = self.create_children(gws.ext.object.owsService, self.cfg('owsServices'))
108 def props(self, user):
109 desc = None
110 tpl = self.root.app.templateMgr.find_template('project.description', where=[self], user=user)
111 if tpl:
112 desc = tpl.render(gws.TemplateRenderInput(args={'project': self}, user=user))
114 printers = [p for p in self.printers if user.can_use(p)]
115 printers.extend(p for p in self.root.app.printers if user.can_use(p))
116 if not printers:
117 printers = [self.root.app.defaultPrinter]
119 return gws.Props(
120 actions=self.root.app.actionMgr.actions_for_project(self, user),
121 client=self.client or self.root.app.client,
122 description=desc.content if desc else '',
123 map=self.map,
124 metadata=gws.base.metadata.props(self.metadata),
125 exporters=self.root.app.exporterMgr.list_exporters([self, self.root.app], user=user),
126 models=[],
127 overviewMap=self.overviewMap,
128 printers=printers,
129 title=self.title,
130 uid=self.uid,
131 )