Commit 63bfcfe3 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

Add actions to download RNG or XSD of earlier SEDA versions

They should appear only if the relevant format is actually supported by the
profile.

Related to #15045341
parent a824bb9d5554
......@@ -22,6 +22,12 @@ class SEDAArchiveTransfer(generated.SEDAArchiveTransfer):
def dc_title(self):
return self.title
@property
def formats_compat(self):
if self.compat_list is None:
return set()
return set(self.compat_list.split(', '))
@property
def comments(self):
return self.reverse_seda_comment
......
......@@ -22,12 +22,12 @@ from cubicweb.view import EntityAdapter
from cubicweb.selectors import is_instance
ALL_FORMATS = frozenset(('SEDA 2', 'SEDA 1', 'SEDA 0.2'))
ALL_FORMATS = frozenset(('SEDA 2.0', 'SEDA 1.0', 'SEDA 0.2'))
Rule = namedtuple('Rule', ['impacted_formats', 'message', 'watch'])
RULES = {
'seda1_need_access_rule': Rule(
set(['SEDA 1']),
set(['SEDA 1.0']),
_("First level archive unit must have an associated access rule to be exportable "
"in SEDA 1. You may define it on the archive unit or as a default rule on the "
"transfer."),
......
......@@ -28,11 +28,11 @@ class CompatAnalyzerTC(CubicWebTC):
doctor = transfer.cw_adapt_to('ISEDACompatAnalyzer')
cnx.commit()
self.assertDiagnostic(doctor, ('SEDA 2', 'SEDA 1', 'SEDA 0.2'))
self.assertDiagnostic(doctor, ('SEDA 2.0', 'SEDA 1.0', 'SEDA 0.2'))
unit, unit_alt, unit_alt_seq = create_archive_unit(transfer)
transfer.cw_clear_all_caches()
cnx.commit()
self.assertDiagnostic(doctor, ('SEDA 2', 'SEDA 0.2'), 'seda1_need_access_rule')
self.assertDiagnostic(doctor, ('SEDA 2.0', 'SEDA 0.2'), 'seda1_need_access_rule')
def assertDiagnostic(self, doctor, expected_formats, *expected_rule_ids):
rule_ids = set(doctor.failing_rule_ids())
......
......@@ -15,17 +15,27 @@
# with this program. If not, see <http://www.gnu.org/licenses/>.
"""cubicweb-saem-ref views related to XSD download"""
from logilab.common.registry import objectify_predicate
from cubicweb import _
from cubicweb.predicates import is_instance, one_line_rset
from cubicweb.web import httpcache, action
from cubicweb.web.views import idownloadable
@objectify_predicate
def format_supported(cls, req, rset=None, entity=None, **kwargs):
if entity is None:
entity = rset.get_entity(0, 0)
return int(('SEDA ' + cls.seda_version) in entity.formats_compat)
class SEDADownloadAction(action.Action):
__abstract__ = True
__select__ = (action.Action.__select__
& one_line_rset()
& is_instance('SEDAArchiveTransfer'))
& is_instance('SEDAArchiveTransfer')
& format_supported())
category = 'moreactions'
# set those in concret classes
......@@ -43,7 +53,7 @@ class SEDA2DownloadRNGAction(SEDADownloadAction):
order = 100
seda_version = '2.0'
export_format = 'rng'
__regid__ = 'seda.export.{}.{}'.format(seda_version, export_format)
__regid__ = 'seda.export.{0}.{1}'.format(seda_version, export_format)
class SEDA2DownloadXSDAction(SEDADownloadAction):
......@@ -51,7 +61,39 @@ class SEDA2DownloadXSDAction(SEDADownloadAction):
order = 101
seda_version = '2.0'
export_format = 'xsd'
__regid__ = 'seda.export.{}.{}'.format(seda_version, export_format)
__regid__ = 'seda.export.{0}.{1}'.format(seda_version, export_format)
class SEDA1DownloadRNGAction(SEDADownloadAction):
title = _('SEDA 1.0 RNG export')
order = 102
seda_version = '1.0'
export_format = 'rng'
__regid__ = 'seda.export.{0}.{1}'.format(seda_version, export_format)
class SEDA1DownloadXSDAction(SEDADownloadAction):
title = _('SEDA 1.0 XSD export')
order = 103
seda_version = '1.0'
export_format = 'xsd'
__regid__ = 'seda.export.{0}.{1}'.format(seda_version, export_format)
class SEDA02DownloadRNGAction(SEDADownloadAction):
title = _('SEDA 0.2 RNG export')
order = 104
seda_version = '0.2'
export_format = 'rng'
__regid__ = 'seda.export.{0}.{1}'.format(seda_version, export_format)
class SEDA02DownloadXSDAction(SEDADownloadAction):
title = _('SEDA 0.2 XSD export')
order = 105
seda_version = '0.2'
export_format = 'xsd'
__regid__ = 'seda.export.{0}.{1}'.format(seda_version, export_format)
class SEDA2DownloadHTMLAction(SEDADownloadAction):
......@@ -59,7 +101,7 @@ class SEDA2DownloadHTMLAction(SEDADownloadAction):
order = 110
seda_version = '2.0'
export_format = 'html'
__regid__ = 'seda.export.{}.{}'.format(seda_version, export_format)
__regid__ = 'seda.export.{0}.{1}'.format(seda_version, export_format)
class SEDAExportView(idownloadable.DownloadView):
......@@ -72,8 +114,8 @@ class SEDAExportView(idownloadable.DownloadView):
@property
def seda_adapter_id(self):
return 'SEDA-{}.{}'.format(self._cw.form.get('version', '2.0'),
self._cw.form.get('format', 'rng').lower())
return 'SEDA-{0}.{1}'.format(self._cw.form.get('version', '2.0'),
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)
......
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