示例#1
0
def serve_article_file(request, identifier_type, identifier, file_id):
    """ Serves an article file.

    :param request: the request associated with this call
    :param identifier_type: the identifier type for the article
    :param identifier: the identifier for the article
    :param file_id: the file ID to serve
    :return: a streaming response of the requested file or 404
    """

    article_object = submission_models.Article.get_article(
        request.journal, identifier_type, identifier)

    try:
        if file_id != "None":
            file_object = get_object_or_404(core_models.File, pk=file_id)
            return files.serve_file(request, file_object, article_object)
        else:
            raise Http404
    except Http404:
        if file_id != "None":
            raise Http404

        # if we are here then the carousel is requesting an image for an article that doesn't exist
        # return a default image instead

        return redirect(static('common/img/default_carousel/carousel1.png'))
示例#2
0
def proofing_download(request, proofing_task_id, file_id):
    proofing_task = get_object_or_404(models.ProofingTask, pk=proofing_task_id)
    file = get_object_or_404(core_models.File, pk=file_id)

    if file in proofing_task.galley_files():
        return files.serve_file(request, file, proofing_task.round.assignment.article)
    else:
        messages.add_message(request, messages.WARNING, 'Requested file is not a galley for proofing')
        return redirect(request.META.get('HTTP_REFERER'))
示例#3
0
def download_galley(request, article_id, galley_id):
    """ Serves a galley file for an article

    :param request: an HttpRequest object
    :param article_id: an Article object PK
    :param galley_id: an Galley object PK
    :return: a streaming response of the requested file or a 404.
    """
    article = get_object_or_404(submission_models.Article, pk=article_id)
    galley = get_object_or_404(core_models.Galley, pk=galley_id)

    store_article_access(request, article, 'download', galley_type=galley.file.label)
    return files.serve_file(request, galley.file, article)
示例#4
0
def article_figure(request, article_id, galley_id, file_name):
    """ Returns a galley article figure

    :param request: an HttpRequest object
    :param article_id: an Article object PK
    :param galley_id: an Galley object PK
    :param file_name: an File object name
    :return: a streaming file response or a 404 if not found
    """
    figure_article = get_object_or_404(submission_models.Article, pk=article_id)
    galley = get_object_or_404(core_models.Galley, pk=galley_id, article=figure_article)

    figure = get_object_or_404(galley.images, original_filename=file_name)
    return files.serve_file(request, figure, figure_article)
示例#5
0
def attempt_to_serve_file(request, copyedit):
    if request.GET.get('file_id', None):
        file_id = request.GET.get('file_id')
        _type = request.GET.get('type', None)
        try:
            if _type == 'for_copyedit':
                file = copyedit.files_for_copyediting.get(pk=file_id)
            else:
                file = copyedit.copyeditor_files.get(pk=file_id)
            return files.serve_file(request, file, copyedit.article)
        except core_models.File.DoesNotExist:
            messages.add_message(request, messages.WARNING,
                                 'File does not exist.')

        raise Http404
示例#6
0
def copyeditor_file(request, copyedit_id, file_id):
    """ Serves an article file.
    :param request: the request associated with this call
    :param copyedit_id: the CopyeditAssignment id.
    :param file_id: the file ID to serve
    :return: a streaming response of the requested file or 404
    """
    copyedit_assignment = models.CopyeditAssignment.objects.get(
        Q(copyeditor_completed__isnull=True) | Q(copyedit_reopened__isnull=False),
        copyedit_reopened_complete__isnull=True,
        pk=copyedit_id,
        decision='accept')
    article_object = copyedit_assignment.article

    file_object = core_models.File.objects.get(pk=file_id)

    if not file_object:
        raise Http404()

    return files.serve_file(request, file_object, article_object)
示例#7
0
def serve_article_file(request, article_id, file_id):
    article = get_object_or_404(submission_models.Article, pk=article_id)
    file = get_object_or_404(core_models.File, pk=file_id)

    response = files.serve_file(request, file, article)
    return response