Example #1
0
def children_schema_node(only_groups: bool = False) -> colander.SequenceSchema:
    """Geth the sequence to the children nodes."""
    return colander.SequenceSchema(
        ChildSchemaNode(
            LayergroupTreeitem,
            name="layergroup_treeitem",
            widget=ChildWidget(
                input_name="treeitem_id",
                model=TreeItem,
                label_field="name",
                icon_class=lambda treeitem: f"icon-{treeitem.item_type}",
                edit_url=treeitem_edit_url,
            ),
        ),
        name="children_relation",
        title=_("Children"),
        description=Literal(
            _(
                """
                <div class="help-block">
                    <p>The ordered children elements.</p>
                    <hr>
                </div>
                """
            ),
        ),
        candidates=colander.deferred(partial(treeitems, only_groups=only_groups)),
        validator=children_validator,
        widget=ChildrenWidget(child_input_name="treeitem_id", add_subitem=True, orderable=True),
    )
 def _item_actions(self, item):
     actions = super()._item_actions(item)
     if inspect(item).persistent:
         actions.insert(next((i for i, v in enumerate(actions) if v.name() == 'delete')), ItemAction(
             name='convert_to_wmts',
             label=_('Convert to WMTS'),
             icon='glyphicon icon-l_wmts',
             url=self._request.route_url(
                 'convert_to_wmts',
                 id=getattr(item, self._id_field)),
             method='POST',
             confirmation=_('Are you sure you want to convert this layer to WMTS?')))
     return actions
Example #3
0
 def _item_actions(self, item, readonly=False):
     actions = super()._item_actions(item, readonly)
     if inspect(item).persistent:
         actions.insert(
             next((i for i, v in enumerate(actions) if v.name() == "delete")),
             ItemAction(
                 name="convert_to_wms",
                 label=_("Convert to WMS"),
                 icon="glyphicon icon-l_wmts",
                 url=self._request.route_url("convert_to_wms", id=getattr(item, self._id_field)),
                 method="POST",
                 confirmation=_("Are you sure you want to convert this layer to WMS?"),
             ),
         )
     return actions
Example #4
0
def children_validator(node, cstruct):
    for dict_ in cstruct:
        if not dict_['treeitem_id'] in [item.id for item, group in node.treeitems]:
            raise colander.Invalid(
                node,
                _('Value {} does not exist in table {} or is not allowed to avoid cycles').
                format(dict_['treeitem_id'], TreeItem.__tablename__))
Example #5
0
def themes_validator(node, cstruct):
    for dict_ in cstruct:
        if not dict_['id'] in [item.id for item, dummy in node.treeitems]:
            raise colander.Invalid(
                node,
                _('Value {} does not exist in table {}').format(
                    dict_['treeitem_id'], Theme.__tablename__))
Example #6
0
def _translate_available_metadata(
        available_metadata: Dict[str, Any],
        request: pyramid.request.Request) -> Dict[str, Any]:
    result = {}
    result.update(available_metadata)
    result["description"] = request.localizer.translate(
        _(available_metadata.get("description", "").strip()))
    return result
Example #7
0
def themes_validator(node, cstruct):
    for dict_ in cstruct:
        if not dict_["id"] in [item["id"] for item in node.candidates]:
            raise colander.Invalid(
                node,
                _("Value {} does not exist in table {}").format(
                    dict_["id"], Theme.__tablename__),
            )
Example #8
0
 def _add_value_node(self, type_name, colander_type, **kw):
     self.add_before(
         'description',
         colander.SchemaNode(colander_type,
                             name=type_name,
                             title=_('Value'),
                             missing=colander.null,
                             **kw))
     self.available_types.append(type_name)
Example #9
0
    def schema(self) -> GeoFormSchemaNode:
        try:
            obj = self._get_object()
        except HTTPNotFound:
            obj = None

        schema = self._base_schema.clone()
        schema["url"].description = Literal(
            _("{}<br>Current runtime value is: {}").format(
                schema["url"].description,
                obj.url_description(self._request),
            ))
        schema["url_wfs"].description = Literal(
            _("{}<br>Current runtime value is: {}").format(
                schema["url_wfs"].description,
                obj.url_wfs_description(self._request),
            ))
        return schema
Example #10
0
def children_validator(node, cstruct):
    """Get the validator on the children nodes."""
    for dict_ in cstruct:
        if not dict_["treeitem_id"] in [item["id"] for item in node.candidates]:
            raise colander.Invalid(
                node,
                _("Value {} does not exist in table {} or is not allowed to avoid cycles").format(
                    dict_["treeitem_id"], TreeItem.__tablename__
                ),
            )
Example #11
0
def regex_validator(node, value):
    definition = node.metadata_definitions.get(value["name"], {})
    if definition.get("type", "string") == "regex":
        validator = colander.Regex(definition["regex"], msg=_(definition["error_message"]))
        try:
            validator(node["string"], value["string"])
        except colander.Invalid as e:
            error = colander.Invalid(node)
            error.add(e, node.children.index(node["string"]))
            raise error
Example #12
0
 def view(self):
     to_render = super().edit()
     if not self._is_new():
         convert_url = self._request.route_url(
             'layers_wmts_from_wms',
             table='layers_wmts',
             wms_layer_id=self._request.matchdict.get('id'),
             action='from_wms')
         to_render['actions'].append({'url': convert_url,
                                      'label': _('Convert to wmts')})
     return to_render
Example #13
0
def regex_validator(node, value):
    definition = node.metadata_definitions[value['name']]
    if definition.get('type', 'string') == 'regex':
        validator = colander.Regex(definition['regex'],
                                   msg=_(definition['error_message']))
        try:
            validator(node['string'], value['string'])
        except colander.Invalid as e:
            error = colander.Invalid(node)
            error.add(e, node.children.index(node['string']))
            raise error
Example #14
0
def children_schema_node(only_groups=False):
    return colander.SequenceSchema(
        ChildSchemaNode(LayergroupTreeitem,
                        name="layergroup_treeitem",
                        widget=ChildWidget()),
        name="children_relation",
        title=_("Children"),
        treeitems=colander.deferred(partial(treeitems,
                                            only_groups=only_groups)),
        validator=children_validator,
        widget=ChildrenWidget(category="structural"),
    )
Example #15
0
 def _item_actions(self, item, readonly=False):
     actions = super()._item_actions(item, readonly)
     if inspect(item).persistent:
         actions.insert(
             next((i for i, v in enumerate(actions)
                   if v.name() == "delete")),
             ItemAction(
                 name="synchronize",
                 label=_("Synchronize"),
                 icon="glyphicon glyphicon-import",
                 url=self._request.route_url("ogcserver_synchronize",
                                             id=getattr(
                                                 item, self._id_field)),
             ),
         )
     return actions
Example #16
0
def children_schema_node(only_groups=False):
    return colander.SequenceSchema(
        ChildSchemaNode(
            LayergroupTreeitem,
            name="layergroup_treeitem",
            widget=ChildWidget(
                input_name="treeitem_id",
                model=TreeItem,
                label_field="name",
                icon_class=lambda treeitem: "icon-{}".format(treeitem.item_type
                                                             ),
                edit_url=treeitem_edit_url,
            ),
        ),
        name="children_relation",
        title=_("Children"),
        candidates=colander.deferred(
            partial(treeitems, only_groups=only_groups)),
        validator=children_validator,
        widget=ChildrenWidget(child_input_name="treeitem_id",
                              add_subitem=True,
                              orderable=True),
    )
Example #17
0
class OGCServerViews(AbstractViews):  # type: ignore
    """The OGC server administration view."""

    _list_fields = [
        _list_field("id"),
        _list_field("name"),
        _list_field("description"),
        _list_field("url"),
        _list_field("url_wfs"),
        _list_field("type"),
        _list_field("image_type"),
        _list_field("auth"),
        _list_field("wfs_support"),
        _list_field("is_single_tile"),
    ]
    _id_field = "id"
    _model = OGCServer
    _base_schema = base_schema

    MSG_COL = {
        **AbstractViews.MSG_COL,
        "cannot_delete":
        UserMessage(
            _("Impossible to delete this server while it contains WMS layers."
              ),
            "alert-danger",
        ),
    }

    @view_config(route_name="c2cgeoform_index",
                 renderer="../templates/index.jinja2")  # type: ignore
    def index(self) -> Dict[str, Any]:
        return super().index()  # type: ignore

    @view_config(route_name="c2cgeoform_grid",
                 renderer="fast_json")  # type: ignore
    def grid(self) -> Dict[str, Any]:
        return super().grid()  # type: ignore

    def schema(self) -> GeoFormSchemaNode:
        try:
            obj = self._get_object()
        except HTTPNotFound:
            obj = None

        schema = self._base_schema.clone()
        schema["url"].description = Literal(
            _("{}<br>Current runtime value is: {}").format(
                schema["url"].description,
                obj.url_description(self._request),
            ))
        schema["url_wfs"].description = Literal(
            _("{}<br>Current runtime value is: {}").format(
                schema["url_wfs"].description,
                obj.url_wfs_description(self._request),
            ))
        return schema

    def _item_actions(self,
                      item: OGCServer,
                      readonly: bool = False) -> List[Any]:
        actions = cast(List[Any], super()._item_actions(item, readonly))
        if inspect(item).persistent:
            actions.insert(
                next((i for i, v in enumerate(actions)
                      if v.name() == "delete")),
                ItemAction(
                    name="synchronize",
                    label=_("Synchronize"),
                    icon="glyphicon glyphicon-import",
                    url=self._request.route_url("ogcserver_synchronize",
                                                id=getattr(
                                                    item, self._id_field)),
                ),
            )
        return actions

    @view_config(  # type: ignore
        route_name="c2cgeoform_item",
        request_method="GET",
        renderer="../templates/edit.jinja2")
    def view(self) -> Dict[str, Any]:
        return super().edit(self.schema())  # type: ignore

    @view_config(  # type: ignore
        route_name="c2cgeoform_item",
        request_method="POST",
        renderer="../templates/edit.jinja2")
    def save(self) -> Dict[str, Any]:
        return super().save()  # type: ignore

    @view_config(route_name="c2cgeoform_item",
                 request_method="DELETE",
                 renderer="fast_json")  # type: ignore
    def delete(self) -> Dict[str, Any]:
        obj = self._get_object()
        if len(obj.layers) > 0:
            return {
                "success":
                True,
                "redirect":
                self._request.route_url(
                    "c2cgeoform_item",
                    action="edit",
                    id=obj.id,
                    _query=[("msg_col", "cannot_delete")],
                ),
            }
        return super().delete()  # type: ignore

    @view_config(  # type: ignore
        route_name="c2cgeoform_item_duplicate",
        request_method="GET",
        renderer="../templates/edit.jinja2")
    def duplicate(self) -> Dict[str, Any]:
        return super().duplicate()  # type: ignore

    @view_config(  # type: ignore
        route_name="ogcserver_synchronize",
        renderer="../templates/ogcserver_synchronize.jinja2")
    def synchronize(self) -> Dict[str, Any]:
        obj = self._get_object()

        if self._request.method == "GET":
            return {
                "ogcserver": obj,
                "success": None,
                "report": None,
            }

        if self._request.method == "POST":
            force_parents = self._request.POST.get("force-parents",
                                                   "false") == "on"
            force_ordering = self._request.POST.get("force-ordering",
                                                    "false") == "on"
            clean = self._request.POST.get("clean", "false") == "on"

            synchronizer = OGCServerSynchronizer(
                self._request,
                obj,
                force_parents=force_parents,
                force_ordering=force_ordering,
                clean=clean,
            )
            if "check" in self._request.params:
                synchronizer.check_layers()
            elif "dry-run" in self._request.params:
                synchronizer.synchronize(dry_run=True)
            elif "synchronize" in self._request.params:
                synchronizer.synchronize()
            return {
                "ogcserver": obj,
                "success": True,
                "report": synchronizer.report(),
            }

        return {}
Example #18
0
base_schema.add(
    colander.SequenceSchema(
        GeoFormManyToManySchemaNode(
            Layer,
            name="layer",
            includes=["id"],
            widget=ChildWidget(
                input_name="id",
                model=Layer,
                label_field="name",
                icon_class=lambda layer: "icon-{}".format(layer.item_type),
                edit_url=treeitem_edit_url,
            ),
        ),
        name="layers",
        title=_("Layers"),
        candidates=colander.deferred(layers),
        widget=ChildrenWidget(child_input_name="id", orderable=False),
    ))


@view_defaults(match_param="table=restriction_areas")
class RestrictionAreaViews(AbstractViews):
    _list_fields = [
        _list_field("id"),
        _list_field("name"),
        _list_field("description"),
        _list_field("readwrite"),
        _list_field("roles",
                    renderer=lambda restriction_area: ", ".join(
                        r.name for r in restriction_area.roles)),
Example #19
0
import colander
from deform.widget import MappingWidget, SequenceWidget
from c2cgeoform.schema import GeoFormSchemaNode
from c2cgeoportal_commons.models.main import Dimension
from c2cgeoportal_admin import _

dimensions_schema_node = colander.SequenceSchema(GeoFormSchemaNode(
    Dimension,
    name='dimension',
    widget=MappingWidget(template='dimension'),
),
                                                 name='dimensions',
                                                 title=_('Dimensions'),
                                                 widget=SequenceWidget(
                                                     category='structural',
                                                     template='dimensions'))
Example #20
0
    def _item_actions(self, item, parent_id=None):
        actions = []
        actions.append(
            ItemAction(name='edit',
                       label=_('Edit'),
                       icon='glyphicon glyphicon-pencil',
                       url=self._request.route_url(
                           'c2cgeoform_item',
                           table=itemtypes_tables[item.item_type],
                           id=item.id)))

        if item.item_type in ('theme', 'group'):
            actions.append(
                ItemAction(name='new_layer_group',
                           label=_('New layer group'),
                           icon='glyphicon glyphicon-plus',
                           url='{}?parent_id={}'.format(
                               self._request.route_url('c2cgeoform_item',
                                                       table='layer_groups',
                                                       id='new'), item.id)))

        if item.item_type == 'group':
            actions.append(
                ItemAction(name='new_layer_wms',
                           label=_('New WMS layer'),
                           icon='glyphicon glyphicon-plus',
                           url='{}?parent_id={}'.format(
                               self._request.route_url('c2cgeoform_item',
                                                       table='layers_wms',
                                                       id='new'), item.id)))

            actions.append(
                ItemAction(name='new_layer_wmts',
                           label=_('New WMTS layer'),
                           icon='glyphicon glyphicon-plus',
                           url='{}?parent_id={}'.format(
                               self._request.route_url('c2cgeoform_item',
                                                       table='layers_wmts',
                                                       id='new'), item.id)))

        actions.append(
            ItemAction(name='duplicate',
                       label=_('Duplicate'),
                       icon='glyphicon glyphicon-duplicate',
                       url=self._request.route_url(
                           'c2cgeoform_item_duplicate',
                           table=itemtypes_tables[item.item_type],
                           id=item.id)))

        if parent_id is not None:
            actions.append(
                ItemAction(
                    name='unlink',
                    label=_('Unlink'),
                    icon='glyphicon glyphicon-log-out',
                    url=self._request.route_url('layertree_unlink',
                                                group_id=parent_id,
                                                item_id=item.id),
                    method='DELETE',
                    confirmation=
                    _('Are your sure you want to unlink this record from his parent ?'
                      )))

        actions.append(
            ItemAction(name='delete',
                       label=_('Delete'),
                       icon='glyphicon glyphicon-remove',
                       url=self._request.route_url('layertree_delete',
                                                   item_id=item.id),
                       method='DELETE',
                       confirmation=_(
                           'Are your sure you want to delete this record ?')))

        return actions
Example #21
0
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# The views and conclusions contained in the software and documentation are those
# of the authors and should not be interpreted as representing official policies,
# either expressed or implied, of the FreeBSD Project.

import colander
from c2cgeoform.schema import GeoFormSchemaNode
from deform.widget import MappingWidget, SequenceWidget

from c2cgeoportal_admin import _
from c2cgeoportal_commons.models.main import Dimension

dimensions_schema_node = colander.SequenceSchema(
    GeoFormSchemaNode(Dimension,
                      name="dimension",
                      widget=MappingWidget(template="dimension")),
    name="dimensions",
    title=_("Dimensions"),
    widget=SequenceWidget(category="structural", template="dimensions"),
)
Example #22
0
def json_validator(node, value):
    """Validate the value to be a valid JSON."""
    try:
        json.loads(value)
    except ValueError as e:
        raise colander.Invalid(node, _('Parser report: "{}"').format(str(e)))
Example #23
0
    def dictify(self, obj):
        dict_ = super().dictify(obj)
        value = obj.value or colander.null
        # depending on the type set the value in the right widget
        dict_[self._ui_type(obj.name)] = value
        return dict_

    def _ui_type(self, metadata_name):
        # pylint: disable=unsubscriptable-object
        metadata_type = self.metadata_definitions[metadata_name].get(
            "type", "string")
        return metadata_type if metadata_type in self.available_types else "string"


metadatas_schema_node = colander.SequenceSchema(
    MetadataSchemaNode(
        Metadata,
        name="metadata",
        metadata_definitions=metadata_definitions,
        validator=regex_validator,
        widget=MappingWidget(template="metadata"),
        overrides={"name": {
            "widget": metadata_name_widget
        }},
    ),
    name="metadatas",
    title=_("Metadatas"),
    metadata_definitions=metadata_definitions,
    widget=SequenceWidget(template="metadatas", category="structural"),
)
Example #24
0
    def _item_actions(self, item, parent_id=None) -> List[ItemAction]:
        actions = []
        actions.append(
            ItemAction(
                name="edit",
                label=_("Edit"),
                icon="glyphicon glyphicon-pencil",
                url=self._request.route_url(
                    "c2cgeoform_item",
                    table=itemtypes_tables[item.item_type],
                    id=item.id),
            ))

        if item.item_type in ("theme", "group"):
            actions.append(
                ItemAction(
                    name="new_layer_group",
                    label=_("New layer group"),
                    icon="glyphicon glyphicon-plus",
                    url="{}?parent_id={}".format(
                        self._request.route_url("c2cgeoform_item",
                                                table="layer_groups",
                                                id="new"), item.id),
                ))

        if item.item_type == "group":
            actions.append(
                ItemAction(
                    name="new_layer_wms",
                    label=_("New WMS layer"),
                    icon="glyphicon glyphicon-plus",
                    url="{}?parent_id={}".format(
                        self._request.route_url("c2cgeoform_item",
                                                table="layers_wms",
                                                id="new"), item.id),
                ))

            actions.append(
                ItemAction(
                    name="new_layer_wmts",
                    label=_("New WMTS layer"),
                    icon="glyphicon glyphicon-plus",
                    url="{}?parent_id={}".format(
                        self._request.route_url("c2cgeoform_item",
                                                table="layers_wmts",
                                                id="new"), item.id),
                ))

        actions.append(
            ItemAction(
                name="duplicate",
                label=_("Duplicate"),
                icon="glyphicon glyphicon-duplicate",
                url=self._request.route_url(
                    "c2cgeoform_item_duplicate",
                    table=itemtypes_tables[item.item_type],
                    id=item.id),
            ))

        if parent_id is not None:
            actions.append(
                ItemAction(
                    name="unlink",
                    label=_("Unlink"),
                    icon="glyphicon glyphicon-log-out",
                    url=self._request.route_url("layertree_unlink",
                                                group_id=parent_id,
                                                item_id=item.id),
                    method="DELETE",
                    confirmation=
                    _("Are your sure you want to unlink this record from his parent?"
                      ),
                ))

        actions.append(
            ItemAction(
                name="delete",
                label=_("Delete"),
                icon="glyphicon glyphicon-remove",
                url=self._request.route_url("layertree_delete",
                                            item_id=item.id),
                method="DELETE",
                confirmation=_(
                    "Are your sure you want to delete this record?"),
            ))

        return actions
Example #25
0
        dict_['value'] = dict_[self._ui_type(dict_['name'])]
        return super().objectify(dict_, context)

    def dictify(self, obj):
        dict_ = super().dictify(obj)
        value = obj.value or colander.null
        # depending on the type set the value in the right widget
        dict_[self._ui_type(obj.name)] = value
        return dict_

    def _ui_type(self, metadata_name):
        # pylint: disable=unsubscriptable-object
        metadata_type = self.metadata_definitions[metadata_name].get(
            'type', 'string')
        return metadata_type if metadata_type in self.available_types else 'string'


metadatas_schema_node = colander.SequenceSchema(
    MetadataSchemaNode(Metadata,
                       name='metadata',
                       metadata_definitions=metadata_definitions,
                       validator=regex_validator,
                       widget=MappingWidget(template='metadata'),
                       overrides={'name': {
                           'widget': metadata_name_widget
                       }}),
    name='metadatas',
    title=_('Metadatas'),
    metadata_definitions=metadata_definitions,
    widget=SequenceWidget(template='metadatas', category='structural'))
Example #26
0
import colander
from c2cgeoform.ext.deform_ext import RelationCheckBoxListWidget
from c2cgeoform.schema import (
    GeoFormManyToManySchemaNode,
    manytomany_validator,
)
from c2cgeoportal_commons.models.main import Interface
from c2cgeoportal_admin import _

interfaces_schema_node = colander.SequenceSchema(
    GeoFormManyToManySchemaNode(Interface),
    name='interfaces',
    title=_('Interfaces'),
    widget=RelationCheckBoxListWidget(
        Interface,
        'id',
        'name',
        order_by='name',
        edit_url=lambda request, value: request.route_url(
            'c2cgeoform_item',
            table='interfaces',
            id=value
        )
    ),
    validator=manytomany_validator,
    missing=colander.drop
)
from c2cgeoform.ext.deform_ext import RelationCheckBoxListWidget
from c2cgeoform.schema import GeoFormManyToManySchemaNode, manytomany_validator
import colander

from c2cgeoportal_admin import _
from c2cgeoportal_commons.models.main import RestrictionArea

restrictionareas_schema_node = colander.SequenceSchema(
    GeoFormManyToManySchemaNode(RestrictionArea),
    name="restrictionareas",
    title=_("Restriction areas"),
    widget=RelationCheckBoxListWidget(
        RestrictionArea,
        "id",
        "name",
        order_by="name",
        edit_url=lambda request, value: request.route_url(
            "c2cgeoform_item", table="restriction_areas", id=value),
    ),
    validator=manytomany_validator,
    missing=colander.drop,
)
Example #28
0
from c2cgeoform.ext.deform_ext import RelationCheckBoxListWidget
from c2cgeoform.schema import GeoFormManyToManySchemaNode, manytomany_validator
import colander

from c2cgeoportal_admin import _
from c2cgeoportal_commons.models.main import Interface

interfaces_schema_node = colander.SequenceSchema(
    GeoFormManyToManySchemaNode(Interface),
    name="interfaces",
    title=_("Interfaces"),
    widget=RelationCheckBoxListWidget(
        Interface,
        "id",
        "name",
        order_by="name",
        edit_url=lambda request, value: request.route_url(
            "c2cgeoform_item", table="interfaces", id=value),
    ),
    validator=manytomany_validator,
    missing=colander.drop,
)
Example #29
0
            name="layer",
            includes=["id"],
            widget=ChildWidget(
                input_name="id",
                model=User,
                label_field="username",
                icon_class=lambda user: "******",
                edit_url=lambda request, user: request.route_url(
                    "c2cgeoform_item",
                    table="users",
                    id=user.id,
                ),
            ),
        ),
        name="users",
        title=_("Users"),
        candidates=colander.deferred(users),
        widget=ChildrenWidget(child_input_name="id", orderable=False, category="structural"),
    )
)


@view_defaults(match_param="table=roles")
class RoleViews(AbstractViews):
    _list_fields = [
        _list_field("id"),
        _list_field("name"),
        _list_field("description"),
        _list_field(
            "functionalities",
            renderer=lambda role: ", ".join(["{}={}".format(f.name, f.value) for f in role.functionalities]),
Example #30
0
import colander
from c2cgeoform.ext.deform_ext import RelationCheckBoxListWidget
from c2cgeoform.schema import (
    GeoFormManyToManySchemaNode,
    manytomany_validator,
)
from c2cgeoportal_commons.models.main import RestrictionArea
from c2cgeoportal_admin import _

restrictionareas_schema_node = colander.SequenceSchema(
    GeoFormManyToManySchemaNode(RestrictionArea),
    name='restrictionareas',
    title=_('Restriction areas'),
    widget=RelationCheckBoxListWidget(
        RestrictionArea,
        'id',
        'name',
        order_by='name',
        edit_url=lambda request, value: request.route_url(
            'c2cgeoform_item',
            table='restriction_areas',
            id=value,
        )
    ),
    validator=manytomany_validator,
    missing=colander.drop
)