[saem-devel] [PATCH 1 of 3 seda] [views] Backport /sedalib path handling from saem_ref

Sylvain Thénault sylvain.thenault at logilab.fr
Thu Feb 23 09:40:31 CET 2017


CI: https://jenkins.logilab.org/job/cubicweb-seda/46/


Le 23/02/2017 à 09:37, Sylvain Thenault a écrit :
> # HG changeset patch
> # User Sylvain Thénault <sylvain.thenault at logilab.fr>
> # Date 1487795986 -3600
> #      Wed Feb 22 21:39:46 2017 +0100
> # Node ID 455449377946008c9eafe51aac28bd6b273d9696
> # Parent  6804cd63f82aaf1e97ca10b3678f0c30afc1c2ed
> [views] Backport /sedalib path handling from saem_ref
>
> leading to archive units which are not in a profile.
>
> diff --git a/views/sedalib.py b/views/sedalib.py
> new file mode 100644
> --- /dev/null
> +++ b/views/sedalib.py
> @@ -0,0 +1,64 @@
> +# copyright 2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
> +# contact http://www.logilab.fr -- mailto:contact at logilab.fr
> +#
> +# This program is free software: you can redistribute it and/or modify it under
> +# the terms of the GNU Lesser General Public License as published by the Free
> +# Software Foundation, either version 2.1 of the License, or (at your option)
> +# any later version.
> +#
> +# This program is distributed in the hope that it will be useful, but WITHOUT
> +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
> +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
> +# details.
> +#
> +# You should have received a copy of the GNU Lesser General Public License along
> +# with this program. If not, see <http://www.gnu.org/licenses/>.
> +"""cubicweb-seda views for archive unit components"""
> +
> +from cubicweb.predicates import (is_instance, multi_lines_rset,
> +                                 has_related_entities, relation_possible)
> +from cubicweb.web.views import basecomponents, baseviews, ibreadcrumbs, urlrewrite
> +
> +
> +class SEDAReqRewriter(urlrewrite.SimpleReqRewriter):
> +    rules = [
> +        ('/sedalib', dict(rql='Any X WHERE X is SEDAArchiveUnit, '
> +                              'NOT X seda_archive_unit P',
> +                          vid='seda.sedalib')),
> +    ]
> +
> +
> +# navigation #######################################################################################
> +
> +class SEDAComponentsBreadcrumbsAdapter(ibreadcrumbs.IBreadCrumbsAdapter):
> +    """Breadcrumbs adapter pointing to /sedalib route when entity has no
> +    parent.
> +    """
> +    __select__ = (ibreadcrumbs.IBreadCrumbsAdapter.__select__
> +                  & relation_possible('seda_archive_unit', role='subject')
> +                  & ~has_related_entities('seda_archive_unit', role='subject'))
> +
> +    def breadcrumbs(self, *args, **kwargs):
> +        return [(self._cw.build_url('sedalib'), self._cw._('SEDAArchiveUnit_plural')),
> +                self.entity]
> +
> +
> +class SEDAComponentsBreadCrumbETypeVComponent(ibreadcrumbs.BreadCrumbEntityVComponent):
> +    """For proper display of the breadcrumb in the SEDA components list"""
> +    __select__ = (basecomponents.HeaderComponent.__select__
> +                  & multi_lines_rset() & is_instance('SEDAArchiveUnit'))
> +
> +    def render_breadcrumbs(self, w, contextentity, path):
> +        w(u'<a href="%s">%s</a>' % (self._cw.build_url('sedalib'),
> +                                    self._cw._('SEDAArchiveUnit')))
> +
> +
> +# SEDA lib components ##############################################################################
> +
> +class SEDALibView(baseviews.SameETypeListView):
> +    __regid__ = 'seda.sedalib'
> +    __select__ = is_instance('SEDAArchiveUnit')
> +
> +    @property
> +    def title(self):
> +        return self._cw._('SEDAArchiveUnit_plural')
> _______________________________________________
> saem-devel mailing list
> saem-devel at lists.cubicweb.org
> http://lists.cubicweb.org/mailman/listinfo/saem-devel

-- 
Sylvain Thénault, LOGILAB, Paris (01.45.32.03.12) - Toulouse (05.62.17.16.42)
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
CubicWeb, the semantic web framework:    http://www.cubicweb.org



More information about the saem-devel mailing list