[views] Remove download while register logic, used only for BrainomicsLocalizer, see #3316348
authorVincent Michel <vincent.michel@logilab.fr>
Mon, 25 Nov 2013 14:05:32 +0000
changeset 503 4797298ce571
parent 502 3b73b96326c8
child 504 42b8cabe6740
[views] Remove download while register logic, used only for BrainomicsLocalizer, see #3316348
site_cubicweb.py
views/download.py
--- a/site_cubicweb.py	Mon Nov 25 13:34:35 2013 +0000
+++ b/site_cubicweb.py	Mon Nov 25 14:05:32 2013 +0000
@@ -15,13 +15,3 @@
 #
 # 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/>.
-
-options = (
-    ('allow-anon-download',
-     {'type' : 'yn',
-      'default': False,
-      'help': 'allow anonymous users to download (e.g. zipview and csview) if set',
-      'group': 'brainomics',
-      'level': 1,
-      }),
-)
--- a/views/download.py	Mon Nov 25 13:34:35 2013 +0000
+++ b/views/download.py	Mon Nov 25 14:05:32 2013 +0000
@@ -52,7 +52,7 @@
     """
     fd, archive_filepath = tempfile.mkstemp()
     try:
-        noext_archivename = osp.splitext(DataZipAbstractView.archive_name)[0]
+        noext_archivename = osp.splitext(DataZipView.archive_name)[0]
         with closing(ZipFile(archive_filepath, "w", ZIP_DEFLATED, True)) as zip:
             for filename, subj, filepath in filepaths:
                 zip.write(filepath, '%s/%s/%s' % (noext_archivename, subj, filename))
@@ -64,22 +64,12 @@
         os.unlink(archive_filepath)
         raise
 
-def build_register_for_download(session):
-        ahref_login = u'<a href="%s">%s</a>' % (session.build_url('login'),
-                                                xml_escape(session._('sign in')))
-        ahref_register = u'<a href="%s">%s</a>' % (session.build_url('register'),
-                                                   xml_escape(session._('sign up')))
-        msg = session._('Please %(login)s or %(register)s before downloading these data.'
-                          % {'login': ahref_login, 'register': ahref_register})
-        return u'<h2>%s</h2>' % msg
-
 
 ###############################################################################
 ### ZIP VIEWS #################################################################
 ###############################################################################
-class DataZipAbstractView(EntityView):
+class DataZipView(EntityView):
     """Abstract base class for the zip view"""
-    __abstract__ = True
     __regid__ = 'data-zip'
     __select__ = EntityView.__select__ & is_instance(*ZIP_DOWNLOADABLE)
     templatable = False
@@ -89,10 +79,6 @@
     def set_request_content_type(self):
         self._cw.set_content_type('application/zip', filename=self.archive_name)
 
-
-class DataZipAuthenticatedView(DataZipAbstractView):
-    __select__ = DataZipAbstractView.__select__ & authenticated_user()
-
     def call(self):
         if not self.cw_rset:
             return
@@ -117,51 +103,3 @@
         finally:
             fileobj.close()
             os.unlink(archive_filepath)
-
-
-class DataZipAnonymousView(DataZipAbstractView):
-    __select__ = DataZipAbstractView.__select__ & anonymous_user()
-    binary = False
-    templatable = True
-
-    def call(self):
-        self.w(build_register_for_download(self._cw))
-
-
-###############################################################################
-### CSV VIEWS #################################################################
-###############################################################################
-class CsvExportAnonymousView(CSVRsetView):
-    __select__ = CSVRsetView.__select__ & anonymous_user() & is_instance(*CSV_DOWNLOADABLE)
-    binary = False
-    templatable = True
-
-    def call(self):
-        self.w(build_register_for_download(self._cw))
-
-
-###############################################################################
-### REGISTRATION CALLBACK #####################################################
-###############################################################################
-def registration_callback(vreg):
-    vreg.register_all(globals().values(), __name__, (DataZipAnonymousView, CsvExportAnonymousView))
-    if not vreg.config['allow-anon-download']:
-        # Register the anon view if do not allow anon download
-        vreg.register(DataZipAnonymousView)
-        # Change CSV views selector
-        from cubes.medicalexp.views.csvexport import (SubjectCSVView, ScoreDefinitionCSVView,
-                                                      GenericTestRunCSVView)
-        SubjectCSVView.__select__ = SubjectCSVView.__select__ & ~anonymous_user()
-        ScoreDefinitionCSVView.__select__ = ScoreDefinitionCSVView.__select__ & ~anonymous_user()
-        GenericTestRunCSVView.__select__ = GenericTestRunCSVView.__select__ & ~anonymous_user()
-        from cubes.genomics.views.csvexport import GenomicMeasureCSVView
-        GenomicMeasureCSVView = GenomicMeasureCSVView.__select__ & ~anonymous_user()
-        from cubes.neuroimaging.views.csvexport import ScanCSVView
-        ScanCSVView.__select__ = ScanCSVView.__select__ & ~anonymous_user()
-        from cubes.questionnaire.views.csvexport import QuestionnaireCSVView
-        QuestionnaireCSVView.__select__ = QuestionnaireCSVView.__select__ & ~anonymous_user()
-        # Register anonymous CSV export view
-        vreg.register(CsvExportAnonymousView)
-    else:
-        # Change the selector of DataZipAuthenticatedView
-        DataZipAuthenticatedView.__select__ = DataZipAbstractView.__select__