[saem-devel] [PATCH 09 of 10 sherpa] Backport import / add etype link components from saem_ref

Sylvain Thénault sylvain.thenault at logilab.fr
Thu Feb 23 10:24:41 CET 2017


Sent a V2 (though I forgot the V2 flag :$ )


Le 23/02/2017 à 10:12, Philippe Pepiot a écrit :
> On 02/23/2017 09:32 AM, Sylvain Thenault wrote:
>> # HG changeset patch
>> # User Sylvain Thénault <sylvain.thenault at logilab.fr>
>> # Date 1487802070 -3600
>> #      Wed Feb 22 23:21:10 2017 +0100
>> # Node ID 6b3f97568caa4a9e4fc8b90816ced41d6216cf59
>> # Parent  b596d5cf6585e39292bdcdcd8c6538d30bdacc76
>> Backport import / add etype link components from saem_ref
>>
>> diff --git a/views/components.py b/views/components.py
>> new file mode 100644
>> --- /dev/null
>> +++ b/views/components.py
>> @@ -0,0 +1,96 @@
>> +# copyright 2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
>
> I guess we want 2017 here
>
>> +# 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-sherpa components"""
>> +
>> +from cubicweb import _, tags
>> +from cubicweb.predicates import multi_lines_rset, has_permission,
>> is_instance
>> +from cubicweb.web import component
>> +
>> +
>> +def add_etype_link(req, etype, text=u'', klass='icon-plus-circled
>> pull-right',
>> +                   **urlparams):
>> +    """Return an HTML link to add an entity of type 'etype'."""
>> +    vreg = req.vreg
>> +    eschema = vreg.schema.eschema(etype)
>> +    if eschema.has_perm(req, 'add'):
>> +        url = vreg['etypes'].etype_class(etype).cw_create_url(req,
>> **urlparams)
>> +        return tags.a(text, href=url, klass=klass,
>> +                      title=req.__('New %s' % etype))
>> +    return u''
>> +
>> +
>> +def import_etype_link(req, etype, url):
>> +    """Return an HTML link to the view that may be used to import an
>> entity of type `etype`.
>> +    """
>> +    eschema = req.vreg.schema.eschema(etype)
>> +    if eschema.has_perm(req, 'add'):
>> +        return tags.a(u'', href=url, klass='icon-upload pull-right',
>> +                      title=req.__('Import %s' % etype))
>> +    return u''
>> +
>> +
>> +class AddEntityComponent(component.CtxComponent):
>> +    """Component with 'add' link to be displayed in 'same etype'
>> views usually 'SameETypeListView'.
>> +    """
>> +    __regid__ = 'saem_ref.add_entity'
>
> Change the __regid__ to 'sherpa.add_entity' ?
>
>> +    __select__ = (component.CtxComponent.__select__ &
>> multi_lines_rset() & has_permission('add') &
>> +                  is_instance('AuthorityRecord', 'ConceptScheme',
>> +                              'SEDAArchiveTransfer',
>> 'SEDAArchiveUnit'))
>> +    context = 'navtop'
>> +    extra_kwargs = {'SEDAArchiveUnit': {'unit_type': 'unit_content'}}
>> +
>> +    def render_body(self, w):
>> +        etype = self.cw_rset.description[0][0]
>> +        w(add_etype_link(self._cw, etype,
>> **self.extra_kwargs.get(etype, {})))
>> +
>> +
>> +class ImportEntityComponent(component.CtxComponent):
>> +    """Component with 'import' link to be displayed in 'same etype'
>> views usually
>> +    'SameETypeListView'.
>> +
>> +    Concret class should fill the `import_vid` class attribute and
>> add a proper `is_instance`
>> +    selector.
>> +    """
>> +    __abstract__ = True
>> +    __regid__ = 'saem_ref.import_entity'
>
> 'sherpa.import_entity' ?
>
>> +    __select__ = component.CtxComponent.__select__ &
>> multi_lines_rset() & has_permission('add')
>> +    import_url = None  # URL of the view that may be used to import
>> data
>> +    context = 'navtop'
>> +
>> +    def render_body(self, w):
>> +        etype = self.cw_rset.description[0][0]
>> +        w(import_etype_link(self._cw, etype, self.import_url))
>> +
>> +
>> +class EACImportComponent(ImportEntityComponent):
>> +    """Component with a link to import an authority record from an
>> EAC-CPF file."""
>> +    __select__ = (ImportEntityComponent.__select__
>> +                  & is_instance('AuthorityRecord'))
>> +    _('Import AuthorityRecord')  # generate message used by the
>> import component
>> +
>> +    @property
>> +    def import_url(self):
>> +        return self._cw.build_url('view', vid='eac.import')
>> +
>> +
>> +class SKOSImportComponent(ImportEntityComponent):
>> +    """Component with a link to import a concept scheme from a SKOS
>> file."""
>> +    __select__ = ImportEntityComponent.__select__ &
>> is_instance('ConceptScheme')
>> +    _('Import ConceptScheme')  # generate message used by the import
>> component
>> +
>> +    @property
>> +    def import_url(self):
>> +        return self._cw.build_url('add/skossource')
>> _______________________________________________
>> 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