Add actions to download RNG or XSD of earlier SEDA versions
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 11 Oct 2016 16:46:35 +0200
changeset 1687 84ac160473a8
parent 1686 a824bb9d5554
child 1688 0f3d38ffd42d
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
entities/custom.py
entities/diag.py
test/test_diag.py
views/export.py
--- a/entities/custom.py	Tue Oct 11 14:03:39 2016 +0200
+++ b/entities/custom.py	Tue Oct 11 16:46:35 2016 +0200
@@ -23,6 +23,12 @@
         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
 
--- a/entities/diag.py	Tue Oct 11 14:03:39 2016 +0200
+++ b/entities/diag.py	Tue Oct 11 16:46:35 2016 +0200
@@ -22,12 +22,12 @@
 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."),
--- a/test/test_diag.py	Tue Oct 11 14:03:39 2016 +0200
+++ b/test/test_diag.py	Tue Oct 11 16:46:35 2016 +0200
@@ -28,11 +28,11 @@
             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())
--- a/views/export.py	Tue Oct 11 14:03:39 2016 +0200
+++ b/views/export.py	Tue Oct 11 16:46:35 2016 +0200
@@ -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 @@
     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 @@
     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 @@
     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 @@
 
     @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)