def dispatch(self, request, *args, **kwargs):
        self.download_type = self.kwargs['download_type']
        self.download_class = get_download_class(self.download_type)
        if self.download_class is None:
            raise Http404

        return super().dispatch(request, *args, **kwargs)
    def get(self, request, *args, **kwargs):
        download_type = self.kwargs['download_type']
        self.item_ids = self.get_item_id_list()

        if request.user.is_authenticated:
            user_id = request.user.id
        else:
            user_id = None

        if self.options_session_key in request.session:
            options = request.session[self.options_session_key]
        else:
            # Default option on the downloader class will be used
            options = {}

        downloader_class = get_download_class(download_type)

        if not downloader_class:
            raise Http404

        # Add the current host url to the options to make the relative links clickable:
        options.update(
            {"CURRENT_HOST": request.scheme + "://" + request.get_host()})

        res = download.delay(download_type, self.item_ids, user_id, options)

        request.session['download_result_id'] = res.id
        # res.forget()
        self.download_type = download_type
        self.download_class = downloader_class
        self.taskid = res.id
        return super().get(request, *args, **kwargs)
def download(download_type: str,
             item_ids: List[int],
             user_id: int,
             options={}) -> Optional[str]:
    dl_class = get_download_class(download_type)

    if dl_class is not None:
        # Instantiate downloader class
        downloader = dl_class(item_ids, user_id, options)
        # Get file url
        return downloader.download()

    raise LookupError('Requested Downloader class could not be found')