[views] Factor out entity label in Zip download view (closes #4627755)
authorVladimir Popescu <vladimir.popescu@logilab.fr>
Wed, 19 Nov 2014 12:25:26 +0100
changeset 1216 e9e0e8ed9656
parent 1186 a448cbbfe403
child 1217 cd2454cc5cf8
[views] Factor out entity label in Zip download view (closes #4627755) Thus, the label can be customized in application-specific cubes. Moreover, there can be several labels involved.
views/download.py
--- a/views/download.py	Wed Oct 15 12:24:24 2014 +0200
+++ b/views/download.py	Wed Nov 19 12:25:26 2014 +0100
@@ -60,10 +60,11 @@
         try:
             noext_archivename = osp.splitext(self.archive_name)[0]
             with closing(ZipFile(archive_filepath, "w", ZIP_DEFLATED, True)) as zip:
-                for filename, gmes_type, subj, _fileobj in filepaths:
-                    zip.writestr('%s/%s/%s/%s' % (noext_archivename, gmes_type,
-                                                  subj, filename),
-                                 _fileobj.read())
+                for filename, gmes_type, subjs, _fileobj in filepaths:
+                    for subj in subjs:
+                        zip.writestr('%s/%s/%s/%s' % (noext_archivename, gmes_type,
+                                                      subj, filename),
+                                     _fileobj.read())
             fileobj = os.fdopen(fd)
             fileobj.seek(0)
             return fileobj, archive_filepath
@@ -75,13 +76,16 @@
     def set_request_content_type(self):
         self._cw.set_content_type('application/zip', filename=self.archive_name)
 
+    def make_entity_labels(self, entity, prefix):
+        return ('{0}_{1}'.format(prefix, entity.concerns[0].identifier),)
+
     def call(self):
         if not self.cw_rset:
             return
         filepaths = set()
         prefix = self._cw._('Subject')
         for entity in self.cw_rset.entities():
-            subj = '{0}_{1}'.format(prefix, entity.concerns[0].identifier)
+            subj = self.make_entity_labels(entity, prefix)
             for _file in entity.results_files:
                 if _file.__regid__ == 'FileSet':
                     for _f in _file.file_entries: