Preliminary refactoring of export actions
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 11 Oct 2016 14:03:39 +0200
changeset 1686 a824bb9d5554
parent 1685 51669dddb342
child 1687 84ac160473a8
Preliminary refactoring of export actions before adding new formats (1.0 / 0.2 XSD / RNG.
views/export.py
--- a/views/export.py	Thu Oct 13 14:27:04 2016 +0200
+++ b/views/export.py	Tue Oct 11 14:03:39 2016 +0200
@@ -21,38 +21,50 @@
 from cubicweb.web.views import idownloadable
 
 
-class SEDA2DownloadRNGAction(action.Action):
-    __regid__ = 'seda.seda2export.rng'
+class SEDADownloadAction(action.Action):
+    __abstract__ = True
     __select__ = (action.Action.__select__
                   & one_line_rset()
                   & is_instance('SEDAArchiveTransfer'))
     category = 'moreactions'
 
-    title = _('SEDA 2.0 RNG export')
-    export_format = 'rng'
-    order = 100
+    # set those in concret classes
+    __regid__ = title = seda_version = export_format = order = None
 
     def url(self):
         entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0)
-        return entity.absolute_url(vid='seda.seda2export', format=self.export_format)
+        return entity.absolute_url(vid='seda.seda2export',
+                                   version=self.seda_version,
+                                   format=self.export_format)
 
 
-class SEDA2DownloadXSDAction(SEDA2DownloadRNGAction):
-    __regid__ = 'seda.seda2export.xsd'
-    title = _('SEDA 2.0 XSD export')
-    export_format = 'xsd'
-    order = 101
+class SEDA2DownloadRNGAction(SEDADownloadAction):
+    title = _('SEDA 2.0 RNG export')
+    order = 100
+    seda_version = '2.0'
+    export_format = 'rng'
+    __regid__ = 'seda.export.{}.{}'.format(seda_version, export_format)
 
 
-class SEDA2DownloadHTMLAction(SEDA2DownloadRNGAction):
-    __regid__ = 'seda.seda2export.html'
-    title = _('HTML documentation')
-    export_format = 'html'
-    order = 110
+class SEDA2DownloadXSDAction(SEDADownloadAction):
+    title = _('SEDA 2.0 XSD export')
+    order = 101
+    seda_version = '2.0'
+    export_format = 'xsd'
+    __regid__ = 'seda.export.{}.{}'.format(seda_version, export_format)
 
 
-class SEDA2DownloadView(idownloadable.DownloadView):
-    """SEDA 2.0 download view"""
+class SEDA2DownloadHTMLAction(SEDADownloadAction):
+    title = _('HTML documentation')
+    order = 110
+    seda_version = '2.0'
+    export_format = 'html'
+    __regid__ = 'seda.export.{}.{}'.format(seda_version, export_format)
+
+
+class SEDAExportView(idownloadable.DownloadView):
+    """SEDA archive transfer export view, to download rng, html or xsd representation of a profile.
+    """
     __regid__ = 'seda.seda2export'
     __select__ = one_line_rset() & is_instance('SEDAArchiveTransfer')
 
@@ -60,7 +72,8 @@
 
     @property
     def seda_adapter_id(self):
-        return 'SEDA-2.0.' + self._cw.form.get('format', 'rng').lower()
+        return 'SEDA-{}.{}'.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)