forked from enviPath/enviPy
[Feature] Integrate DOI Links, Handle Cycles in Pathway Viz (#407)
Co-authored-by: Tim Lorsbach <tim@lorsba.ch> Reviewed-on: enviPath/enviPy#407
This commit is contained in:
48
epdb/migrations/0026_auto_20260602_1718.py
Normal file
48
epdb/migrations/0026_auto_20260602_1718.py
Normal file
@ -0,0 +1,48 @@
|
||||
# Generated by Django 6.0.3 on 2026-06-02 17:18
|
||||
|
||||
from django.db import migrations
|
||||
from envipy_additional_information import DOI
|
||||
|
||||
|
||||
def forward_func(apps, schema_editor):
|
||||
AdditionalInformation = apps.get_model("epdb", "AdditionalInformation")
|
||||
|
||||
refs = AdditionalInformation.objects.filter(type="Reference")
|
||||
|
||||
remaining = []
|
||||
|
||||
for ref in refs:
|
||||
r = ref.data["reference"]
|
||||
try:
|
||||
# PubMed IDs are plain ints, try parsing
|
||||
_ = int(r)
|
||||
# Nothing to do
|
||||
except ValueError:
|
||||
DOMAINS = [
|
||||
"http://dx.doi.org/",
|
||||
"https://dx.doi.org/",
|
||||
"http://doi.org/",
|
||||
"https://doi.org/",
|
||||
]
|
||||
for d in DOMAINS:
|
||||
r = r.replace(d, "")
|
||||
|
||||
if r.startswith("10."):
|
||||
ref.type = DOI.__name__
|
||||
ref.data = {"doi": r}
|
||||
ref.save()
|
||||
else:
|
||||
remaining.append(ref)
|
||||
|
||||
if len(remaining) > 0:
|
||||
raise ValueError(f"Could not parse {len(remaining)} references")
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("epdb", "0025_auto_20260511_2025"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(forward_func, reverse_code=migrations.RunPython.noop),
|
||||
]
|
||||
Reference in New Issue
Block a user