Skip to content

Commit

Permalink
Enhance error handling / doc - initialized ArticleXml in ArticleDetail
Browse files Browse the repository at this point in the history
  • Loading branch information
eliselavy committed Jan 2, 2025
1 parent 5f54ce8 commit 1c2eec3
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 19 deletions.
60 changes: 43 additions & 17 deletions jdhapi/utils/publication_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,52 @@


def check_if_editorial(pid):
article = Article.objects.filter(abstract__pid=pid, tags__name="editorial").first()
if article:
return True
else:
try:
article = Article.objects.filter(abstract__pid=pid, tags__name="editorial").first()
if article:
return True
else:
return False
except Exception as e:
logger.error(f"An error occurred while checking if editorial: {e}")
return False


def get_order_publication(pid, issue):
# Check if editorial
# logger.info(f"result check if editorial {check_if_editorial(pid)}")
if check_if_editorial(pid):
return "1"
else:
seq = "UNDEFINED"
articles = Article.objects.filter(status=Article.Status.PUBLISHED, issue=issue).exclude(tags__name="editorial").order_by('publication_date').values("abstract__pid", 'abstract__title')
for index, article in enumerate(articles, 2):
logger.info(f"Articles issue {issue} sorted {article['abstract__title']} - INDEX {index}")
if pid == article['abstract__pid']:
seq = index
return seq
def get_order_publication(pid, issue_pid):
"""
Determine the order of publication for a given article within an issue.
This function checks if the article is an editorial. If it is, it returns "1".
Otherwise, it retrieves all published articles in the specified issue, excluding
editorials, and orders them by their publication date. It then determines the
position of the given article (identified by `pid`) within this ordered list.
Args:
pid (str): The unique identifier of the article.
issue (str): The identifier of the issue in which the article is published.
Returns:
str: The order of publication as a string. Returns "1" if the article is an
editorial, otherwise returns the position of the article in the ordered
list or "UNDEFINED" if the article is not found.
"""
try:
# Check if editorial
# logger.info(f"result check if editorial {check_if_editorial(pid)}")
if check_if_editorial(pid):
return "1"
else:
logger.info("not an editorial")
seq = "UNDEFINED"
articles = Article.objects.filter(status=Article.Status.PUBLISHED, issue__pid=issue_pid).exclude(tags__name="editorial").order_by('publication_date').values("abstract__pid", 'abstract__title')
# Start index from 2 because editorials are given the position 1
for index, article in enumerate(articles, 2):
logger.info(f"Articles issue {issue_pid} sorted {article['abstract__title']} - INDEX {index}")
seq = str(index)
return seq
except Exception as e:
logger.error(f"An error occurred while determining the order of publication: {e}")
return "UNDEFINED"



Expand Down
23 changes: 21 additions & 2 deletions jdhseo/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ def ArticleDetail(request, pid):
if 'keywords' in article.data:
array_keys = "<b>Keywords: </b>" + article.data['keywords'][0].replace(';', ',')
logger.info(f"keywords {array_keys}")
# Initialize ArticleXml to get authors and affiliations
try:
article_xml = ArticleXml(
article_authors=article.abstract.authors.all(),
title=article.data.get('title', [''])[0],
article_doi=article.doi,
keywords=article.data.get('keywords', []),
publication_date=article.publication_date,
copyright=article.copyright_type,
issue_pid=article.issue.pid,
pid=pid
)
authors = article_xml.authors
logger.info(f"authors {authors}")
affiliations = article_xml.affiliations
logger.info(f"affiliations {affiliations}")
except Http404 as e:
raise Http404(f"Error initializing ArticleXml: {str(e)}")
# fill the context for the template file.
context = {
'article': article,
Expand All @@ -61,10 +79,11 @@ def ArticleDetail(request, pid):
'media_url': settings.MEDIA_URL,
'doi_url': doi_url,
'published_date': published_date,
'keywords': array_keys
'keywords': array_keys,
'authors': authors,
'affiliations': affiliations
}
# check if it is a github url

context.update({'proxy': 'github', 'host': settings.JDHSEO_PROXY_HOST})
if notebook_url.startswith(settings.JDHSEO_PROXY_PATH_GITHUB):
# load contents from remote link (it uses nginx cache if availeble.
Expand Down

0 comments on commit 1c2eec3

Please sign in to comment.