def get_file(self): filename, filepath = self.get_path() if not os.path.isfile(filepath): raise FileNotFound('File "{0}" does not exists'.format(filepath)) try: zippedFile = get_zip_from_path(filepath, filename, self.kwargs.get('name')) except Exception as e: raise FileNotFound('File "{0}" does not exists'.format(filepath)) return zippedFile
def get_file(self): """Return :class:`~django.db.models.fields.files.FieldFile` instance. The file wrapper is model's field specified as :attr:`file_field`. It is typically a :class:`~django.db.models.fields.files.FieldFile` or subclass. Raises :class:`~django_downloadview.exceptions.FileNotFound` if instance's field is empty. Additional attributes are set on the file wrapper if :attr:`encoding`, :attr:`mime_type`, :attr:`charset`, :attr:`modification_time` or :attr:`size` are configured. """ file_instance = getattr(self.object, self.file_field) if not file_instance: raise FileNotFound( f'Field="{self.file_field}" on object="{self.object}" is empty' ) for field in ("encoding", "mime_type", "charset", "modification_time", "size"): model_field = getattr(self, "%s_field" % field, False) if model_field: value = getattr(self.object, model_field) setattr(file_instance, field, value) return file_instance
def get_file(self): type = self.kwargs.get('type') path = self.kwargs.get('path') file = '%s/%s' % (type, path) full_path = '%s/%s' % (settings.MEDIA_ROOT, file) if not os.path.isfile(full_path): raise FileNotFound('File "{0}" does not exists'.format(file)) return File(file=open(full_path, 'rb'))
def get_file(self): """Use path to return wrapper around file to serve.""" filename = self.get_path() if not os.path.isfile(filename): raise FileNotFound('File "{0}" does not exists'.format(filename)) return File(open(filename, 'rb'))
def get_file(self): """Use path to return wrapper around file to serve.""" filename = self.get_path() if not os.path.isfile(filename): raise FileNotFound(f'File "{filename}" does not exists') return File(open(filename, "rb"))
def get_file(self): filepath = self.get_path() if not os.path.isfile(filepath): raise FileNotFound('File "{0}" does not exists'.format(filepath)) return File(file=open(filepath, 'rb'), name=self.kwargs.get('name'))