Commit 3ff831bd authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

[ui] Introduce a tab for data-objects of an archive transfer (binary or physical)

and start configuring the creation/edition form for them.

All the "add button" related code in __init__ has been backported from the
saem_ref cube.

Related to #11447483
parent 60bc39770939
......@@ -829,10 +829,6 @@ msgstr ""
msgid "SEDABinaryDataObject"
msgstr ""
msgctxt "inlined:SEDAArchiveTransfer.seda_binary_data_object.object"
msgid "SEDABinaryDataObject"
msgstr ""
msgid "SEDABinaryDataObject_plural"
msgstr ""
......@@ -1584,10 +1580,6 @@ msgstr ""
msgid "SEDAPhysicalDataObject"
msgstr ""
msgctxt "inlined:SEDAArchiveTransfer.seda_physical_data_object.object"
msgid "SEDAPhysicalDataObject"
msgstr ""
msgid "SEDAPhysicalDataObject_plural"
msgstr ""
......@@ -3715,10 +3707,6 @@ msgstr ""
msgid "add a SEDABinaryDataObject"
msgstr ""
msgctxt "inlined:SEDAArchiveTransfer.seda_binary_data_object.object"
msgid "add a SEDABinaryDataObject"
msgstr ""
msgid "add a SEDAClassificationReassessingDate"
msgstr ""
......@@ -4251,10 +4239,6 @@ msgstr ""
msgid "add a SEDAPhysicalDataObject"
msgstr ""
msgctxt "inlined:SEDAArchiveTransfer.seda_physical_data_object.object"
msgid "add a SEDAPhysicalDataObject"
msgstr ""
msgid "add a SEDAPhysicalDimensions"
msgstr ""
......@@ -6077,12 +6061,6 @@ msgctxt "CWRType"
msgid "scheme_relation_type_object"
msgstr ""
msgid "seda.at.code_list_versions_tab"
msgstr ""
msgid "seda.at.main_tab"
msgstr ""
msgid "seda_access_rule"
msgstr ""
......@@ -6557,6 +6535,15 @@ msgctxt "SEDAArchiveUnit"
msgid "seda_archive_unit_ref_id_to_object"
msgstr ""
msgid "seda_at_code_list_versions_tab"
msgstr ""
msgid "seda_at_data_objects_tab"
msgstr ""
msgid "seda_at_main_tab"
msgstr ""
msgid "seda_attachment"
msgstr ""
......
......@@ -29,6 +29,9 @@ msgid ""
"Default identifier that will be used to handle references. This is not "
"necessarily the identifier that will appear in the final sheet."
msgstr ""
"Identifiant qui sera utilisé pour gérer les références à la génération du "
"profil - ce n'est pas nécessairement l'identifiant qui sera utilisé dans les "
"bordereaux de transfert"
msgid "New Agent"
msgstr ""
......@@ -587,7 +590,7 @@ msgid "SEDAAltArchiveUnitArchiveUnitRefId_plural"
msgstr ""
msgid "SEDAAltBinaryDataObjectAttachment"
msgstr ""
msgstr "<b>Alternative</b> : URI ou attachement"
msgctxt ""
"inlined:SEDABinaryDataObject.seda_alt_binary_data_object_attachment.subject"
......@@ -807,7 +810,7 @@ msgid "SEDAArchiveUnit_plural"
msgstr ""
msgid "SEDAAttachment"
msgstr ""
msgstr "attachement"
msgctxt "inlined:SEDAAltBinaryDataObjectAttachment.seda_attachment.object"
msgid "SEDAAttachment"
......@@ -829,12 +832,8 @@ msgstr ""
msgid "SEDABinaryDataObject"
msgstr ""
msgctxt "inlined:SEDAArchiveTransfer.seda_binary_data_object.object"
msgid "SEDABinaryDataObject"
msgstr ""
msgid "SEDABinaryDataObject_plural"
msgstr ""
msgstr "objets-données binaires"
msgid "SEDAClassificationReassessingDate"
msgstr ""
......@@ -1132,7 +1131,7 @@ msgid "SEDADocumentType_plural"
msgstr ""
msgid "SEDAEncoding"
msgstr ""
msgstr "encodage"
msgctxt "inlined:SEDAFormatIdentification.seda_encoding_from.object"
msgid "SEDAEncoding"
......@@ -1218,7 +1217,7 @@ msgid "SEDAFilePlanPosition_plural"
msgstr ""
msgid "SEDAFormatId"
msgstr ""
msgstr "type spécifique du format"
msgctxt "inlined:SEDAFormatIdentification.seda_format_id_from.object"
msgid "SEDAFormatId"
......@@ -1228,7 +1227,7 @@ msgid "SEDAFormatId_plural"
msgstr ""
msgid "SEDAFormatIdentification"
msgstr ""
msgstr "format"
msgctxt "inlined:SEDABinaryDataObject.seda_format_identification.subject"
msgid "SEDAFormatIdentification"
......@@ -1238,7 +1237,7 @@ msgid "SEDAFormatIdentification_plural"
msgstr ""
msgid "SEDAFormatLitteral"
msgstr ""
msgstr "forme littérale du nom du format"
msgctxt "inlined:SEDAFormatIdentification.seda_format_litteral.object"
msgid "SEDAFormatLitteral"
......@@ -1470,7 +1469,7 @@ msgid "SEDAMasterdata_plural"
msgstr ""
msgid "SEDAMessageDigest"
msgstr ""
msgstr "empreinte du message"
msgctxt "inlined:SEDABinaryDataObject.seda_message_digest.subject"
msgid "SEDAMessageDigest"
......@@ -1490,7 +1489,7 @@ msgid "SEDAMetadata_plural"
msgstr ""
msgid "SEDAMimeType"
msgstr ""
msgstr "type MIME"
msgctxt "inlined:SEDAFormatIdentification.seda_mime_type_from.object"
msgid "SEDAMimeType"
......@@ -1584,12 +1583,8 @@ msgstr ""
msgid "SEDAPhysicalDataObject"
msgstr ""
msgctxt "inlined:SEDAArchiveTransfer.seda_physical_data_object.object"
msgid "SEDAPhysicalDataObject"
msgstr ""
msgid "SEDAPhysicalDataObject_plural"
msgstr ""
msgstr "objets-données physiques"
msgid "SEDAPhysicalDimensions"
msgstr ""
......@@ -2220,7 +2215,7 @@ msgid "SEDAType_plural"
msgstr ""
msgid "SEDAUri"
msgstr ""
msgstr "URI"
msgctxt "inlined:SEDAAltBinaryDataObjectAttachment.seda_uri.object"
msgid "SEDAUri"
......@@ -2274,7 +2269,7 @@ msgid "SEDAWriter_plural"
msgstr ""
msgid "SEDAfilename"
msgstr ""
msgstr "nom du fichier"
msgctxt "inlined:SEDAAttachment.seda_filename.object"
msgid "SEDAfilename"
......@@ -3715,10 +3710,6 @@ msgstr ""
msgid "add a SEDABinaryDataObject"
msgstr ""
msgctxt "inlined:SEDAArchiveTransfer.seda_binary_data_object.object"
msgid "add a SEDABinaryDataObject"
msgstr ""
msgid "add a SEDAClassificationReassessingDate"
msgstr ""
......@@ -4251,10 +4242,6 @@ msgstr ""
msgid "add a SEDAPhysicalDataObject"
msgstr ""
msgctxt "inlined:SEDAArchiveTransfer.seda_physical_data_object.object"
msgid "add a SEDAPhysicalDataObject"
msgstr ""
msgid "add a SEDAPhysicalDimensions"
msgstr ""
......@@ -5527,7 +5514,7 @@ msgstr ""
msgid ""
"creating SEDABinaryDataObject (SEDABinaryDataObject seda_binary_data_object "
"SEDAArchiveTransfer %(linkto)s)"
msgstr ""
msgstr "création d'un objet-données binaire dans le profil %(linkto)s"
msgid ""
"creating SEDAComment (SEDAComment seda_comment SEDAArchiveTransfer "
......@@ -5579,7 +5566,7 @@ msgstr ""
msgid ""
"creating SEDAPhysicalDataObject (SEDAPhysicalDataObject "
"seda_physical_data_object SEDAArchiveTransfer %(linkto)s)"
msgstr ""
msgstr "création d'un objet-données physique dans le profil %(linkto)s"
msgid ""
"creating SEDARecipient (SEDARecipient seda_recipient_from SEDAContent "
......@@ -5891,7 +5878,7 @@ msgid "href"
msgstr ""
msgid "id"
msgstr ""
msgstr "identifiant"
msgctxt "SEDAArchiveUnit"
msgid "id"
......@@ -6077,12 +6064,6 @@ msgctxt "CWRType"
msgid "scheme_relation_type_object"
msgstr ""
msgid "seda.at.code_list_versions_tab"
msgstr "vocabulaires (CodeListVersions)"
msgid "seda.at.main_tab"
msgstr "description"
msgid "seda_access_rule"
msgstr ""
......@@ -6172,7 +6153,7 @@ msgid "seda_addressee_to_object"
msgstr ""
msgid "seda_algorithm"
msgstr ""
msgstr "algorithme"
msgctxt "SEDACompressed"
msgid "seda_algorithm"
......@@ -6557,6 +6538,15 @@ msgctxt "SEDAArchiveUnit"
msgid "seda_archive_unit_ref_id_to_object"
msgstr ""
msgid "seda_at_code_list_versions_tab"
msgstr "vocabulaires (CodeListVersions)"
msgid "seda_at_data_objects_tab"
msgstr "objets-données"
msgid "seda_at_main_tab"
msgstr "description"
msgid "seda_attachment"
msgstr ""
......@@ -6607,7 +6597,7 @@ msgid "seda_binary_data_object"
msgstr ""
msgid "seda_binary_data_object_object"
msgstr ""
msgstr "objet-données binaire"
msgctxt "SEDAArchiveTransfer"
msgid "seda_binary_data_object_object"
......@@ -7825,7 +7815,7 @@ msgid "seda_message_digest"
msgstr ""
msgid "seda_message_digest_algorithm_code_list_version"
msgstr "algorithmes de hachage"
msgstr "algorithmes d'empreinte"
msgctxt "SEDAArchiveTransfer"
msgid "seda_message_digest_algorithm_code_list_version"
......@@ -8039,7 +8029,7 @@ msgid "seda_physical_data_object"
msgstr ""
msgid "seda_physical_data_object_object"
msgstr ""
msgstr "objet-données physique"
msgctxt "SEDAArchiveTransfer"
msgid "seda_physical_data_object_object"
......
......@@ -14,6 +14,8 @@
# 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/>.
from cubicweb import tags, neg_role
from cubicweb.utils import UStringIO
from cubicweb.web.views import uicfg
pvs = uicfg.primaryview_section
......@@ -22,3 +24,81 @@ pvs.tag_subject_of(('*', 'container', '*'), 'hidden')
pvs.tag_object_of(('*', 'container', '*'), 'hidden')
afs.tag_subject_of(('*', 'container', '*'), 'main', 'hidden')
afs.tag_object_of(('*', 'container', '*'), 'main', 'hidden')
def add_relations_button(req, entity, msg, *rtype_roles, **extraurlparams):
"""Return an HTML dropdown button to add relations with `entity` as object"""
links = [relation_link(req, entity, rtype, role, **extraurlparams)
for rtype, role in rtype_roles]
links = [l for l in links if l]
if links:
# No links if user cannot add any relation.
return dropdown_button(req._(msg), *links)
def relation_link(req, entity, rtype, role, **extraurlparams):
"""Return a HTML link to add a `rtype` relation to `entity`"""
rschema = req.vreg.schema[rtype]
targets = rschema.targets(role=role)
assert len(targets) == 1, 'expecting a single {0} for relation {1}'.format(role, rschema)
etype = targets[0].type
if not has_rel_perm('add', entity, rtype, role, target_etype=etype):
return u''
linkto = '{rtype}:{eid}:{role}'.format(rtype=rtype, eid=entity.eid, role=neg_role(role))
urlparams = {'__linkto': linkto,
'__redirectpath': entity.rest_path()}
urlparams.update(extraurlparams)
msg = rtype if role == 'subject' else rtype + '_object'
return add_etype_link(req, etype, text=req.__(msg),
klass='', **urlparams)
def has_rel_perm(action, entity, rtype, role, target_etype=None, target_entity=None):
"""Return True if the user has the permission for `action` on the relation `rtype` where
`entity` is `role`. Either target entity type or target entity could also be specified.
"""
if role == 'subject':
kwargs = {'fromeid': entity.eid}
if target_entity is not None:
kwargs['toeid'] = target_entity.eid
else:
kwargs = {'toeid': entity.eid}
if target_entity is not None:
kwargs['fromeid'] = target_entity.eid
if target_entity is not None:
assert not target_etype
target_etype = target_entity.cw_etype
rdef = entity.e_schema.rdef(rtype, role, target_etype)
return rdef.has_perm(entity._cw, action, **kwargs)
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 dropdown_button(text, *links):
"""Return an HTML button with `text` and dropdown content from `links`.
"""
data = UStringIO()
w = data.write
w(u'<div class="btn-group pull-right clearfix">')
w(tags.button(text, klass='btn btn-success'))
w(tags.button(
tags.span(klass='caret'),
escapecontent=False,
klass='btn btn-success dropdown-toggle',
**{'data-toggle': 'dropdown', 'aria-expanded': 'false'}))
w(u'<ul class="dropdown-menu" role="menu">')
for link in links:
w(u'<li>{0}</li>'.format(link))
w(u'</ul>')
w(u'</div>')
return data.getvalue()
......@@ -17,13 +17,14 @@
from logilab.common.decorators import monkeypatch
from cubicweb.predicates import is_instance
from cubicweb import tags
from cubicweb.predicates import is_instance, match_kwargs, relation_possible
from cubicweb.view import EntityView
from cubicweb.web import formwidgets as fw
from cubicweb.web.views import tabs, uicfg, reledit
from cubes.seda.xsd import XSDMMapping
from cubes.seda.views import add_relations_button
_ = unicode
......@@ -48,21 +49,22 @@ XSDM_MAPPING = XSDMMapping('ArchiveTransfer')
class ArchiveTransferTabbedPrimaryView(tabs.TabbedPrimaryView):
__select__ = tabs.TabbedPrimaryView.__select__ & is_instance('SEDAArchiveTransfer')
tabs = [
_('seda.at.main_tab'),
_('seda.at.code_list_versions_tab'),
_('seda_at_main_tab'),
_('seda_at_code_list_versions_tab'),
_('seda_at_data_objects_tab'),
]
default_tab = 'seda.at.main_tab'
default_tab = 'seda_at_main_tab'
class ArchiveTransferMainTab(tabs.PrimaryTab):
"""Main tab for archive transfert (profiles)"""
__regid__ = 'seda.at.main_tab'
__regid__ = 'seda_at_main_tab'
__select__ = tabs.PrimaryTab.__select__ & is_instance('SEDAArchiveTransfer')
class ArchiveTransferCodeListVersionsTab(tabs.PrimaryTab):
"""Main tab for code list versions information of an archive transfert"""
__regid__ = 'seda.at.code_list_versions_tab'
__regid__ = 'seda_at_code_list_versions_tab'
__select__ = tabs.PrimaryTab.__select__ & is_instance('SEDAArchiveTransfer')
clv_mapping = XSDM_MAPPING[XSDM_MAPPING.element_by_name('CodeListVersions')]
......@@ -85,6 +87,70 @@ class ArchiveTransferCodeListVersionsTab(tabs.PrimaryTab):
rsection.tag_relation(relation, 'attributes')
class ArchiveTransferDataObjectsTab(tabs.TabsMixin, EntityView):
"""Main tab for code list versions information of an archive transfert"""
__regid__ = 'seda_at_data_objects_tab'
__select__ = tabs.PrimaryTab.__select__ & is_instance('SEDAArchiveTransfer')
rtype_roles = [
('seda_binary_data_object', 'object'),
('seda_physical_data_object', 'object'),
]
def entity_call(self, entity):
urlparams = {'__redirectparams': 'tab=' + self.__regid__}
button = add_relations_button(self._cw, entity, 'add',
*self.rtype_roles, **urlparams)
if button is not None:
# No button if user cannot add any relation.
self.w(button)
self.w(tags.div(klass='clearfix'))
for etype, rtype in [('SEDABinaryDataObject', 'seda_binary_data_object'),
('SEDAPhysicalDataObject', 'seda_physical_data_object')]:
rset = self._cw.execute('Any X, XI,XC WHERE P eid %(p)s, X {0} P, '
'X id XI, X user_cardinality XC'.format(rtype),
{'p': entity.eid})
if rset:
self.w('<h2>%s</h2>' % self._cw.__(etype + '_plural'))
subvid = 'seda.listitem'
self._cw.view('list', rset=rset, w=self.w, subvid=subvid, parent=entity,
tabid=self.__regid__)
class ListItemView(EntityView):
"""Extended 'oneline' view for entities related to an Agent, including link to remove the
relation.
"""
__regid__ = 'seda.listitem'
__select__ = EntityView.__select__ & match_kwargs('parent', 'tabid')
def entity_call(self, entity, parent, tabid):
entity.view('outofcontext', w=self.w)
entity.view('seda.xsdmeta', w=self.w)
if entity.cw_has_perm('update'):
self._cw.add_js(('cubicweb.ajax.js', 'cubes.seda.js'))
editurlparams = {
'__redirectpath': parent.rest_path(),
'__redirectparams': 'tab=' + tabid
}
self.w(u'<div class="pull-right">')
self.w(tags.a(title=self._cw.__('edit'), klass='icon-pencil',
href=entity.absolute_url(vid='edition', **editurlparams)))
self.w(tags.a(title=self._cw.__('delete'), klass='icon-trash',
href=entity.absolute_url(vid='deleteconf', **editurlparams)))
self.w(u'</div>')
class XSDMetaEntityView(EntityView):
__regid__ = 'seda.xsdmeta'
__select__ = relation_possible('user_cardinality')
def entity_call(self, entity):
self.w(u' <span class="cardinality">[%s]</span>' % entity.user_cardinality)
if entity.user_annotation:
self.w(u' <div class="description">%s</div>' % entity.user_annotation)
class LinkToConceptEntityView(EntityView):
"""Attribute view for SEDA relations linking to a concept through an intermediary entity holding
cardinalities / annotation
......@@ -99,9 +165,7 @@ class LinkToConceptEntityView(EntityView):
self._cw.view('csv', value_rset, w=self.w)
else:
self.wdata(self._cw.__('<not specified>'))
self.w(u' <span class="cardinality">[%s]</span>' % entity.user_cardinality)
if entity.user_annotation:
self.w(u' <div class="description">%s</div>' % entity.user_annotation)
entity.view('seda.xsdmeta', w=self.w)
self.w(u'</div>')
......
# copyright 2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr -- mailto:contact@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 data objects (BinaryDataObject / PhysicalDataObject)"""
from cubicweb.web import formwidgets as fw
from cubicweb.web.views import uicfg
from cubes.relationwidget import views as rwdg
_ = unicode
pvs = uicfg.primaryview_section
affk = uicfg.autoform_field_kwargs
pvdc = uicfg.primaryview_display_ctrl
rec = uicfg.reledit_ctrl
for etype in ('SEDABinaryDataObject', 'SEDAPhysicalDataObject'):
affk.set_fields_order(etype, ('id', 'user_cardinality', 'user_annotation', 'size'))
pvdc.set_fields_order(etype, ('id', 'user_cardinality', 'user_annotation', 'size'))
affk.set_field_kwargs('*', 'id', widget=fw.TextInput({'size': 80}))
for rtype in ('seda_mime_type_to', 'seda_encoding_to', 'seda_format_id_to', 'seda_algorithm'):
affk.tag_subject_of(('*', rtype, '*'),
{'widget': rwdg.RelationFacetWidget(dialog_options={'width': 800})})
......@@ -186,8 +186,10 @@ afs.tag_object_of(('*', 'seda_related_transfer_reference', '*'), 'main', 'inline
afs.tag_object_of(('*', 'seda_transfer_request_reply_identifier', '*'), 'main', 'inlined')
afs.tag_subject_of(('*', 'seda_archival_agency', '*'), 'main', 'attributes')
afs.tag_subject_of(('*', 'seda_transferring_agency', '*'), 'main', 'attributes')
afs.tag_object_of(('*', 'seda_binary_data_object', '*'), 'main', 'inlined')
afs.tag_object_of(('*', 'seda_physical_data_object', '*'), 'main', 'inlined')
afs.tag_subject_of(('*', 'seda_binary_data_object', '*'), 'main', 'hidden')
afs.tag_object_of(('*', 'seda_binary_data_object', '*'), 'main', 'hidden')
afs.tag_subject_of(('*', 'seda_physical_data_object', '*'), 'main', 'hidden')
afs.tag_object_of(('*', 'seda_physical_data_object', '*'), 'main', 'hidden')
afs.tag_object_of(('*', 'seda_service_level', '*'), 'main', 'inlined')
afs.tag_object_of(('*', 'seda_storage_rule', '*'), 'main', 'inlined')
afs.tag_object_of(('*', 'seda_appraisal_rule', '*'), 'main', 'inlined')
......
......@@ -87,7 +87,8 @@ class UICFGGenerator(object):
# the schema
if not mapping.final and mapping.subjtype != 'SEDAid':
if (mapping.rtype.endswith('code_list_version_from')
or mapping.rtype.endswith('code_list_version')):
or mapping.rtype.endswith('code_list_version')
or mapping.rtype.endswith('data_object')):
section = 'hidden'
role = mapping.composite or 'subject'
yield mapping.rtype, neg_role(role), section
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment