Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .flake8

This file was deleted.

11 changes: 7 additions & 4 deletions jdh/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
https://docs.djangoproject.com/en/3.1/ref/settings/
"""

from pathlib import Path
import os
import sys
from pathlib import Path

from .base import get_env_variable

# Build paths inside the project like this: BASE_DIR / 'subdir'.
Expand Down Expand Up @@ -292,6 +293,8 @@
FACEBOOK_JDH_PAGE_ID = get_env_variable("FACEBOOK_JDH_PAGE_ID")
FACEBOOK_JDH_ACCESS_TOKEN = get_env_variable("FACEBOOK_JDH_ACCESS_TOKEN")

#OJS API
OJS_API_KEY_TOKEN= get_env_variable("OJS_API_KEY_TOKEN", "default")
OJS_API_URL = get_env_variable("OJS_API_URL", "http://ojs.journalofdigitalhistory.org")
# OJS API
OJS_API_KEY_TOKEN = get_env_variable("OJS_API_KEY_TOKEN", "default")
OJS_API_URL = get_env_variable("OJS_API_URL", "http://ojs.journalofdigitalhistory.org")

COPY_EDITOR_ADDRESS = get_env_variable("COPY_EDITOR_ADDRESS", "")
4 changes: 2 additions & 2 deletions jdhapi/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
from .tasks import (
save_article_fingerprint,
save_article_specific_content,
save_citation,
save_libraries,
save_references,
)
from .utils.articles import save_citation
from import_export.admin import ExportActionMixin
from django.utils.html import format_html

Expand All @@ -37,7 +37,7 @@ def save_notebook_specific_cell(modeladmin, request, queryset):

def save_article_citation(modeladmin, request, queryset):
for article in queryset:
save_citation.delay(article_id=article.pk)
save_citation(article_id=article.pk)


save_article_citation.short_description = "3: Generate citation"
Expand Down
14 changes: 10 additions & 4 deletions jdhapi/models/article.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging

from django.db import models
from model_utils import FieldTracker


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -35,7 +35,6 @@ class Article(models.Model):
Methods:
get_kernel_language(): Returns the kernel language based on the 'tool' tag.
__str__(): Returns the title of the abstract.
send_email_if_peer_review(): Sends an email with a PDF attachment if the article is in peer review status.
"""

class Status(models.TextChoices):
Expand All @@ -55,7 +54,14 @@ class Status(models.TextChoices):
"DESIGN_REVIEW",
"Design review",
)
PUBLISHED = "PUBLISHED", "Published"
COPY_EDITING = (
"COPY_EDITING",
"Copy editing",
)
PUBLISHED = (
"PUBLISHED",
"Published",
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add SOCIAL_MEDIA and ARCHIVED.


class CopyrightType(models.TextChoices):
DRAFT = (
Expand Down Expand Up @@ -130,7 +136,7 @@ class RepositoryType(models.TextChoices):
blank=True,
null=True,
help_text="Url to find here https://data.journalofdigitalhistory.org/",
) # New field for Dataverse URL
)
publication_date = models.DateTimeField(blank=True, null=True)
copyright_type = models.CharField(
max_length=15,
Expand Down
6 changes: 2 additions & 4 deletions jdhapi/signals.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import requests
import logging
from django.core.exceptions import ValidationError
from django.db.models.signals import post_save, pre_save
from django.db.models.signals import pre_save
from django.dispatch import receiver

from jdhapi.models import Article
from jdhapi.utils.articles import convert_string_to_base64
from jdhapi.utils.run_github_action import trigger_workflow


@receiver(pre_save, sender=Article)
Expand Down Expand Up @@ -37,5 +36,4 @@ def check_notebook_url(notebook_url, repository_url):
if instance.notebook_url and check_notebook_url(
instance.notebook_url, instance.repository_url
):

raise ValidationError("Notebook url is not correct")
13 changes: 0 additions & 13 deletions jdhapi/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from jdhapi.utils.articles import (
get_notebook_stats,
get_notebook_specifics_tags,
get_citation,
generate_tags,
generate_narrative_tags,
get_notebook_references_fulltext,
Expand Down Expand Up @@ -75,18 +74,6 @@ def save_article_specific_content(article_id):
article.save()


@shared_task
def save_citation(article_id):
logger.info(f"save_article_citation:{article_id}")
try:
article = Article.objects.get(pk=article_id)
except Article.DoesNotExist:
logger.error(f"save_article_citation:{article_id} not found")
citation = get_citation(raw_url=article.notebook_ipython_url, article=article)
article.citation = citation
article.save()


@shared_task
def save_libraries(article_id):
logger.info(f"save_article_libraries:{article_id}")
Expand Down
14 changes: 8 additions & 6 deletions jdhapi/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
),
path("api/abstracts/submit", views.submit_abstract, name="submit-abstract"),
path("api/articles/", views.ArticleList.as_view(), name="article-list"),
path("api/articles/<str:abstract__pid>/status/", views.ArticleStatus.as_view(), name='article-status'),
path(
"api/articles/status",
views.update_article_status,
name="article-change-status",
),
path("api/articles/<str:abstract__pid>/status", views.ArticleStatus.as_view(), name='article-status'),
path(
"api/articles/<str:abstract__pid>/",
views.ArticleDetail.as_view(),
name="article-detail",
),
path(
"api/articles/status",
views.update_article_status,
name="article-change-status",
),
path("api/articles/advance", views.AdvanceArticleList.as_view(), name="advance-article-list"),
path(
"api/articles/bluesky",
Expand All @@ -51,6 +51,8 @@
path("api/articles/ojs/submissions", views.get_count_submission_from_ojs, name="count-submission-from-ojs"),
path("api/articles/ojs/submission", views.send_article_to_ojs, name="articles-send-to-ojs"),
path("api/articles/tweet", views.get_tweet_md_file, name="articles-tweet"),
path("api/articles/docx", views.get_docx, name="article-docx"),
path("api/articles/docx/email", views.send_docx_email, name="article-docx-email"),
path("api/authors/", views.AuthorList.as_view(), name="author-list"),
path("api/authors/<int:pk>/", views.AuthorDetail.as_view(), name="author-detail"),
path(
Expand Down
14 changes: 13 additions & 1 deletion jdhapi/utils/articles.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from django.utils.html import strip_tags

from jdhapi.utils.doi import get_doi_url_formatted_jdh
from jdhapi.models import Author, Tag
from jdhapi.models import Article, Author, Tag

from jdhseo.utils import getReferencesFromJupyterNotebook
from requests.exceptions import HTTPError
Expand Down Expand Up @@ -217,6 +217,18 @@ def get_citation(raw_url, article):
}


def save_citation(article_id):
logger.info(f"save_article_citation:{article_id}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to write the name of the function, write instead 'save_citation', so that for debugging we know exactly what to look for :)

try:
article = Article.objects.get(pk=article_id)
except Article.DoesNotExist:
logger.error(f"save_article_citation:{article_id} not found")
return
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe here do a raise Exception("Article id not found") instead of a return

citation = get_citation(raw_url=article.notebook_ipython_url, article=article)
article.citation = citation
article.save()


def get_raw_from_github(
repository_url, file_type, host="https://raw.githubusercontent.com"
):
Expand Down
Loading
Loading