Coverage for gws-app/gws/base/application/templates/__init__.py: 100%

0 statements  

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

1"""Standard templates. 

2 

3All templates are written in the CX template language and live alongside this 

4package.  

5 

6These templates are added to the application template manager by default, and can be overridden with custom templates. 

7The ``subject`` property of each template is used to identify it, and is documented below. 

8 

9Every template receives the following context variables automatically: 

10 

11- ``app`` (`gws.Application`) - the running application instance. 

12- ``project`` (`gws.Project`) - active project, if any. 

13- ``user`` (`gws.User`) - the currently authenticated (or guest) user. 

14- ``locale`` (`gws.Locale`) - the active locale, carrying language, 

15 number and date formatting helpers. 

16 

17Some templates expect additional context variables, which are documented below. 

18 

19Localised UI strings are loaded from ``strings.ini`` in this directory and 

20exposed to templates as the ``STRINGS`` mapping. 

21 

22---- 

23 

24Complete HTML templates 

25----------------------- 

26 

27Complete HTML templates render a full ``<!doctype html>`` page and are 

28served directly in response to an HTTP request (e.g. the home page). 

29 

30``application_home.cx.html`` (subject ``application.home``) 

31 The application's root (``/``) page. Displays the application title, 

32 optionally a sign-in / sign-out form (when ``app.templateOptions.withLogin`` 

33 is set), and a list of projects the current user may access. 

34 

35 Extra context variable: ``projects`` (list of `gws.Project`) - all projects accessible to the 

36 current user. 

37 

38``application_error.cx.html`` (subject ``application.error``) 

39 Rendered whenever a request results in an HTTP error. Picks an 

40 appropriate heading and message from ``STRINGS`` based on the status code. 

41 

42 Extra context variable: ``status`` (``int``) - the HTTP status code (e.g. ``404``, ``500``). 

43 

44``project_home.cx.html`` (subject ``project.home``) 

45 The shell page that bootstraps the interactive map viewer for a specific 

46 project. Outputs a minimal HTML skeleton and embeds ``projectUid`` and 

47 ``localeUid`` as a JSON block so the JavaScript application can 

48 initialise itself. 

49 

50 Extra context variable: ``projects`` (list of `gws.Project`) - all projects accessible to the 

51 current user (available for custom navigation). 

52 

53``project_print.cx.html`` (attached to the default printer object) 

54 A print-ready A3-landscape layout used when the user exports the current 

55 map view. Renders the project title, a full-bleed map area (``@map``), 

56 and a legend panel (``@legend``). 

57 

58Feature templates 

59----------------- 

60 

61Feature templates that render specific aspects of a map feature.  

62They receive a ``feature`` context variable (``gws.Feature``) in addition to the standard context variables. 

63Additionally, feature attributes are available as context variables. 

64 

65``feature_description.cx.html`` (subject ``feature.description``) 

66 An HTML ``<table>`` listing all attributes of a feature.  

67 

68``feature_label.cx.html`` (subject ``feature.label``) 

69 A brief inline label rendered next to a feature on the map (e.g. inside 

70 an SVG text element or a map overlay).  

71 

72``feature_title.cx.html`` (subject ``feature.title``) 

73 A short display title for a feature, used in pop-ups and result lists. 

74 

75Other templates 

76--------------- 

77 

78``layer_description.cx.html`` (subject ``layer.description``) 

79 An info panel for a map layer.  

80 

81 Extra context variable: ``layer`` (`gws.Layer`) - the layer being described. 

82 

83``project_description.cx.html`` (subject ``project.description``) 

84 An info panel for a project.  

85 

86Support files 

87------------- 

88 

89``parts.cx.html`` 

90 Defines shared macros used by application templates above. 

91 These macros can also be used in custom templates to ensure consistent layout and behaviour. 

92 

93``strings.ini`` 

94 Localised UI strings for the home and error pages, keyed by locale. 

95 

96``home.css`` / ``home.js`` 

97 Static assets bundled with the home page. 

98 

99Template options 

100---------------- 

101 

102The behaviour of the standard templates is controlled by `gws.TemplateOptions`, 

103configured in the ``templateOptions`` property of the application config and 

104available to every template as ``app.templateOptions``: 

105 

106``withLogin`` (``bool``) 

107 Render the sign-in / sign-out form on the application home page. 

108 Defaults to ``true`` if the `auth` action is configured. 

109 

110``footerText`` (``str``) 

111 Text for the footer of the application home page. May contain HTML, 

112 which is inserted as is. The footer is only rendered if this option is set. 

113 

114``withGws`` (``bool``) 

115 Render the GWS logo, linking to the GBD WebSuite website, in the footer 

116 of the application home page. Defaults to ``true``. Requires ``footerText``, 

117 since the footer is not rendered without it. 

118 

119``homeResources`` (list of ``str``) 

120 Additional resource URLs injected into the ``<head>`` of the application 

121 home page. 

122 

123``projectResources`` (list of ``str``) 

124 Additional resource URLs injected into the ``<head>`` of the project home 

125 page.  

126  

127If resources are not configured and the file ``style.css`` exists  

128in the static root of the first configured web site,  

129``/style.css`` is used as the default resource. 

130"""