272 dashboard create one endpoint for articles with proper status#357
Conversation
| PUBLISHED = ( | ||
| "PUBLISHED", | ||
| "Published", | ||
| ) |
There was a problem hiding this comment.
We should add SOCIAL_MEDIA and ARCHIVED.
|
|
||
|
|
||
| def save_citation(article_id): | ||
| logger.info(f"save_article_citation:{article_id}") |
There was a problem hiding this comment.
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 :)
| article = Article.objects.get(pk=article_id) | ||
| except Article.DoesNotExist: | ||
| logger.error(f"save_article_citation:{article_id} not found") | ||
| return |
There was a problem hiding this comment.
maybe here do a raise Exception("Article id not found") instead of a return
| @@ -1,10 +1,15 @@ | |||
| #!/usr/bin/env python3 | |||
There was a problem hiding this comment.
We can rename the file github_action.py
jdhapi/utils/run_github_action.py
Outdated
| #!/usr/bin/env python3 | ||
| import logging | ||
| import os | ||
| import sys |
There was a problem hiding this comment.
do not forget to clean imports that we are not using :)
| return Response( | ||
| {"error": f"repository_url is missing for PID '{pid}'."}, | ||
| status=400, | ||
| ) |
There was a problem hiding this comment.
Maybe remove the check of the article pid outside of the first try exept
|
|
||
|
|
||
| def send_email_copy_editor(pid, docx_bytes): | ||
| COPY_EDITOR_ADDRESS = "elisabeth.guerard@uni.lu" |
There was a problem hiding this comment.
The email address should be stored as env variable. It should not be commited.
|
|
||
| @api_view(["GET"]) | ||
| @permission_classes([IsAdminUser]) | ||
| def send_docx_email(request): |
There was a problem hiding this comment.
I think we can merge that one with the following function because error response should be managed at the level of the endpoint function not after.
|
|
||
| docx_bytes = fetch_docx_bytes(pid, branch_name) | ||
| send_email_copy_editor(pid, docx_bytes) | ||
| return Response({"status": "sent", "pid": pid}) |
There was a problem hiding this comment.
When it is a success we need to set the status at 200 with an informative message like :
return Response({"message": "Docx sent succesfully by email for article : {pid}"}, status=200)
| def send_docx_email(request): | ||
| """ | ||
| Send the docx as an email attachment. | ||
| """ |
There was a problem hiding this comment.
Do not hesitate to write endpoint path into the docstring:
"""
GET api/articles/docx/email
Send the docx as an email attachment.
:params pid: the article PID
:params branch_name: the branch name where the docx file is located, by default "pandoc"
"""
Then it is a bit more clear to what it corresponds :)
Main changes made :
After changes, test done for :
Question
|
@salaun-marion
To test:
http://127.0.0.1:8000/api/articles/TqGQCFzXyreV/status/
pass in put:
{"status":"COPY_EDITING"}run github action pandoc.yml
get the docx
send to elisabeth.guerard need to be remove
or method added in the API
http://127.0.0.1:8000/api/articles/docx?pid=TqGQCFzXyreVhttp://127.0.0.1:8000/api/articles/api/articles/docx/email?pid=TqGQCFzXyreV{"status":"PUBLISHED"}add citation - controle DOI - publication date