Commit 5554a664 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

Allow to specify export version/format as select context variable

This will ease usage of the export view programmatically (for interaction with e.g.
oaipmh).
parent c15f45eaad6a
......@@ -187,6 +187,15 @@ class FormatSupportedPredicateTC(CubicWebTC):
self.assertEqual(predicate(None, req, entity=transfer),
0)
del req.form['version']
self.assertEqual(predicate(fakecls(seda_version='1.0'), req, entity=transfer,
version='2.0'),
0)
self.assertEqual(predicate(None, req, entity=transfer, version='2.0'),
1)
self.assertEqual(predicate(None, req, entity=transfer, version='1.0'),
0)
class ArchiveTransferDiagnoseTabTC(CubicWebTC):
......
......@@ -30,7 +30,7 @@ def format_supported(cls, req, rset=None, entity=None, **kwargs):
"""
if entity is None:
entity = rset.get_entity(0, 0)
version = getattr(cls, 'seda_version', req.form.get('version', '2.0'))
version = getattr(cls, 'seda_version', kwargs.get('version', req.form.get('version', '2.0')))
return int(('SEDA ' + version) in entity.formats_compat)
......@@ -122,8 +122,9 @@ class SEDAExportView(SEDAExportViewMixin, idownloadable.DownloadView):
@property
def seda_adapter_id(self):
return 'SEDA-{0}.{1}'.format(self._cw.form.get('version', '2.0'),
self._cw.form.get('format', 'rng').lower())
return 'SEDA-{0}.{1}'.format(
self.cw_extra_kwargs.get('version', self._cw.form.get('version', '2.0')),
self.cw_extra_kwargs.get('format', self._cw.form.get('format', 'rng')).lower())
def set_request_content_type(self):
entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0)
......@@ -131,7 +132,7 @@ class SEDAExportView(SEDAExportViewMixin, idownloadable.DownloadView):
self._cw.set_content_type(adapter.content_type, filename=adapter.file_name,
encoding=adapter.encoding, disposition='attachment')
def call(self):
def call(self, **kwargs):
entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0)
adapter = entity.cw_adapt_to(self.seda_adapter_id)
self.w(adapter.dump())
......@@ -144,7 +145,7 @@ class SEDANonSupportedExportView(SEDAExportViewMixin, view.EntityView):
def entity_call(self, entity):
self.w(u'<p class="bg-error">')
version = self._cw.form['version']
version = self.cw_extra_kwargs.get('version', self._cw.form.get('version', '2.0'))
self.w(self._cw._('Export to SEDA version {0} is not possible.').format(version))
self.w(u'</p>')
self.w(u'<p>')
......
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