Esempio n. 1
0
 def delete(self, name):
     try:
         file = name.split('/')[-1]
         filename = file.split('.')[0]
         path = self.location.replace(file, '')
         directories, files = FILEMANAGER_STORAGE.listdir(path)
         if len(files) >= 1:
             for f in files:
                 if filename == f.split('.')[0]:
                     FILEMANAGER_STORAGE.delete(path + f)
                     
         if len(directories) >= 1:
             for d in directories:
                 if filename == d.split('.')[0]:
                     FILEMANAGER_STORAGE.delete(path + d)
         return True
         
     except Exception as e:
         if e.errno == 21:
             path = name.replace('file://', '')
             self.set_permission_to_dir(path, 775)
             shutil.rmtree(path)
             return True
         if e.errno == 1:
             path = name.replace('file://', '')
             self.set_permission_to_dir(path, 775)
             shutil.rmtree(path)
             return True
         return False
Esempio n. 2
0
 def upload_file(self, filedata):
     filename = FILEMANAGER_STORAGE.get_valid_name(filedata.name)
     filepath = os.path.join(self.path, filename)
     signals.filemanager_pre_upload.send(sender=self.__class__, filename=filename, path=self.path, filepath=filepath)
     FILEMANAGER_STORAGE.save(filepath, filedata)
     signals.filemanager_post_upload.send(sender=self.__class__, filename=filename, path=self.path, filepath=filepath)
     return filename
Esempio n. 3
0
    def create_directory(self, name):
        name = FILEMANAGER_STORAGE.get_valid_name(name)
        tmpfile = os.path.join(name, '.tmp')

        path = os.path.join(self.path, tmpfile)

        FILEMANAGER_STORAGE.save(path, ContentFile(''))
        FILEMANAGER_STORAGE.delete(path)
Esempio n. 4
0
 def _helper(name, filetype, extension):
     return {
         'filepath': os.path.join(self.path, name),
         'extension': extension,
         'filetype': filetype,
         'filename': name,
         'filedate': FILEMANAGER_STORAGE.modified_time(os.path.join(self.path, name)),
         'filesize': sizeof_fmt(FILEMANAGER_STORAGE.size(os.path.join(self.path, name))),
     }
Esempio n. 5
0
 def file_details(self):
     filename = self.path.rsplit('/', 1)[-1]
     return {
         'directory': os.path.dirname(self.path),
         'filepath': self.path,
         'filename': filename,
         'filesize': sizeof_fmt(FILEMANAGER_STORAGE.size(self.location)),
         'filedate': FILEMANAGER_STORAGE.modified_time(self.location),
         'fileurl': self.url,
     }
Esempio n. 6
0
    def directory_list(self, request, first_level):
        listing = []
        
        visible_extensions = ['shp', 'dbf', 'geotif', 'geotiff', 'tif', 'tiff', 'zip']
        
        if 'gvsigol_plugin_etl' in INSTALLED_APPS:
            visible_extensions = visible_extensions + ['xlsx', 'xls', 'csv']
        
        directories, files = FILEMANAGER_STORAGE.listdir(self.location)

        def _helper(name, filetype, extension):
            return {
                'filepath': os.path.join(self.path, name),
                'extension': extension,
                'filetype': filetype,
                'filename': name,
                'filedate': FILEMANAGER_STORAGE.modified_time(os.path.join(self.path, name)),
                'filesize': sizeof_fmt(FILEMANAGER_STORAGE.size(os.path.join(self.path, name))),
            }

        for directoryname in directories:
            '''if first_level:
                if request.user.is_superuser:
                    groups = core_utils.get_groups()
                else:
                    groups = core_utils.get_group_names_by_user(request.user)
                for g in groups:
                    if directoryname == g:
                        listing.append(_helper(directoryname, 'Directory', ''))
            else:
                listing.append(_helper(directoryname, 'Directory', ''))'''
            if request.user.is_superuser:
                listing.append(_helper(directoryname, 'Directory', ''))
            else: 
                if first_level:
                    groups = core_utils.get_group_names_by_user(request.user)
                    for g in groups:
                        if directoryname == g:
                            listing.append(_helper(directoryname, 'Directory', ''))
                else:
                    listing.append(_helper(directoryname, 'Directory', ''))

        for filename in files:
            parts = filename.split('.')
            if len(parts) > 1:
                extension = parts[1]
                #if extension.lower() in visible_extensions:
                #    listing.append(_helper(filename, 'File', extension))
                listing.append(_helper(filename, 'File', extension))

        return listing