Esempio n. 1
0
def manage_issues(request, issue_id=None, event=None):
    from core.logic import resize_and_crop
    issue_list = models.Issue.objects.filter(journal=request.journal)
    issue, modal, form = None, None, issue_forms.NewIssue()

    if issue_id:
        issue = get_object_or_404(models.Issue, pk=issue_id)
        form = issue_forms.NewIssue(instance=issue)
        if event == 'edit':
            modal = 'issue'
        if event == 'delete':
            modal = 'deleteme'
        if event == 'remove':
            article_id = request.GET.get('article')
            article = get_object_or_404(submission_models.Article, pk=article_id, pk__in=issue.article_pks)
            issue.articles.remove(article)
            return redirect(reverse('manage_issues_id', kwargs={'issue_id': issue.pk}))

    if request.POST:
        if 'make_current' in request.POST:
            issue = models.Issue.objects.get(id=request.POST['make_current'])
            request.journal.current_issue = issue
            request.journal.save()
            issue = None
            return redirect(reverse('manage_issues'))

        if 'delete_issue' in request.POST:
            issue.delete()
            return redirect(reverse('manage_issues'))

        if issue:
            form = issue_forms.NewIssue(request.POST, request.FILES, instance=issue)
        else:
            form = issue_forms.NewIssue(request.POST, request.FILES)

        if form.is_valid():
            save_issue = form.save(commit=False)
            save_issue.journal = request.journal
            save_issue.save()
            if request.FILES and save_issue.large_image:
                resize_and_crop(save_issue.large_image.path, [750, 324])
            if issue:
                return redirect(reverse('manage_issues_id', kwargs={'issue_id': issue.pk}))
            else:
                return redirect(reverse('manage_issues'))
        else:
            modal = 'issue'

    template = 'journal/manage/issues.html'
    context = {
        'issues': issue_list if not issue else [issue],
        'issue': issue,
        'form': form,
        'modal': modal,
    }

    return render(request, template, context)
Esempio n. 2
0
def handle_new_issue(request):
    form = issue_forms.NewIssue(request.POST, journal=request.journal)

    if form.is_valid():
        new_issue = form.save(commit=False)
        new_issue.journal = request.journal
        new_issue.save()
    else:
        new_issue = None
    return [form, 'issue', new_issue]
Esempio n. 3
0
def publish_article(request, article_id):
    """
    View allows user to set an article for publication
    :param request: request object
    :param article_id: Article PK
    :return: contextualised django template
    """
    article = get_object_or_404(
        submission_models.Article,
        Q(stage=submission_models.STAGE_READY_FOR_PUBLICATION)
        | Q(stage=submission_models.STAGE_PUBLISHED),
        pk=article_id,
        journal=request.journal)
    models.FixedPubCheckItems.objects.get_or_create(article=article)

    doi_data, doi = logic.get_doi_data(article)
    issues = request.journal.issues()
    new_issue_form = issue_forms.NewIssue()
    modal = request.GET.get('m', None)
    pubdate_errors = []

    if request.POST:
        if 'assign_issue' in request.POST:
            logic.handle_assign_issue(request, article, issues)
            return redirect('{0}?m=issue'.format(
                reverse('publish_article', kwargs={'article_id': article.pk})))

        if 'unassign_issue' in request.POST:
            logic.handle_unassign_issue(request, article, issues)
            return redirect('{0}?m=issue'.format(
                reverse('publish_article', kwargs={'article_id': article.pk})))

        if 'new_issue' in request.POST:
            new_issue_form, modal, new_issue = logic.handle_new_issue(request)
            if new_issue:
                return redirect('{0}?m=issue'.format(
                    reverse('publish_article',
                            kwargs={'article_id': article.pk})))

        if 'pubdate' in request.POST:
            date_set, pubdate_errors = logic.handle_set_pubdate(
                request, article)
            if not pubdate_errors:
                return redirect(
                    reverse('publish_article',
                            kwargs={'article_id': article.pk}))
            else:
                modal = 'pubdate'

        if 'author' in request.POST:
            logic.notify_author(request, article)
            return redirect(
                reverse('publish_article', kwargs={'article_id': article.pk}))

        if 'galley' in request.POST:
            logic.set_render_galley(request, article)
            return redirect(
                reverse('publish_article', kwargs={'article_id': article.pk}))

        if 'image' in request.POST or 'delete_image' in request.POST:
            logic.set_article_image(request, article)
            return redirect("{0}{1}".format(
                reverse('publish_article', kwargs={'article_id': article.pk}),
                "?m=article_image"))

        if 'publish' in request.POST:
            article.stage = submission_models.STAGE_PUBLISHED
            article.snapshot_authors(article)
            article.save()
            return redirect(
                reverse('publish_article', kwargs={'article_id': article.pk}))

    template = 'journal/publish_article.html'
    context = {
        'article': article,
        'doi_data': doi_data,
        'doi': doi,
        'issues': issues,
        'new_issue_form': new_issue_form,
        'modal': modal,
        'pubdate_errors': pubdate_errors,
        'notify_author_text': logic.get_notify_author_text(request, article)
    }

    return render(request, template, context)