Coverage for gws-app/gws/base/project/core.py: 100%
83 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-16 23:09 +0200
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-16 23:09 +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.base.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.WebDirConfig]
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[gws.LocaleUid]]
29 """Project locales."""
30 map: Optional[gws.base.map.Config]
31 """Map configuration."""
32 metadata: Optional[gws.base.metadata.Config]
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."""
46 vars: Optional[dict]
47 """Custom variables."""
50class Props(gws.Props):
51 actions: list[gws.ext.props.action]
52 client: Optional[gws.base.client.Props]
53 description: str
54 locales: list[str]
55 map: gws.ext.props.map
56 models: list[gws.ext.props.model]
57 metadata: gws.base.metadata.Props
58 overviewMap: gws.ext.props.map
59 printers: list[gws.base.printer.Props]
60 title: str
61 uid: str
64class Object(gws.Project):
65 overviewMap: gws.base.map.Object
66 title: str
68 def configure(self):
69 gws.log.info(f'configuring project {self.uid!r}')
71 self.vars = self.cfg('vars') or {}
73 self.metadata = gws.base.metadata.from_args(
74 self.root.app.metadata,
75 self.cfg('metadata'),
76 )
78 title = self.cfg('title') or self.metadata.get('title') or self.cfg('uid')
79 # title at the top level config preferred to metadata
80 self.title = self.metadata.title = title
82 p = self.cfg('assets')
83 self.assetsRoot = gws.WebDocumentRoot(p) if p else None
85 self.localeUids = self.cfg('locales') or self.root.app.localeUids
87 self.actions = self.create_children(gws.ext.object.action, self.cfg('actions'))
88 self.map = self.create_child_if_configured(gws.ext.object.map, self.cfg('map'), _defaultTitle=self.title)
89 self.overviewMap = self.create_child_if_configured(gws.base.map.Object, self.cfg('overviewMap'))
90 self.printers = self.create_children(gws.ext.object.printer, self.cfg('printers'))
91 self.models = self.create_children(gws.ext.object.model, self.cfg('models'))
92 self.finders = self.create_children(gws.ext.object.finder, self.cfg('finders'))
93 self.templates = self.create_children(gws.ext.object.template, self.cfg('templates'))
94 self.client = self.create_child_if_configured(gws.base.client.Object, self.cfg('client'))
95 self.owsServices = self.create_children(gws.ext.object.owsService, self.cfg('owsServices'))
97 def props(self, user):
98 desc = None
99 tpl = self.root.app.templateMgr.find_template('project.description', where=[self], user=user)
100 if tpl:
101 desc = tpl.render(gws.TemplateRenderInput(args={'project': self}, user=user))
103 printers = [p for p in self.printers if user.can_use(p)]
104 printers.extend(p for p in self.root.app.printers if user.can_use(p))
105 if not printers:
106 printers = [self.root.app.defaultPrinter]
108 return gws.Props(
109 actions=self.root.app.actionMgr.actions_for_project(self, user),
110 client=self.client or self.root.app.client,
111 description=desc.content if desc else '',
112 map=self.map,
113 metadata=gws.base.metadata.props(self.metadata),
114 models=[],
115 overviewMap=self.overviewMap,
116 printers=printers,
117 title=self.title,
118 uid=self.uid,
119 )