def test_article_how_to_cite(self): issue = journal_models.Issue.objects.create(journal=self.journal_one) journal_models.Issue article = models.Article.objects.create( journal = self.journal_one, title="Test article: a test article", primary_issue=issue, date_published=dateparser.parse("2020-01-01"), page_numbers = "2-4" ) author = models.FrozenAuthor.objects.create( article=article, first_name="Mauro", middle_name="Middle", last_name="Sanchez", ) id_logic.generate_crossref_doi_with_pattern(article) expected = """ <p> Sanchez M. M., (2020) “Test article: a test article”, <i>Janeway JS</i> 1(1). doi: <a href="https://doi.org/{0}">https://doi.org/{0}</a></p> """.format(article.get_doi()) self.assertHTMLEqual(expected, article.how_to_cite)
def accept_article(self, stage=None): self.date_accepted = timezone.now() self.date_declined = None if stage: self.stage = stage else: self.stage = STAGE_ACCEPTED self.save() id_logic.generate_crossref_doi_with_pattern(self)
def handle(self, *args, **options): """Calls the Crossref registration options :param args: None :param options: Dictionary containing 'journal_code' :return: None """ journal = journal_models.Journal.objects.get(code=options.get('journal_code')) articles = submission_models.Article.objects.filter(journal=journal, date_published__isnull=False, ) for article in articles: if article.is_published: print('Handling article {0}'.format(article.pk)) try: identifier = article.get_identifier('doi', object=True) if identifier and identifier.is_doi: identifier.register() else: identifier = identifier_logic.generate_crossref_doi_with_pattern(article) identifier.register() except AttributeError as e: print('Error {0}'.format(e)) time.sleep(1)
def test_custom_article_how_to_cite(self): issue = journal_models.Issue.objects.create(journal=self.journal_one) journal_models.Issue article = models.Article.objects.create( journal = self.journal_one, title="Test article: a test article", primary_issue=issue, date_published=dateparser.parse("2020-01-01"), page_numbers = "2-4", custom_how_to_cite = "Banana", ) author = models.FrozenAuthor.objects.create( article=article, first_name="Mauro", middle_name="M", last_name="Sanchez", ) id_logic.generate_crossref_doi_with_pattern(article) expected = "Banana" self.assertHTMLEqual(expected, article.how_to_cite)
def handle(self, *args, **options): """Calls the Crossref registration options :param args: None :param options: Dictionary containing 'article_id' :return: None """ article = submission_models.Article.objects.get( pk=options['article_id']) identifier = article.get_identifier('doi', object=True) if identifier.is_doi: identifier.register() else: identifier = identifier_logic.generate_crossref_doi_with_pattern( article) identifier.register()
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)
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)