Exemplo n.º 1
0
Arquivo: views.py Projeto: StuJ/rua-1
def author(request, book_id, author_id=None):

    book = get_object_or_404(core_models.Book, pk=book_id)

    if request.GET.get('delete'):
        author = get_object_or_404(
            core_models.Author, pk=request.GET.get('delete')
        )
        author.delete()

        return redirect(
            reverse('swiftsubmit_authors', kwargs={'book_id': book.id})
        )

    if author_id:
        if book.author.filter(pk=author_id).exists():
            author = get_object_or_404(core_models.Author, pk=author_id)
            author_form = submission_forms.AuthorForm(instance=author)
        else:
            return HttpResponseForbidden()
    else:
        author = None
        author_form = submission_forms.AuthorForm()

    if request.method == 'POST':
        if author:
            author_form = submission_forms.AuthorForm(
                request.POST,
                instance=author,
            )
        else:
            author_form = submission_forms.AuthorForm(request.POST)
        if author_form.is_valid():
            author = author_form.save(commit=False)

            if not author.sequence:
                author.sequence = 1

            author.save()

            if not author_id:
                book.author.add(author)

            return redirect(
                reverse('swiftsubmit_authors', kwargs={'book_id': book.id})
            )

        if 'next_step' in request.POST:
            return redirect(
                reverse('swiftsubmit_stage', kwargs={'book_id': book.id})
            )

    template = "swiftsubmit/author.html"
    context = {'author_form': author_form, 'book': book}

    return render(request, template, context)
Exemplo n.º 2
0
def submit_authors(request, article_id):
    """
    Allows the submitting author to add other authors to the submission.
    :param request: HttpRequest object
    :param article_id: Article PK
    :return: HttpRedirect or HttpResponse
    """
    article = get_object_or_404(models.Article, pk=article_id)

    if article.current_step < 2 and not request.user.is_staff:
        return redirect(reverse('submit_info', kwargs={'article_id': article_id}))

    form = forms.AuthorForm()
    error, modal = None, None

    if request.GET.get('add_self', None) == 'True':
        new_author = logic.add_self_as_author(request.user, article)
        messages.add_message(request, messages.SUCCESS, '%s added to the article' % new_author.full_name())
        return redirect(reverse('submit_authors', kwargs={'article_id': article_id}))

    if request.POST and 'add_author' in request.POST:
        form = forms.AuthorForm(request.POST)
        modal = 'author'

        author_exists = logic.check_author_exists(request.POST.get('email'))
        if author_exists:
            article.authors.add(author_exists)
            models.ArticleAuthorOrder.objects.get_or_create(article=article, author=author_exists)
            messages.add_message(request, messages.SUCCESS, '%s added to the article' % author_exists.full_name())
            return redirect(reverse('submit_authors', kwargs={'article_id': article_id}))
        else:
            if form.is_valid():
                new_author = form.save(commit=False)
                new_author.username = new_author.email
                new_author.set_password(utils_shared.generate_password())
                new_author.save()
                new_author.add_account_role(role_slug='author', journal=request.journal)
                article.authors.add(new_author)
                models.ArticleAuthorOrder.objects.get_or_create(article=article, author=new_author)
                messages.add_message(request, messages.SUCCESS, '%s added to the article' % new_author.full_name())

                return redirect(reverse('submit_authors', kwargs={'article_id': article_id}))

    elif request.POST and 'search_authors' in request.POST:
        search = request.POST.get('author_search_text', None)
        
        if not search:
            messages.add_message(
                request, 
                messages.WARNING, 
                'An empty search is not allowed.'
            )
        else:
            try:
                search_author = core_models.Account.objects.get(Q(email=search) | Q(orcid=search))
                article.authors.add(search_author)
                models.ArticleAuthorOrder.objects.get_or_create(article=article, author=search_author)
                messages.add_message(request, messages.SUCCESS, '%s added to the article' % search_author.full_name())
            except core_models.Account.DoesNotExist:
                messages.add_message(request, messages.WARNING, 'No author found with those details.')

    elif request.POST and 'main-author' in request.POST:
        correspondence_author = request.POST.get('main-author', None)

        if correspondence_author == 'None':
            messages.add_message(request, messages.WARNING, 'You must select a main author.')
        else:
            author = core_models.Account.objects.get(pk=correspondence_author)
            article.correspondence_author = author
            article.current_step = 3
            article.save()

            return redirect(reverse('submit_files', kwargs={'article_id': article_id}))

    elif request.POST and 'authors[]' in request.POST:
        author_pks = [int(pk) for pk in request.POST.getlist('authors[]')]
        for author in article.authors.all():
            order = author_pks.index(author.pk)
            author_order, c = models.ArticleAuthorOrder.objects.get_or_create(
                article=article,
                author=author,
                defaults={'order': order}
            )

            if not c:
                author_order.order = order
                author_order.save()

        return HttpResponse('Complete')

    template = 'admin/submission//submit_authors.html'
    context = {
        'error': error,
        'article': article,
        'form': form,
        'modal': modal,
    }

    return render(request, template, context)
Exemplo n.º 3
0
def article(request, article_id):
    article = get_object_or_404(models.Article,
                                pk=article_id,
                                journal=request.journal)
    article_form = forms.ArticleInfo(instance=article)
    author_form = forms.AuthorForm()
    pub_form = bc_forms.PublicationInfo(instance=article)
    remote_form = bc_forms.RemoteArticle(instance=article)
    modal = None

    if request.POST:
        if 'save_section_1' in request.POST:
            article_form = forms.ArticleInfo(request.POST, instance=article)

            if article_form.is_valid():
                article_form.save()
                return redirect(
                    reverse('bc_article', kwargs={'article_id': article.pk}))

        if 'save_section_2' in request.POST:
            correspondence_author = request.POST.get('main-author', None)

            if correspondence_author:
                author = core_models.Account.objects.get(
                    pk=correspondence_author)
                article.correspondence_author = author
                article.save()
                return redirect(
                    reverse('bc_article', kwargs={'article_id': article.pk}))

        if 'save_section_4' in request.POST:
            pub_form = bc_forms.PublicationInfo(request.POST, instance=article)

            if pub_form.is_valid():
                pub_form.save()
                if article.primary_issue:
                    article.primary_issue.articles.add(article)

                if article.date_published:
                    article.stage = models.STAGE_READY_FOR_PUBLICATION
                    article.save()
                return redirect(
                    reverse('bc_article', kwargs={'article_id': article.pk}))

        if 'save_section_5' in request.POST:
            remote_form = bc_forms.RemoteArticle(request.POST,
                                                 instance=article)

            if remote_form.is_valid():
                remote_form.save()
                return redirect(
                    reverse('bc_article', kwargs={'article_id': article.pk}))

        if 'xml' in request.POST:
            for uploaded_file in request.FILES.getlist('xml-file'):
                prod_logic.save_galley(article, request, uploaded_file, True,
                                       "XML", False)

        if 'pdf' in request.POST:
            for uploaded_file in request.FILES.getlist('pdf-file'):
                prod_logic.save_galley(article, request, uploaded_file, True,
                                       "PDF", False)

        if 'other' in request.POST:
            for uploaded_file in request.FILES.getlist('other-file'):
                prod_logic.save_galley(article, request, uploaded_file, True,
                                       "Other", True)

        if 'add_author' in request.POST:
            author_form = forms.AuthorForm(request.POST)
            modal = 'author'

            author_exists = logic.check_author_exists(
                request.POST.get('email'))
            if author_exists:
                article.authors.add(author_exists)
                messages.add_message(
                    request, messages.SUCCESS,
                    '%s added to the article' % author_exists.full_name())
                return redirect(
                    reverse('bc_article', kwargs={'article_id': article_id}))
            else:
                if author_form.is_valid():
                    new_author = author_form.save(commit=False)
                    new_author.username = new_author.email
                    new_author.set_password(shared.generate_password())
                    new_author.save()
                    new_author.add_account_role(role_slug='author',
                                                journal=request.journal)
                    article.authors.add(new_author)
                    messages.add_message(
                        request, messages.SUCCESS,
                        '%s added to the article' % new_author.full_name())

                    return redirect(
                        reverse('bc_article',
                                kwargs={'article_id': article_id}))

        if 'publish' in request.POST:
            if not article.stage == models.STAGE_PUBLISHED:
                id_logic.generate_crossref_doi_with_pattern(article)
                article.stage = models.STAGE_PUBLISHED
                article.snapshot_authors(article)
                article.save()

            if plugin_settings.IS_WORKFLOW_PLUGIN:
                workflow_kwargs = {
                    'handshake_url': 'bc_article',
                    'request': request,
                    'article': article,
                    'switch_stage': True
                }
                return event_logic.Events.raise_event(
                    event_logic.Events.ON_WORKFLOW_ELEMENT_COMPLETE,
                    task_object=article,
                    **workflow_kwargs)
            else:
                return redirect(reverse('bc_index'))

    template = 'back_content/article.html'
    context = {
        'article': article,
        'article_form': article_form,
        'form': author_form,
        'pub_form': pub_form,
        'galleys': prod_logic.get_all_galleys(article),
        'remote_form': remote_form,
        'modal': modal
    }

    return render(request, template, context)
Exemplo n.º 4
0
def article(request, article_id):
    article = get_object_or_404(models.Article,
                                pk=article_id,
                                journal=request.journal)
    article_form = bc_forms.ArticleInfo(instance=article)
    author_form = forms.AuthorForm()
    pub_form = bc_forms.PublicationInfo(instance=article)
    remote_form = bc_forms.RemoteArticle(instance=article)
    existing_author_form = bc_forms.ExistingAuthor()
    modal = None

    if request.POST:
        if 'save_section_1' in request.POST:
            article_form = bc_forms.ArticleInfo(request.POST, instance=article)

            if article_form.is_valid():
                article_form.save()
                return redirect(
                    reverse('bc_article', kwargs={'article_id': article.pk}))

        if 'save_section_2' in request.POST:
            correspondence_author = request.POST.get('main-author', None)

            if correspondence_author:
                author = core_models.Account.objects.get(
                    pk=correspondence_author)
                article.correspondence_author = author
                article.save()
                return redirect(
                    reverse('bc_article', kwargs={'article_id': article.pk}))

        if 'save_section_4' in request.POST:
            pub_form = bc_forms.PublicationInfo(request.POST, instance=article)

            if pub_form.is_valid():
                pub_form.save()
                if article.primary_issue:
                    article.primary_issue.articles.add(article)

                if article.date_published:
                    article.stage = models.STAGE_READY_FOR_PUBLICATION
                    article.save()
                return redirect(
                    reverse('bc_article', kwargs={'article_id': article.pk}))

        if 'save_section_5' in request.POST:
            remote_form = bc_forms.RemoteArticle(request.POST,
                                                 instance=article)

            if remote_form.is_valid():
                remote_form.save()
                return redirect(
                    reverse('bc_article', kwargs={'article_id': article.pk}))

        if 'file' in request.FILES:
            label = request.POST.get('label')
            for uploaded_file in request.FILES.getlist('file'):
                prod_logic.save_galley(
                    article,
                    request,
                    uploaded_file,
                    is_galley=True,
                    label=label,
                )

        if 'existing_author' in request.POST:
            existing_author_form = bc_forms.ExistingAuthor(request.POST)
            if existing_author_form.is_valid():
                author = existing_author_form.cleaned_data.get('author')
                article.authors.add(author)
                messages.add_message(
                    request,
                    messages.SUCCESS,
                    'Author added to the article.',
                )
                models.ArticleAuthorOrder.objects.get_or_create(
                    article=article,
                    author=author,
                    defaults={
                        'order': article.next_author_sort(),
                    })
                return redirect(
                    reverse('bc_article', kwargs={'article_id': article_id}))

        if 'add_author' in request.POST:
            author_form = forms.AuthorForm(request.POST)
            modal = 'author'

            author = logic.check_author_exists(request.POST.get('email'))
            if author:
                article.authors.add(author)
                messages.add_message(
                    request,
                    messages.SUCCESS,
                    '%s added to the article' % author.full_name(),
                )
            else:
                if author_form.is_valid():
                    author = author_form.save(commit=False)
                    author.username = author.email
                    author.set_password(shared.generate_password())
                    author.save()
                    author.add_account_role(
                        role_slug='author',
                        journal=request.journal,
                    )
                    article.authors.add(author)
                    messages.add_message(
                        request,
                        messages.SUCCESS,
                        '%s added to the article' % author.full_name(),
                    )

            models.ArticleAuthorOrder.objects.get_or_create(
                article=article,
                author=author,
                defaults={
                    'order': article.next_author_sort(),
                })

            return redirect(
                reverse('bc_article', kwargs={'article_id': article_id}))

        if 'publish' in request.POST:
            crossref_enabled = request.journal.get_setting(
                'Identifiers',
                'use_crossref',
            )
            if not article.stage == models.STAGE_PUBLISHED:
                if crossref_enabled:
                    id_logic.generate_crossref_doi_with_pattern(article)
                article.stage = models.STAGE_PUBLISHED
                article.snapshot_authors(article)
                article.save()

            if plugin_settings.IS_WORKFLOW_PLUGIN:
                workflow_kwargs = {
                    'handshake_url': 'bc_article',
                    'request': request,
                    'article': article,
                    'switch_stage': True
                }
                return event_logic.Events.raise_event(
                    event_logic.Events.ON_WORKFLOW_ELEMENT_COMPLETE,
                    task_object=article,
                    **workflow_kwargs)
            else:
                return redirect(reverse('bc_index'))

    template = 'back_content/article.html'
    context = {
        'article': article,
        'article_form': article_form,
        'form': author_form,
        'pub_form': pub_form,
        'galleys': prod_logic.get_all_galleys(article),
        'remote_form': remote_form,
        'existing_author_form': existing_author_form,
        'modal': modal
    }

    return render(request, template, context)
Exemplo n.º 5
0
def submit_authors(request, article_id):
    article = get_object_or_404(models.Article, pk=article_id)

    if article.current_step < 2 and not request.user.is_staff:
        return redirect(reverse('submit_info', kwargs={'article_id': article_id}))

    form = forms.AuthorForm()
    error, modal = None, None

    if request.GET.get('add_self', None) == 'True':
        new_author = logic.add_self_as_author(request.user, article)
        messages.add_message(request, messages.SUCCESS, '%s added to the article' % new_author.full_name())
        return redirect(reverse('submit_authors', kwargs={'article_id': article_id}))

    if request.POST and 'add_author' in request.POST:
        form = forms.AuthorForm(request.POST)
        modal = 'author'

        author_exists = logic.check_author_exists(request.POST.get('email'))
        if author_exists:
            article.authors.add(author_exists)
            messages.add_message(request, messages.SUCCESS, '%s added to the article' % author_exists.full_name())
            return redirect(reverse('submit_authors', kwargs={'article_id': article_id}))
        else:
            if form.is_valid():
                new_author = form.save(commit=False)
                new_author.username = new_author.email
                new_author.set_password(utils_shared.generate_password())
                new_author.save()
                new_author.add_account_role(role_slug='author', journal=request.journal)
                article.authors.add(new_author)
                messages.add_message(request, messages.SUCCESS, '%s added to the article' % new_author.full_name())

                return redirect(reverse('submit_authors', kwargs={'article_id': article_id}))

    elif request.POST and 'search_authors' in request.POST:
        search = request.POST.get('author_search_text')

        try:
            search_author = core_models.Account.objects.get(Q(email=search) | Q(orcid=search))
            article.authors.add(search_author)
            messages.add_message(request, messages.SUCCESS, '%s added to the article' % search_author.full_name())
        except core_models.Account.DoesNotExist:
            messages.add_message(request, messages.WARNING, 'No author found with those details.')

    elif request.POST:
        correspondence_author = request.POST.get('main-author', None)

        if correspondence_author == 'None':
            messages.add_message(request, messages.WARNING, 'You must select a main author.')
        else:
            author = core_models.Account.objects.get(pk=correspondence_author)
            article.correspondence_author = author
            article.current_step = 3
            article.save()

            return redirect(reverse('submit_files', kwargs={'article_id': article_id}))

    template = 'submission/submit_authors.html'
    context = {
        'error': error,
        'article': article,
        'form': form,
        'modal': modal,
    }

    return render(request, template, context)
Exemplo n.º 6
0
def preprints_authors(request, article_id):
    """
    Handles submission of new authors. Allows users to search for existing authors or add new ones.
    :param request: HttpRequest
    :param article_id: Article object PK
    :return: HttpRedirect or HttpResponse
    """
    article = get_object_or_404(submission_models.Article.preprints,
                                pk=article_id,
                                owner=request.user,
                                date_submitted__isnull=True)

    form = submission_forms.AuthorForm()
    error, modal = None, None

    # If someone is attempting to add a new author
    if request.POST and 'add_author' in request.POST:
        form = submission_forms.AuthorForm(request.POST)
        modal = 'author'

        # Check if the author exists, if they do, add them without creating a new account
        author_exists = logic.check_author_exists(request.POST.get('email'))
        if author_exists:
            article.authors.add(author_exists)
            submission_models.ArticleAuthorOrder.objects.get_or_create(
                article=article,
                author=author_exists,
                defaults={'order': article.next_author_sort()})
            messages.add_message(
                request, messages.SUCCESS,
                '%s added to the article' % author_exists.full_name())
            return redirect(
                reverse('preprints_authors', kwargs={'article_id':
                                                     article_id}))
        else:
            # Of the author isn't in the db, create a dummy account for them
            if form.is_valid():
                new_author = form.save(commit=False)
                new_author.username = new_author.email
                new_author.set_password(utils_shared.generate_password())
                new_author.save()
                article.authors.add(new_author)
                submission_models.ArticleAuthorOrder.objects.get_or_create(
                    article=article,
                    author=new_author,
                    defaults={'order': article.next_author_sort()})
                messages.add_message(
                    request, messages.SUCCESS,
                    '%s added to the article' % new_author.full_name())

                return redirect(
                    reverse('preprints_authors',
                            kwargs={'article_id': article_id}))

    # If a user is trying to search for author without using the modal
    elif request.POST and 'search_authors' in request.POST:
        search = request.POST.get('author_search_text')

        try:
            search_author = core_models.Account.objects.get(
                Q(email=search) | Q(orcid=search))
            article.authors.add(search_author)
            submission_models.ArticleAuthorOrder.objects.get_or_create(
                article=article,
                author=search_author,
                defaults={'order': article.next_author_sort()})
            messages.add_message(
                request, messages.SUCCESS,
                '%s added to the article' % search_author.full_name())
        except core_models.Account.DoesNotExist:
            messages.add_message(request, messages.WARNING,
                                 'No author found with those details.')

    # Handles posting from drag and drop.
    elif request.POST and 'authors[]' in request.POST:
        author_pks = [int(pk) for pk in request.POST.getlist('authors[]')]
        for author in article.authors.all():
            order = author_pks.index(author.pk)
            author_order, c = submission_models.ArticleAuthorOrder.objects.get_or_create(
                article=article, author=author, defaults={'order': order})

            if not c:
                author_order.order = order
                author_order.save()

        return HttpResponse('Complete')

    # Handle deleting an author
    elif request.POST and 'delete_author' in request.POST:
        author_id = request.POST.get('delete_author')
        author_to_delete = get_object_or_404(core_models.Account, pk=author_id)
        # Delete the author-article ordering
        submission_models.ArticleAuthorOrder.objects.filter(
            article=article, author=author_to_delete).delete()
        # Remove the author from the article
        article.authors.remove(author_to_delete)
        # Add message and redirect
        messages.add_message(request, messages.SUCCESS,
                             'Author removed from article.')
        return redirect(
            reverse('preprints_authors', kwargs={'article_id': article_id}))

    elif request.POST and 'save_continue' in request.POST:
        return redirect(
            reverse('preprints_files', kwargs={'article_id': article.pk}))

    template = 'preprints/authors.html'
    context = {
        'article': article,
        'form': form,
        'modal': modal,
    }

    return render(request, template, context)