c2cgeoportal-admin 2.6.0__py3-none-any.whl → 2.7.1.156__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. c2cgeoportal_admin/__init__.py +17 -10
  2. c2cgeoportal_admin/lib/lingua_extractor.py +77 -0
  3. c2cgeoportal_admin/lib/ogcserver_synchronizer.py +166 -54
  4. c2cgeoportal_admin/py.typed +0 -0
  5. c2cgeoportal_admin/routes.py +4 -3
  6. c2cgeoportal_admin/schemas/dimensions.py +12 -10
  7. c2cgeoportal_admin/schemas/functionalities.py +62 -21
  8. c2cgeoportal_admin/schemas/interfaces.py +22 -18
  9. c2cgeoportal_admin/schemas/metadata.py +99 -46
  10. c2cgeoportal_admin/schemas/restriction_areas.py +21 -19
  11. c2cgeoportal_admin/schemas/roles.py +7 -5
  12. c2cgeoportal_admin/schemas/treegroup.py +37 -16
  13. c2cgeoportal_admin/schemas/treeitem.py +2 -3
  14. c2cgeoportal_admin/static/layertree.css +3 -4
  15. c2cgeoportal_admin/static/navbar.css +36 -35
  16. c2cgeoportal_admin/static/theme.css +16 -9
  17. c2cgeoportal_admin/subscribers.py +3 -3
  18. c2cgeoportal_admin/templates/layertree.jinja2 +31 -9
  19. c2cgeoportal_admin/templates/navigation_navbar.jinja2 +33 -0
  20. c2cgeoportal_admin/templates/ogcserver_synchronize.jinja2 +12 -0
  21. c2cgeoportal_admin/templates/widgets/functionality_fields.pt +51 -0
  22. c2cgeoportal_admin/templates/widgets/metadata.pt +7 -1
  23. c2cgeoportal_admin/views/dimension_layers.py +7 -6
  24. c2cgeoportal_admin/views/functionalities.py +31 -5
  25. c2cgeoportal_admin/views/home.py +5 -5
  26. c2cgeoportal_admin/views/interfaces.py +5 -7
  27. c2cgeoportal_admin/views/layer_groups.py +9 -11
  28. c2cgeoportal_admin/views/layers.py +8 -7
  29. c2cgeoportal_admin/views/layers_vectortiles.py +30 -10
  30. c2cgeoportal_admin/views/layers_wms.py +39 -35
  31. c2cgeoportal_admin/views/layers_wmts.py +39 -35
  32. c2cgeoportal_admin/views/layertree.py +35 -27
  33. c2cgeoportal_admin/views/oauth2_clients.py +26 -21
  34. c2cgeoportal_admin/views/ogc_servers.py +57 -29
  35. c2cgeoportal_admin/views/restriction_areas.py +11 -10
  36. c2cgeoportal_admin/views/roles.py +14 -11
  37. c2cgeoportal_admin/views/themes.py +15 -14
  38. c2cgeoportal_admin/views/themes_ordering.py +13 -8
  39. c2cgeoportal_admin/views/treeitems.py +12 -11
  40. c2cgeoportal_admin/views/users.py +7 -5
  41. c2cgeoportal_admin/widgets.py +17 -14
  42. {c2cgeoportal_admin-2.6.0.dist-info → c2cgeoportal_admin-2.7.1.156.dist-info}/METADATA +15 -12
  43. c2cgeoportal_admin-2.7.1.156.dist-info/RECORD +92 -0
  44. {c2cgeoportal_admin-2.6.0.dist-info → c2cgeoportal_admin-2.7.1.156.dist-info}/WHEEL +1 -1
  45. c2cgeoportal_admin-2.7.1.156.dist-info/entry_points.txt +5 -0
  46. tests/__init__.py +9 -9
  47. tests/conftest.py +2 -1
  48. tests/test_edit_url.py +11 -13
  49. tests/test_functionalities.py +23 -10
  50. tests/test_interface.py +7 -7
  51. tests/test_layer_groups.py +13 -17
  52. tests/test_layers_vectortiles.py +11 -13
  53. tests/test_layers_wms.py +25 -36
  54. tests/test_layers_wmts.py +15 -19
  55. tests/test_layertree.py +99 -15
  56. tests/test_lingua_extractor_config.py +66 -0
  57. tests/test_main.py +3 -1
  58. tests/test_metadatas.py +34 -20
  59. tests/test_oauth2_clients.py +4 -4
  60. tests/test_ogc_servers.py +21 -10
  61. tests/test_restriction_areas.py +10 -12
  62. tests/test_role.py +37 -35
  63. tests/test_themes.py +40 -33
  64. tests/test_themes_ordering.py +1 -1
  65. tests/test_treegroup.py +2 -2
  66. tests/test_user.py +15 -13
  67. tests/themes_ordering.py +1 -1
  68. c2cgeoportal_admin/templates/navigation_vertical.jinja2 +0 -33
  69. c2cgeoportal_admin-2.6.0.dist-info/RECORD +0 -89
  70. c2cgeoportal_admin-2.6.0.dist-info/entry_points.txt +0 -3
  71. {c2cgeoportal_admin-2.6.0.dist-info → c2cgeoportal_admin-2.7.1.156.dist-info}/top_level.txt +0 -0
@@ -32,7 +32,7 @@
32
32
  }
33
33
 
34
34
  @media (min-width: 992px) and (max-width: 1125px) {
35
- .navbar-default .navbar-nav>li>a {
35
+ .navbar-default .navbar-nav > li > a {
36
36
  max-width: 8.5vw;
37
37
  overflow: hidden;
38
38
  text-overflow: ellipsis;
@@ -42,39 +42,40 @@
42
42
 
43
43
  /*csslint important: false*/
44
44
  @media (max-width: 991px) {
45
- .navbar-header {
46
- float: none;
47
- }
48
- .navbar-left,.navbar-right {
49
- float: none !important;
50
- }
51
- .navbar-toggle {
52
- display: block;
53
- }
54
- .navbar-collapse {
55
- border-top: 1px solid transparent;
56
- box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
57
- }
58
- .navbar-fixed-top {
59
- top: 0;
60
- border-width: 0 0 1px;
61
- }
62
- .navbar-collapse.collapse {
63
- display: none!important;
64
- }
65
- .navbar-nav {
66
- float: none!important;
67
- margin-top: 7.5px;
68
- }
69
- .navbar-nav>li {
70
- float: none;
71
- }
72
- .navbar-nav>li>a {
73
- padding-top: 10px;
74
- padding-bottom: 10px;
75
- }
76
- .collapse.in{
77
- display:block !important;
78
- }
45
+ .navbar-header {
46
+ float: none;
47
+ }
48
+ .navbar-left,
49
+ .navbar-right {
50
+ float: none !important;
51
+ }
52
+ .navbar-toggle {
53
+ display: block;
54
+ }
55
+ .navbar-collapse {
56
+ border-top: 1px solid transparent;
57
+ box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
58
+ }
59
+ .navbar-fixed-top {
60
+ top: 0;
61
+ border-width: 0 0 1px;
62
+ }
63
+ .navbar-collapse.collapse {
64
+ display: none !important;
65
+ }
66
+ .navbar-nav {
67
+ float: none !important;
68
+ margin-top: 7.5px;
69
+ }
70
+ .navbar-nav > li {
71
+ float: none;
72
+ }
73
+ .navbar-nav > li > a {
74
+ padding-top: 10px;
75
+ padding-bottom: 10px;
76
+ }
77
+ .collapse.in {
78
+ display: block !important;
79
+ }
79
80
  }
80
81
  /*csslint important: true*/
@@ -21,33 +21,35 @@
21
21
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  */
23
23
 
24
- @import "navbar.css";
24
+ @import 'navbar.css';
25
25
 
26
- .nav>li>a {
26
+ .nav > li > a {
27
27
  padding-left: 8px;
28
28
  padding-right: 8px;
29
29
  }
30
30
 
31
31
  .bootstrap-table th.actions,
32
- .bootstrap-table td.actions
33
- {
32
+ .bootstrap-table td.actions {
34
33
  width: 30px;
35
34
  }
36
35
 
37
36
  .icon-theme:before {
38
- content: "\e139";
37
+ content: '\e139';
39
38
  }
40
39
  .icon-group:before {
41
- content: "\e118";
40
+ content: '\e118';
42
41
  }
43
42
  .icon-l_wms:before {
44
- content: "\e060";
43
+ content: '\e060';
45
44
  }
46
45
  .icon-l_wmts:before {
47
- content: "\e011";
46
+ content: '\e011';
47
+ }
48
+ .icon-mvt:before {
49
+ content: '\e011';
48
50
  }
49
51
  .icon-user:before {
50
- content: "\e008";
52
+ content: '\e008';
51
53
  }
52
54
 
53
55
  .ms-res-ctn .ms-res-item {
@@ -74,3 +76,8 @@
74
76
  #layertree .alert-info {
75
77
  margin-top: 30px;
76
78
  }
79
+
80
+ .item-functionalities .checkbox label {
81
+ overflow: hidden;
82
+ overflow-wrap: break-word;
83
+ }
@@ -1,6 +1,4 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- # Copyright (c) 2018-2020, Camptocamp SA
1
+ # Copyright (c) 2018-2021, Camptocamp SA
4
2
  # All rights reserved.
5
3
 
6
4
  # Redistribution and use in source and binary forms, with or without
@@ -34,6 +32,7 @@ from pyramid.i18n import TranslationStringFactory, get_localizer
34
32
 
35
33
 
36
34
  def add_renderer_globals(event):
35
+ """Add the localizer to the global event."""
37
36
  request = event["request"]
38
37
  event["_"] = request.translate
39
38
  event["localizer"] = request.localizer
@@ -44,6 +43,7 @@ tsf2 = TranslationStringFactory("c2cgeoform")
44
43
 
45
44
 
46
45
  def add_localizer(event):
46
+ """Add the localizer to the request."""
47
47
  request = event.request
48
48
  localizer = get_localizer(request)
49
49
 
@@ -37,15 +37,26 @@
37
37
  {% block content %}
38
38
  <div id="layertree" class="container-fluid">
39
39
  <div id="toolbar">
40
- <div class="btn-group">
41
- {% if limit_exceeded %}
42
- <button id="layertree-expand" type="button" class="btn btn-default"><span class="glyphicon glyphicon-chevron-down"></span> {{_("Expand all")}}</button>
43
- {% endif %}
44
- <button id="layertree-collapse" type="button" class="btn btn-default"><span class="glyphicon glyphicon-chevron-up"></span> {{_("Collapse all")}}</button>
45
- </div>
46
- <div class="btn-group">
47
- <a id="layertree-ordering" class="btn btn-default" href="{{request.route_url('layertree_ordering')}}"><span class="glyphicon glyphicon-sort"></span> {{_("Edit themes order")}}</a>
48
- </div>
40
+ <form class="form-inline">
41
+ <div class="form-group">
42
+ <label for="interface">{{ _("Interface") }}</label>
43
+ <select class="form-control" id="interface">
44
+ <option value="all">{{ _("All") }}</option>
45
+ {% for interface in interfaces %}
46
+ <option>{{ interface.name }}</option>
47
+ {% endfor %}
48
+ </select>
49
+ </div>
50
+ <div class="btn-group">
51
+ {% if limit_exceeded %}
52
+ <button id="layertree-expand" type="button" class="btn btn-default"><span class="glyphicon glyphicon-chevron-down"></span> {{_("Expand all")}}</button>
53
+ {% endif %}
54
+ <button id="layertree-collapse" type="button" class="btn btn-default"><span class="glyphicon glyphicon-chevron-up"></span> {{_("Collapse all")}}</button>
55
+ </div>
56
+ <div class="btn-group">
57
+ <a id="layertree-ordering" class="btn btn-default" href="{{request.route_url('layertree_ordering')}}"><span class="glyphicon glyphicon-sort"></span> {{_("Edit themes order")}}</a>
58
+ </div>
59
+ </form>
49
60
  </div>
50
61
 
51
62
  <div id="tree"></div>
@@ -56,8 +67,14 @@
56
67
  core: {
57
68
  data: function(node, callback) {
58
69
  var url = "{{ request.route_url('layertree_children') }}";
70
+ let separator = '?';
59
71
  if (node.id != '#') {
60
72
  url += "?group_id=" + node.data.id + "&path=" + node.id;
73
+ separator = '&';
74
+ }
75
+ const interface = $('#interface')[0].value;
76
+ if (interface != 'all') {
77
+ url += separator + "interface=" + interface;
61
78
  }
62
79
  $.ajax({ url: url })
63
80
  .done(function(data) {
@@ -226,6 +243,11 @@
226
243
  $('.jstree-grid-wrapper').height($(window).height() - $('nav').height() - $('#toolbar').height() - 50);
227
244
  $('.jstree-grid-wrapper').width('100%');
228
245
  });
246
+
247
+ const interfaceField = $('#interface');
248
+ interfaceField.on('change', function(e) {
249
+ $jstree.jstree(true).refresh();
250
+ });
229
251
  });
230
252
  </script>
231
253
 
@@ -46,6 +46,39 @@
46
46
  {% endfor %}
47
47
  </ul>
48
48
 
49
+ <button id="help-button" type="button" class="btn btn-default navbar-btn navbar-right">{{_("Show help")}}</button>
50
+ <script>
51
+ $(function() {
52
+ const key = 'adminShowHelp';
53
+
54
+ const getCurrentValue = function() {
55
+ // Get current value from localStorage
56
+ // True by default
57
+ return localStorage.getItem(key) !== 'false'
58
+ }
59
+
60
+ const apply = function(value) {
61
+ // Apply some value on UI
62
+ if (value) {
63
+ $("#help-button").addClass("active")
64
+ $(".help-block").removeClass("hidden")
65
+ } else {
66
+ $("#help-button").removeClass("active")
67
+ $(".help-block").addClass("hidden")
68
+ }
69
+ }
70
+
71
+ $("#help-button").click(function() {
72
+ // Toggle value in localStorage and apply on UI
73
+ localStorage.setItem(key, getCurrentValue() ? 'false' : 'true');
74
+ apply(getCurrentValue())
75
+ })
76
+
77
+ // Apply current value from localStorage on UI
78
+ apply(getCurrentValue())
79
+ });
80
+ </script>
81
+
49
82
  <ul class="nav navbar-nav navbar-right">
50
83
  <li id="language-dropdown" class="dropdown">
51
84
  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{{request.locale_name}} <span class="caret"></span></a>
@@ -59,6 +59,18 @@
59
59
  <li>else it will create a <code>Group</code> object.</li>
60
60
  </ul>
61
61
  <form method="POST" class="deform" id="form-synchronize">
62
+ <div class="form-group">
63
+ <input type="checkbox" name="force-parents" id="force-parents-field">
64
+ <label for="force-parents-field" class="control-label">{{_("Force parents re-initialization.")}}</label>
65
+ </div>
66
+ <div class="form-group">
67
+ <input type="checkbox" name="force-ordering" id="force-ordering-field">
68
+ <label for="force-ordering-field" class="control-label">{{_("Force children sorting, current server at top and other servers at bottom.")}}</label>
69
+ </div>
70
+ <div class="form-group">
71
+ <input type="checkbox" name="clean" id="clean">
72
+ <label for="clean" class="control-label">{{_("Remove unexisting layers and empty groups.")}}</label>
73
+ </div>
62
74
  <button type="submit" name="synchronize" class="btn btn-primary">{{_("Synchronize")}}</button>
63
75
  </form>
64
76
  </div>
@@ -0,0 +1,51 @@
1
+ <tal:comment replace="nothing">
2
+ The MIT License (MIT)
3
+
4
+ Copyright (c) Camptocamp SA
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ this software and associated documentation files (the "Software"), to deal in
8
+ the Software without restriction, including without limitation the rights to
9
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10
+ the Software, and to permit persons to whom the Software is furnished to do so,
11
+ subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ </tal:comment>
23
+
24
+ <?python import json ?>
25
+
26
+ <tal metal:use-macro='load:mapping_fields.pt'></tal>
27
+
28
+ <script type="text/javascript">
29
+ deform.addCallback(
30
+ '${field['name'].oid}',
31
+ function(oid) {
32
+ const $name = $('#' + oid);
33
+
34
+ const functionalities = ${structure: json.dumps(field.schema.functionalities, indent=4, separators=(',', ': '))};
35
+
36
+ const $form = $name.closest('form');
37
+ const $valueItem = $form.find('.item-value');
38
+ const $helpBlock = $valueItem.find('p.help-block');
39
+
40
+ const updateDescription = function() {
41
+ const functionality = functionalities[$name.val()] || {};
42
+ const description = functionality.description || '';
43
+ $helpBlock.text(description);
44
+ }
45
+ $name.change(function() {
46
+ updateDescription();
47
+ });
48
+ updateDescription();
49
+ }
50
+ );
51
+ </script>
@@ -75,13 +75,19 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
75
75
  $metadataItem.find('.col-value .form-group').hide();
76
76
  $metadataItem.find('.col-value .form-group .form-control').attr('disabled', true);
77
77
 
78
- var type = (c2cgeoportalAdmin.metadata_definitions[$name.val()] || {}).type || 'string';
78
+ var metadataDef = c2cgeoportalAdmin.metadata_definitions[$name.val()] || {};
79
+ var type = metadataDef.type || 'string';
80
+ var description = metadataDef.description || '';
81
+
79
82
  $typedFormgroup = $metadataItem.find('.item-' + type);
80
83
  if ($typedFormgroup.length == 0) {
81
84
  $typedFormgroup = $metadataItem.find('.item-string');
82
85
  }
83
86
  $typedFormgroup.show();
84
87
  $typedFormgroup.find('.form-control').attr('disabled', false);
88
+
89
+ $helpBlock = $typedFormgroup.find('p.help-block');
90
+ $helpBlock.text(description);
85
91
  };
86
92
  $name.change(function() {
87
93
  updateType();
@@ -1,6 +1,4 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- # Copyright (c) 2017-2020, Camptocamp SA
1
+ # Copyright (c) 2017-2021, Camptocamp SA
4
2
  # All rights reserved.
5
3
 
6
4
  # Redistribution and use in source and binary forms, with or without
@@ -30,7 +28,9 @@
30
28
 
31
29
  from functools import partial
32
30
  from itertools import groupby
31
+ from typing import cast
33
32
 
33
+ import sqlalchemy
34
34
  from c2cgeoform.views.abstract_views import ListField
35
35
  from sqlalchemy.orm import subqueryload
36
36
 
@@ -41,18 +41,19 @@ _list_field = partial(ListField, DimensionLayer)
41
41
 
42
42
 
43
43
  class DimensionLayerViews(LayerViews):
44
+ """The layer with dimensions administration view."""
44
45
 
45
46
  _extra_list_fields = [
46
47
  _list_field(
47
48
  "dimensions",
48
49
  renderer=lambda layer_wms: "; ".join(
49
50
  [
50
- "{}: {}".format(group[0], ", ".join([d.value or "NULL" for d in group[1]]))
51
- for group in groupby(layer_wms.dimensions, lambda d: d.name)
51
+ f"{group[0]}: {', '.join([d.value or 'NULL' for d in group[1]])}"
52
+ for group in groupby(layer_wms.dimensions, lambda d: cast(str, d.name))
52
53
  ]
53
54
  ),
54
55
  )
55
56
  ] + LayerViews._extra_list_fields
56
57
 
57
- def _base_query(self, query):
58
+ def _base_query(self, query: sqlalchemy.orm.query.Query) -> sqlalchemy.orm.query.Query:
58
59
  return super()._base_query(query.options(subqueryload("dimensions")))
@@ -1,6 +1,4 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- # Copyright (c) 2017-2020, Camptocamp SA
1
+ # Copyright (c) 2017-2021, Camptocamp SA
4
2
  # All rights reserved.
5
3
 
6
4
  # Redistribution and use in source and binary forms, with or without
@@ -29,20 +27,48 @@
29
27
 
30
28
 
31
29
  from functools import partial
30
+ from typing import Any, Dict
32
31
 
32
+ import colander
33
+ import pyramid.request
33
34
  from c2cgeoform.schema import GeoFormSchemaNode
34
35
  from c2cgeoform.views.abstract_views import AbstractViews, ListField
36
+ from deform.widget import FormWidget
35
37
  from pyramid.view import view_config, view_defaults
36
38
 
39
+ from c2cgeoportal_admin import _
37
40
  from c2cgeoportal_commons.models.main import Functionality
38
41
 
39
42
  _list_field = partial(ListField, Functionality)
40
43
 
41
- base_schema = GeoFormSchemaNode(Functionality)
44
+
45
+ def _translate_available_functionality(
46
+ available_functionality: Dict[str, Any], request: pyramid.request.Request
47
+ ) -> Dict[str, Any]:
48
+ result = {}
49
+ result.update(available_functionality)
50
+ result["description"] = request.localizer.translate(
51
+ _(available_functionality.get("description", "").strip())
52
+ )
53
+ return result
54
+
55
+
56
+ base_schema = GeoFormSchemaNode(
57
+ Functionality,
58
+ widget=FormWidget(fields_template="functionality_fields"),
59
+ functionalities=colander.deferred(
60
+ lambda node, kw: {
61
+ f["name"]: _translate_available_functionality(f, kw["request"])
62
+ for f in kw["request"].registry.settings["admin_interface"]["available_functionalities"]
63
+ },
64
+ ),
65
+ )
42
66
 
43
67
 
44
68
  @view_defaults(match_param="table=functionalities")
45
- class FunctionalityViews(AbstractViews):
69
+ class FunctionalityViews(AbstractViews): # type: ignore
70
+ """The functionality administration view."""
71
+
46
72
  _list_fields = [_list_field("id"), _list_field("name"), _list_field("description"), _list_field("value")]
47
73
  _id_field = "id"
48
74
  _model = Functionality
@@ -1,6 +1,4 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- # Copyright (c) 2017-2020, Camptocamp SA
1
+ # Copyright (c) 2017-2021, Camptocamp SA
4
2
  # All rights reserved.
5
3
 
6
4
  # Redistribution and use in source and binary forms, with or without
@@ -28,10 +26,12 @@
28
26
  # either expressed or implied, of the FreeBSD Project.
29
27
 
30
28
 
29
+ import pyramid.request
31
30
  from pyramid.httpexceptions import HTTPFound
32
31
  from pyramid.view import view_config
33
32
 
34
33
 
35
- @view_config(route_name="admin")
36
- def home_view(request):
34
+ @view_config(route_name="admin") # type: ignore # type: ignore
35
+ def home_view(request: pyramid.request.Request) -> HTTPFound:
36
+ """Get the main administration view, redirect to the layertree."""
37
37
  return HTTPFound(request.route_url("layertree", application="admin"))
@@ -1,6 +1,4 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- # Copyright (c) 2017-2020, Camptocamp SA
1
+ # Copyright (c) 2017-2021, Camptocamp SA
4
2
  # All rights reserved.
5
3
 
6
4
  # Redistribution and use in source and binary forms, with or without
@@ -42,7 +40,9 @@ base_schema = GeoFormSchemaNode(Interface)
42
40
 
43
41
 
44
42
  @view_defaults(match_param="table=interfaces")
45
- class InterfacesViews(AbstractViews):
43
+ class InterfacesViews(AbstractViews): # type: ignore
44
+ """The interface administration view."""
45
+
46
46
  _list_fields = [
47
47
  _list_field("id"),
48
48
  _list_field("name"),
@@ -52,9 +52,7 @@ class InterfacesViews(AbstractViews):
52
52
  ),
53
53
  _list_field(
54
54
  "theme",
55
- renderer=lambda interface: ", ".join(
56
- ["{}-{}".format(t.name, t.name) or "" for t in interface.theme]
57
- ),
55
+ renderer=lambda interface: ", ".join([f"{t.name}-{t.name}" or "" for t in interface.theme]),
58
56
  ),
59
57
  ]
60
58
  _id_field = "id"
@@ -1,6 +1,4 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- # Copyright (c) 2017-2020, Camptocamp SA
1
+ # Copyright (c) 2017-2021, Camptocamp SA
4
2
  # All rights reserved.
5
3
 
6
4
  # Redistribution and use in source and binary forms, with or without
@@ -29,13 +27,15 @@
29
27
 
30
28
 
31
29
  from functools import partial
30
+ from typing import Optional
32
31
 
32
+ import sqlalchemy
33
33
  from c2cgeoform.schema import GeoFormSchemaNode
34
34
  from c2cgeoform.views.abstract_views import ListField
35
35
  from deform.widget import FormWidget
36
36
  from pyramid.view import view_config, view_defaults
37
37
 
38
- from c2cgeoportal_admin.schemas.metadata import metadatas_schema_node
38
+ from c2cgeoportal_admin.schemas.metadata import metadata_schema_node
39
39
  from c2cgeoportal_admin.schemas.treegroup import children_schema_node
40
40
  from c2cgeoportal_admin.schemas.treeitem import parent_id_node
41
41
  from c2cgeoportal_admin.views.treeitems import TreeItemViews
@@ -43,26 +43,24 @@ from c2cgeoportal_commons.models.main import LayerGroup, TreeGroup
43
43
 
44
44
  _list_field = partial(ListField, LayerGroup)
45
45
 
46
-
47
46
  base_schema = GeoFormSchemaNode(LayerGroup, widget=FormWidget(fields_template="layer_group_fields"))
48
47
  base_schema.add(children_schema_node())
49
- base_schema.add(metadatas_schema_node.clone())
48
+ base_schema.add(metadata_schema_node(LayerGroup.metadatas, LayerGroup))
50
49
  base_schema.add_unique_validator(LayerGroup.name, LayerGroup.id)
51
- base_schema.add(parent_id_node(TreeGroup))
50
+ base_schema.add(parent_id_node(TreeGroup)) # type: ignore
52
51
 
53
52
 
54
53
  @view_defaults(match_param="table=layer_groups")
55
54
  class LayerGroupsViews(TreeItemViews):
55
+ """The layer group administration view."""
56
56
 
57
- _list_fields = (
58
- TreeItemViews._list_fields + [_list_field("is_expanded")] + TreeItemViews._extra_list_fields
59
- )
57
+ _list_fields = TreeItemViews._list_fields + TreeItemViews._extra_list_fields
60
58
 
61
59
  _id_field = "id"
62
60
  _model = LayerGroup
63
61
  _base_schema = base_schema
64
62
 
65
- def _base_query(self, query=None):
63
+ def _base_query(self, query: Optional[sqlalchemy.orm.query.Query] = None) -> sqlalchemy.orm.query.Query:
66
64
  return super()._base_query(self._request.dbsession.query(LayerGroup).distinct())
67
65
 
68
66
  @view_config(route_name="c2cgeoform_index", renderer="../templates/index.jinja2")
@@ -1,6 +1,4 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- # Copyright (c) 2017-2020, Camptocamp SA
1
+ # Copyright (c) 2017-2021, Camptocamp SA
4
2
  # All rights reserved.
5
3
 
6
4
  # Redistribution and use in source and binary forms, with or without
@@ -29,7 +27,9 @@
29
27
 
30
28
 
31
29
  from functools import partial
30
+ from typing import cast
32
31
 
32
+ import sqlalchemy
33
33
  from c2cgeoform.views.abstract_views import ListField
34
34
  from sqlalchemy.orm import subqueryload
35
35
 
@@ -40,6 +40,7 @@ _list_field = partial(ListField, Layer)
40
40
 
41
41
 
42
42
  class LayerViews(TreeItemViews):
43
+ """The layer administration view."""
43
44
 
44
45
  _list_fields = TreeItemViews._list_fields + [
45
46
  _list_field("public"),
@@ -51,7 +52,7 @@ class LayerViews(TreeItemViews):
51
52
  _list_field(
52
53
  "interfaces",
53
54
  renderer=lambda layer_wms: ", ".join(
54
- [i.name or "" for i in sorted(layer_wms.interfaces, key=lambda i: i.name)]
55
+ [i.name or "" for i in sorted(layer_wms.interfaces, key=lambda i: cast(str, i.name))]
55
56
  ),
56
57
  sort_column=Interface.name,
57
58
  filter_column=Interface.name,
@@ -59,14 +60,14 @@ class LayerViews(TreeItemViews):
59
60
  _list_field(
60
61
  "restrictionareas",
61
62
  renderer=lambda layer_wms: ", ".join(
62
- [r.name or "" for r in sorted(layer_wms.restrictionareas, key=lambda r: r.name)]
63
+ [r.name or "" for r in sorted(layer_wms.restrictionareas, key=lambda r: cast(str, r.name))]
63
64
  ),
64
65
  ),
65
66
  ] + TreeItemViews._extra_list_fields
66
67
 
67
- def _base_query(self, query):
68
+ def _base_query(self, query: sqlalchemy.orm.query.Query) -> sqlalchemy.orm.query.Query:
68
69
  return super()._base_query(
69
- query.outerjoin("interfaces")
70
+ query.outerjoin(Layer.interfaces)
70
71
  .options(subqueryload("interfaces"))
71
72
  .options(subqueryload("restrictionareas"))
72
73
  )