Errata backend#5249
Conversation
a91fe97 to
21289b6
Compare
|
@mauromsl we have been notified of a small incoherence in the XML deposit specs (see https://github.com/orgs/openlibhums/discussions/5238#discussioncomment-16599730 ). I've moved this MR to "draft". I'll complete it after we publish our first erratum and ping again. |
21289b6 to
ab30aa4
Compare
1047bef to
9c75895
Compare
from crossref support staff: > [...] > You can't totally omit the <crossmark_policy> element. For historical reasons, it's strictly required by the schema. But, as a workaround, you can just repeat the DOI of the original paper in that field. It's not used for anything, but it has to have a valid DOI in it.
9c75895 to
796c658
Compare
|
|
||
| {% if article.erratum_of %} | ||
| <crossmark> | ||
| <crossmark_policy>{{ article.object.journal|setting:'crossref_prefix' }}/not-used</crossmark_policy> |
There was a problem hiding this comment.
<update>, then a <crossmark_policy> DOI should also be provided, but, according to crossref support, that element is not used and any DOI would do. They suggested to use the article DOI, but I'm hardcoding a 10.11111/no-used fake DOI (I feel it's less confusing...)
There was a problem hiding this comment.
@mauromsl please feel free to resolve this thread if you have no objections
mauromsl
left a comment
There was a problem hiding this comment.
Thank you @gamboz great work. I've proposed two main changes inline:
- Avoid using the section names as the mechanism for serializing the relationship type of "errata"
- Use a linker table with a
throughmodel relationship, ideally repurposing the model that already lives in the hydra plugin.
| if self.section.name != "Erratum": | ||
| return None | ||
| if not self.ancestors.exists(): | ||
| return None |
There was a problem hiding this comment.
While it makes sense on the context of this PR, section.name is a customizable (and translatable) entry. Since we are adding a new model to register the relationships between articles, it would make sense to codify this (and other relationships) as part of that model, rather than relying on the indirection of the section name.
There was a problem hiding this comment.
should be addressed by openlibhums/Hydra#12
| class Genealogy(models.Model): | ||
| """ | ||
| Maintain relations of type parent/children between articles. | ||
|
|
||
| This can be used, for instance, to link erratum to the original paper. | ||
| """ | ||
|
|
||
| parent = models.OneToOneField( | ||
| Article, | ||
| verbose_name=_("Original or main paper"), | ||
| on_delete=models.CASCADE, | ||
| related_name="genealogy", | ||
| ) | ||
| children = SortedManyToManyField( | ||
| Article, | ||
| related_name="ancestors", | ||
| ) | ||
|
|
||
| def __str__(self): | ||
| return f"Genealogy: {self.parent} has {self.children.count()} kids" | ||
|
|
||
|
|
There was a problem hiding this comment.
I think the community are asking for a few more relationship types such as addendum, correction and so on. We also have a model on the hydra plugin for registering relationships such as translations.
Would it work for your use case if we were to port the LinkedArticle model from Hydra plugin instead?
It behaves as a linking table, so there is one less join required when querying both sides of the relationship.
There was a problem hiding this comment.
should be addressed by openlibhums/Hydra#12
| pytz==2024.1 | ||
| requests==2.32.4 | ||
| six==1.16.0 | ||
| django-sortedm2m~=3.1 |
There was a problem hiding this comment.
If we go with the approach I proposed about registering a model that behaves as a linking table, we could also use our M2MOrderedThroughField. It would avoid the additional dependency and also maintain consistency with other ordered many to many relationships in the codebase.
There was a problem hiding this comment.
should be addressed by openlibhums/Hydra#12
37cf503 to
8fc6bc8
Compare
| def ancestors(self, link_type: str) -> QuerySet["Article"]: | ||
| """ | ||
| Return articles related to self, where self is the "to-article". | ||
|
|
||
| This can be used, for instance, to refer to corrections in self's landing page. | ||
| """ | ||
| return self._related(link_type=link_type, direction="ancestors") | ||
|
|
||
| def descendants(self, link_type: str) -> QuerySet["Article"]: | ||
| """ | ||
| Return articles related to self, where self is the "from-article". | ||
|
|
||
| This can be used, for instance, to refer to corrections in self's landing page. | ||
| """ | ||
| return self._related(link_type=link_type, direction="descendants") | ||
|
|
||
| def _related(self, link_type: str, direction: str) -> QuerySet["Article"]: | ||
| """ | ||
| Return articles related to self. | ||
|
|
||
| Direction: | ||
| - descendants -> where self is the "from-article" | ||
| - ancenstors -> where self. is the "to-article" | ||
| """ | ||
| if not link_type: | ||
| return Article.objects.none() | ||
|
|
||
| # Silently return nothing if Hydra plugin is not available | ||
| try: | ||
| from plugins.hydra.models import LinkedArticle # noqa: F401 | ||
| except ImportError: | ||
| return Article.objects.none() | ||
|
|
||
| if direction == "descendants": | ||
| # self is the "from-article"; return the "to-articles" | ||
| return Article.objects.filter( | ||
| linked_to__from_article=self, linked_to__relationship=link_type | ||
| ) | ||
| if direction == "ancestors": | ||
| # self is the "to-article"; return the "from-articles" | ||
| return Article.objects.filter( | ||
| linked_from__to_article=self, linked_from__relationship=link_type | ||
| ) | ||
|
|
||
| raise ValueError( | ||
| f"Unknown relationship direction '{direction}' requested for {self.id}" | ||
| ) |
There was a problem hiding this comment.
I wrote these methods as helpers for the theme templates, but before seeing that there was the sidebar_article_links hook in hydra.
ATM, these are not used and probably not necessary.
Let me know if you prefer I drop them 🙂
Please also see commit 3dc9f69 in Hydra
8fc6bc8 to
796c658
Compare
|
@mauromsl something funny happened to this MR: I don't see my recent commits and the changes are still the old ones... Please ignore this MR until I understand what's going on 😢 |
796c658 to
e64c22e
Compare
Situation back to normal... (was github unhappy with me? I will worry about this on the beach all next week 🏖️ 🥳 ) |
e64c22e to
796c658
Compare
Add the possibility of linking an erratum to an article and register this relation with Crossref.
See also discussion 5238
ATM, errata are so rare that no front-end or manager interface is changed here, but an "admin" is provided.
Please note the new dependency.