예제 #1
0
def edit_galley(request, galley_id, typeset_id=None, article_id=None):
    if typeset_id:
        typeset_task = get_object_or_404(models.TypesetTask,
                                         pk=typeset_id,
                                         accepted__isnull=False,
                                         completed__isnull=True)
        article = typeset_task.assignment.article
    else:
        typeset_task = None
        article = get_object_or_404(submission_models.Article,
                                    pk=article_id)
    galley = get_object_or_404(core_models.Galley,
                               pk=galley_id,
                               article=article)

    if request.POST:

        if 'delete' in request.POST:
            if typeset_task:
                logic.handle_delete_request(request, galley, typeset_task=typeset_task, page="edit")
                return redirect(reverse('do_typeset_task', kwargs={'typeset_id': typeset_task.pk}))
            else:
                logic.handle_delete_request(request, galley, article=article, page="pm_edit")
                return redirect(reverse('production_article', kwargs={'article_id': article.pk}))

        label = request.POST.get('label')
        if 'fixed-image-upload' in request.POST:
            for uploaded_file in request.FILES.getlist('image'):
                logic.save_galley_image(galley, request, uploaded_file, label, fixed=True)
        if 'image-upload' in request.POST:
            for uploaded_file in request.FILES.getlist('image'):
                logic.save_galley_image(galley, request, uploaded_file, label, fixed=False)
        elif 'css-upload' in request.POST:
            for uploaded_file in request.FILES.getlist('css'):
                logic.save_galley_css(galley, request, uploaded_file, 'galley-{0}.css'.format(galley.id), label)
        if 'galley-label' in request.POST:
            galley.label = request.POST.get('galley_label')
            galley.save()
        if 'replace-galley' in request.POST:
            logic.replace_galley_file(article, request, galley, request.FILES.get('galley'))

        if typeset_task:
            return redirect(reverse('edit_galley', kwargs={'typeset_id': typeset_id, 'galley_id': galley_id}))
        else:
            return redirect(reverse('pm_edit_galley', kwargs={'article_id': article.pk, 'galley_id': galley_id}))

    template = 'production/edit_galley.html'
    context = {
        'typeset_task': typeset_task,
        'galley': galley,
        'article': galley.article,
        'image_names': logic.get_image_names(galley)
    }

    return render(request, template, context)
예제 #2
0
def edit_galley(request, galley_id, typeset_id=None, article_id=None):
    """
    Allows a typesetter or editor to edit a Galley file.
    :param request: HttpRequest object
    :param galley_id: Galley object PK
    :param typeset_id: TypesetTask PK, optional
    :param article_id: Article PK, optiona
    :return: HttpRedirect or HttpResponse
    """
    return_url = request.GET.get('return', None)

    if typeset_id:
        typeset_task = get_object_or_404(
            models.TypesetTask,
            pk=typeset_id,
            assignment__article__journal=request.journal,
            accepted__isnull=False,
            completed__isnull=True,
        )
        article = typeset_task.assignment.article
    else:
        typeset_task = None
        article = get_object_or_404(
            submission_models.Article.allarticles,
            pk=article_id,
            journal=request.journal
        )
    galley = get_object_or_404(core_models.Galley,
                               pk=galley_id,
                               article=article)

    if request.POST:

        if 'delete' in request.POST:
            if typeset_task:
                logic.handle_delete_request(request, galley, typeset_task=typeset_task, page="edit")
                return redirect(reverse('do_typeset_task', kwargs={'typeset_id': typeset_task.pk}))
            else:
                logic.handle_delete_request(request, galley, article=article, page="pm_edit")
                if not return_url:
                    return redirect(reverse('production_article', kwargs={'article_id': article.pk}))
                else:
                    return redirect(return_url)

        label = request.POST.get('label')

        if 'fixed-image-upload' in request.POST:
            if request.POST.get('datafile') is not None:
                logic.use_data_file_as_galley_image(galley, request, label)
            for uploaded_file in request.FILES.getlist('image'):
                logic.save_galley_image(galley, request, uploaded_file, label, fixed=True)

        if 'image-upload' in request.POST:
            for uploaded_file in request.FILES.getlist('image'):
                logic.save_galley_image(galley, request, uploaded_file, label, fixed=False)

        elif 'css-upload' in request.POST:
            for uploaded_file in request.FILES.getlist('css'):
                logic.save_galley_css(galley, request, uploaded_file, 'galley-{0}.css'.format(galley.id), label)

        if 'galley-label' in request.POST:
            galley.label = request.POST.get('galley_label')
            galley.save()

        if 'replace-galley' in request.POST:
            logic.replace_galley_file(article, request, galley, request.FILES.get('galley'))

        if typeset_task:
            return redirect(reverse('edit_galley', kwargs={'typeset_id': typeset_id, 'galley_id': galley_id}))
        else:
            return_path = '?return={return_url}'.format(return_url=return_url) if return_url else ''
            url = reverse('pm_edit_galley', kwargs={'article_id': article.pk, 'galley_id': galley_id})
            redirect_url = '{url}{return_path}'.format(url=url, return_path=return_path)
            return redirect(redirect_url)

    template = 'production/edit_galley.html'
    context = {
        'typeset_task': typeset_task,
        'galley': galley,
        'article': galley.article,
        'image_names': logic.get_image_names(galley),
        'return_url': return_url,
        'data_files': article.data_figure_files.all(),
        'galley_images': galley.images.all()
    }

    return render(request, template, context)