示例#1
0
 def __call__(self):
     collectionID, datasetID = self.request.matchdict['collectionID'], self.request.matchdict['datasetID']
     principals = frozenset(self.request.effective_principals)
     collection = LabCASCollection.get(collectionID, principals)
     dataset = collection.datasets(datasetID)
     params = self.request.params
     if 'Download checked files' in params:
         # Download multiple files
         # FIXME: overly large archives cause browser to hang and we fail
         ids = [unicode(i[8:]) for i in params if i.startswith(u'include.') and params[i] == u'on']
         if len(ids) == 0:
             raise HTTPFound(self.request.url, message=u'No files were selected.')
         zipFileDesc, zipFileName = tempfile.mkstemp(u'.zip', u'labcas-')
         with zipfile.ZipFile(os.fdopen(zipFileDesc, 'w'), 'w', zipfile.ZIP_DEFLATED, allowZip64=True) as z:
             for i in ids:
                 f = dataset.files(i)
                 os.chdir(f.physicalLocation)
                 z.write(f.name)
         remover = threading.Timer(_tempFileRemovalTimeout, os.remove, (zipFileName,))
         remover.daemon = True
         remover.start()
         return FileResponse(zipFileName, self.request, content_type='application/zip')
     else:
         # View files
         return {
             'collection': collection,
             'dataset': dataset
         }
示例#2
0
 def __init__(self, request):
     principals = frozenset(request.effective_principals)
     collectionID = request.matchdict.get('collectionID', None)
     collection = LabCASCollection.get(collectionID, principals)
     if collection:
         self.__acl__ = [(Allow, principal, 'view') for principal in principals]
     else:
         self.__acl__ = [DENY_ALL]
示例#3
0
 def __call__(self):
     collectionID = self.request.matchdict['collectionID']
     principals = frozenset(self.request.effective_principals)
     collection = LabCASCollection.get(collectionID, principals)
     canUpload = any([i for i in principals if i.startswith('cn=')])
     return {
         'collection': collection,
         'canUpload': canUpload,
     }
示例#4
0
 def __call__(self):
     principals = frozenset(self.request.effective_principals)
     allCollections = LabCASCollection.get(principals=principals)
     collections, publicCollections = [], []
     for collection in allCollections:
         collections.append(collection)
         if collection.isPublic():
             publicCollections.append(collection)
     return {
         'collections': collections,
         'hasCollections': len(collections) > 0,
         'publicCollections': publicCollections,
         'hasPublicCollections': len(publicCollections) > 0
     }
示例#5
0
 def __call__(self):
     collectionID = self.request.matchdict['collectionID']
     datasetID = self.request.matchdict['datasetID']
     fileID = self.request.matchdict['fileID']
     principals = frozenset(self.request.effective_principals)
     collection = LabCASCollection.get(collectionID, principals)
     dataset = collection.datasets(datasetID)
     f = dataset.files(fileID)
     params = self.request.params
     if 'download' in params:
         # Download the file
         return FileResponse(os.path.join(f.physicalLocation, f.name), self.request,
             content_type=f.contentType.encode('utf-8'))
     else:
         # View the file metadata
         return {
             'collection': collection,
             'dataset': dataset,
             'f': f
         }