Exemplo n.º 1
0
def do_typeset_task(request, typeset_id):
    """
    Displays a form for completing typeset tasks
    :param request: HttpRequest object
    :param typeset_id: TypesetTask object PK
    :return: HttpResponse or HttpRedirect
    """
    typeset_task = get_object_or_404(
        models.TypesetTask,
        pk=typeset_id,
        accepted__isnull=False,
        completed__isnull=True,
        assignment__article__journal=request.journal,
    )

    article = typeset_task.assignment.article
    galleys = core_models.Galley.objects.filter(article=article)
    form = forms.TypesetterNote(instance=typeset_task)

    if request.POST:

        if 'complete' in request.POST:
            form = forms.TypesetterNote(request.POST, instance=typeset_task)
            if form.is_valid():
                task = form.save()
                task.completed = timezone.now()
                task.save()

                kwargs = {
                    'typeset_task': typeset_task,
                    'request': request,
                }
                event_logic.Events.raise_event(
                    event_logic.Events.ON_TYPESET_COMPLETE,
                    **kwargs,
                )

                messages.add_message(
                    request,
                    messages.INFO,
                    'Typeset assignment complete.',
                )
                return redirect(reverse('typesetter_requests'))

        new_galley = None
        if 'file' in request.FILES:
            label = request.POST.get('label')
            for uploaded_file in request.FILES.getlist('file'):
                try:
                    new_galley = logic.save_galley(
                        article,
                        request,
                        uploaded_file,
                        True,
                        label=label,
                    )
                except UnicodeDecodeError:
                    messages.add_message(request, messages.ERROR,
                                         "Uploaded file is not UTF-8 encoded")

        if 'source' in request.POST:
            for uploaded_file in request.FILES.getlist('source-file'):
                logic.save_source_file(
                    article,
                    request,
                    uploaded_file,
                )

        if new_galley:
            typeset_task.galleys_loaded.add(new_galley.file)

        if not request.FILES:
            messages.add_message(request, messages.WARNING,
                                 'No files uploaded.')

        return redirect(
            reverse('do_typeset_task', kwargs={'typeset_id': typeset_task.pk}))

    manuscripts = article.manuscript_files.filter(is_galley=False)
    data_files = article.data_figure_files.filter(is_galley=False)
    copyedit_files = logic.get_copyedit_files(article)

    template = 'production/typeset_task.html'
    context = {
        'typeset_task': typeset_task,
        'article': article,
        'manuscripts': manuscripts,
        'data_files': data_files,
        'production_assignment': typeset_task.assignment,
        'copyedit_files': copyedit_files,
        'galleys': galleys,
        'form': form,
    }

    return render(request, template, context)
Exemplo n.º 2
0
def production_article(request, article_id):
    """
    Displays typesetting tasks, Galleys and allows new Galleys to be uploaded.
    :param request: HttpRequest object
    :param article_id: Article object PK
    :return: HttpResponse object
    """
    article = get_object_or_404(
        submission_models.Article,
        pk=article_id,
        journal=request.journal,
    )

    try:
        production_assignment = models.ProductionAssignment.objects.get(
            article=article)
    except models.ProductionAssignment.DoesNotExist:
        return redirect(
            reverse(
                'production_non_workflow_assign',
                kwargs={'article_id': article.pk},
            ))

    galleys = logic.get_all_galleys(production_assignment.article)

    if request.POST:
        try:
            if 'file' in request.FILES:
                label = request.POST.get('label', None)
                for uploaded_file in request.FILES.getlist('file'):
                    logic.save_galley(
                        article,
                        request,
                        uploaded_file,
                        True,
                        label=label,
                    )
        except TypeError as exc:
            messages.add_message(request, messages.ERROR, str(exc))
        except UnicodeDecodeError:
            messages.add_message(request, messages.ERROR,
                                 "Uploaded file is not UTF-8 encoded")

        if 'prod' in request.POST:
            for uploaded_file in request.FILES.getlist('prod-file'):
                logic.save_prod_file(
                    article,
                    request,
                    uploaded_file,
                    'Production Ready File',
                )

        if 'supp' in request.POST:
            label = request.POST.get('label', 'Supplementary File')
            for uploaded_file in request.FILES.getlist('supp-file'):
                logic.save_supp_file(article, request, uploaded_file, label)

        if 'source' in request.POST:
            for uploaded_file in request.FILES.getlist('source-file'):
                logic.save_source_file(
                    article,
                    request,
                    uploaded_file,
                )
        if not request.FILES:
            messages.add_message(request, messages.WARNING,
                                 'No files uploaded.')

        return redirect(
            reverse('production_article', kwargs={'article_id': article.pk}))

    manuscripts = article.manuscript_files.filter(is_galley=False)
    data_files = article.data_figure_files.filter(is_galley=False)
    copyedit_files = logic.get_copyedit_files(article)

    template = 'production/assigned_article.html'
    context = {
        'article':
        article,
        'manuscripts':
        manuscripts,
        'data_files':
        data_files,
        'production_assignment':
        production_assignment,
        'copyedit_files':
        copyedit_files,
        'typeset_tasks':
        production_assignment.typesettask_set.all().order_by('-id'),
        'galleys':
        galleys,
        'complete_message':
        logic.get_complete_template(request, article, production_assignment)
    }

    return render(request, template, context)