示例#1
0
def proofing_article(request, article_id):
    article = get_object_or_404(submission_models.Article.objects.select_related('productionassignment'), pk=article_id,
                                journal=request.journal)
    proofreaders = logic.get_all_possible_proofers(journal=request.journal, article=article)
    form = forms.AssignProofreader()
    modal = None

    if request.POST:

        if 'new-round' in request.POST:
            logic.handle_closing_active_task(request, article)
            new_round = article.proofingassignment.add_new_proofing_round()
            messages.add_message(request, messages.SUCCESS, 'New round {0} added.'.format(new_round.number))
            return redirect(reverse('proofing_article', kwargs={'article_id': article.pk}))

        if 'new-proofreader' in request.POST:
            form = forms.AssignProofreader(request.POST)
            user = logic.get_user_from_post(request)
            galleys = logic.get_galleys_from_post(request)

            if not user:
                form.add_error(None, 'You must select a user.')

            if not galleys:
                form.add_error(None, 'You must select at least one Galley.')

            if form.is_valid():
                proofing_task = form.save(commit=False)
                proofing_task.proofreader = user
                proofing_task.round = article.proofingassignment.current_proofing_round()
                proofing_task.save()
                proofing_task.galleys_for_proofing.add(*galleys)
                return redirect(reverse('notify_proofreader', kwargs={'article_id': article.pk,
                                                                      'proofing_task_id': proofing_task.pk}))

            # Set the modal to open if this page is not redirected.
            modal = 'add_proofer'

    template = 'proofing/proofing_article.html'
    context = {
        'article': article,
        'proofreaders': proofreaders,
        'form': form,
        'modal': modal,
        'user': user if request.POST else None,
        'galleys': galleys if request.POST else None
    }

    return render(request, template, context)
示例#2
0
def proofing_article(request, article_id):
    """
    Displays the proofing control page, allows PM to add tasks, edit galleys and mark proofing as complete
    :param request: HttpRequest object
    :param article_id: Article object PK
    :return: HttpRedirect if POST or HttpResponse
    """
    article = get_object_or_404(
        submission_models.Article.objects.select_related(
            'productionassignment'),
        pk=article_id,
        journal=request.journal,
    )
    current_round = article.proofingassignment.current_proofing_round()
    proofreaders = logic.get_all_possible_proofers(
        journal=request.journal,
        article=article,
    )
    form = forms.AssignProofreader()
    modal = None

    if request.POST:

        if 'new-round' in request.POST:
            logic.handle_closing_active_task(request, article)
            new_round = article.proofingassignment.add_new_proofing_round()
            messages.add_message(
                request,
                messages.SUCCESS,
                'New round {0} added.'.format(new_round.number),
            )
            return redirect(
                reverse(
                    'proofing_article',
                    kwargs={'article_id': article.pk},
                ))

        if 'new-proofreader' in request.POST:

            if not current_round.can_add_another_proofreader(request.journal):
                messages.add_message(
                    request,
                    messages.WARNING,
                    'The number of proofreaders per round has been limited.'
                    ' You cannot add another proofreader in this round.',
                )
                return redirect(
                    reverse(
                        'proofing_article',
                        kwargs={'article_id': article.pk},
                    ))

            form = forms.AssignProofreader(request.POST)
            user = logic.get_user_from_post(request, article)
            galleys = logic.get_galleys_from_post(request)

            if not user:
                form.add_error(None, 'You must select a user.')

            if not galleys:
                form.add_error(None, 'You must select at least one Galley.')

            if form.is_valid():
                proofing_task = form.save(commit=False)
                proofing_task.proofreader = user
                proofing_task.round = current_round
                proofing_task.save()
                proofing_task.galleys_for_proofing.add(*galleys)
                return redirect(
                    reverse('notify_proofreader',
                            kwargs={
                                'article_id': article.pk,
                                'proofing_task_id': proofing_task.pk,
                            }))

            # Set the modal to open if this page is not redirected.
            modal = 'add_proofer'

    template = 'proofing/proofing_article.html'
    context = {
        'article': article,
        'proofreaders': proofreaders,
        'form': form,
        'modal': modal,
        'user': user if request.POST else None,
        'galleys': galleys if request.POST else None
    }

    return render(request, template, context)