Esempio n. 1
0
def preprints_subjects(request, subject_id=None):

    if subject_id:
        subject = get_object_or_404(models.Subject, pk=subject_id)
    else:
        subject = None

    form = forms.SubjectForm(instance=subject)

    if request.POST:

        if 'delete' in request.POST:
            utils_shared.clear_cache()
            return preprint_logic.handle_delete_subject(request)

        form = forms.SubjectForm(request.POST, instance=subject)

        if form.is_valid():
            form.save()
            utils_shared.clear_cache()
            return redirect(reverse('preprints_subjects'))

    template = 'admin/preprints/subjects.html'
    context = {
        'subjects': models.Subject.objects.all().prefetch_related('editors'),
        'form': form,
        'subject': subject,
        'active_users': core_models.Account.objects.all()
    }

    return render(request, template, context)
Esempio n. 2
0
def workflow_next(handshake_url, request, article, switch_stage=False):
    """
    Works out what the next workflow element should be so we can redirect the user there.
    :param handshake_url: Current workflow element's handshake url
    :param request: HttpRequest object
    :param article: Article object
    :return: HttpRedirect
    """

    workflow = models.Workflow.objects.get(journal=request.journal)
    workflow_elements = workflow.elements.all()

    if handshake_url == 'submit_review':
        set_stage(article)
        clear_cache()
        return redirect(reverse('core_dashboard'))

    current_element = workflow.elements.get(handshake_url=handshake_url)

    try:
        try:
            index = list(workflow_elements).index(current_element) + 1
            next_element = workflow_elements[index]
        except IndexError:
            # An index error will occur here when the workflow is complete
            return redirect(
                reverse('manage_archive_article',
                        kwargs={'article_id': article.pk}))

        if switch_stage:
            log_stage_change(article, next_element)
            clear_cache()
            article.stage = next_element.stage
            article.save()

        try:
            response = redirect(
                reverse(
                    next_element.handshake_url,
                    kwargs={'article_id': article.pk},
                ))
        except NoReverseMatch:
            response = redirect(reverse(next_element.handshake_url))

    except Exception as e:
        logger.exception(e)
        response = redirect(reverse('core_dashboard'))

    if response.status_code == 302:
        response = redirect(reverse('core_dashboard'))

    messages.add_message(
        request,
        messages.SUCCESS,
        '%s stage completed for article: %d'
        '' % (current_element.stage, article.pk),
    )

    return response
Esempio n. 3
0
def move_to_stage(from_stage, to_stage, article):
    stages_to_process = stages_in_between(from_stage, to_stage, article)

    # TODO: Loop through the stages and call a function to reverse process
    # the stage.

    for stage in stages_to_process:
        if stage == submissions_models.STAGE_READY_FOR_PUBLICATION:
            article.date_published = None
            article.stage = submissions_models.STAGE_READY_FOR_PUBLICATION
            reset_prepub_checklist(article)

        elif stage == submissions_models.STAGE_PROOFING:
            article.stage = submissions_models.STAGE_PROOFING
            reopen_proofing_assignments(article)

        elif stage == submissions_models.STAGE_TYPESETTING:
            article.stage = submissions_models.STAGE_TYPESETTING
            reopen_production_assignments(article)

        elif stage == submissions_models.STAGE_EDITOR_COPYEDITING:
            article.stage = submissions_models.STAGE_EDITOR_COPYEDITING

        elif stage == submissions_models.STAGE_UNASSIGNED:
            article.stage = submissions_models.STAGE_UNDER_REVIEW
            article.date_accepted = None
            article.date_declined = None

        else:
            pass
            # TODO: No stage found, likely a plugin, find it?

    article.save()
    stages_to_delete = drop_workflow_log_entries(article, stages_to_process)
    clear_cache()

    return stages_to_delete
Esempio n. 4
0
def reset_article_url_cache(sender, instance, created, **kwargs):
    shared.clear_cache()