Skip to content

Commit

Permalink
add management command
Browse files Browse the repository at this point in the history
  • Loading branch information
adlius committed Dec 4, 2023
1 parent b1297c3 commit 232d71b
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions osf/management/commands/fetch_cedar_metadata_templates.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from django.conf import settings
from django.core.management.base import BaseCommand

from osf.models import CedarMetadataTemplate
Expand All @@ -8,24 +7,23 @@ class Command(BaseCommand):
def handle(self, *args, **kwargs):
ids = CedarClient().retrieve_all_template_ids()
for cedar_id in ids:
try:
json = CedarClient().retrieve_template_by_id(cedar_id)
title = json['title']
older_versions = CedarMetadataTemplate.objects.filter(cedar_id=id).order_by('-template_version').values()
latest_version = older_versions.first()
if latest_version and json != latest_version.template:
CedarMetadataTemplate.objects.create(
title=title,
template=json,
cedar_id=cedar_id,
template_version=latest_version.template_version + 1
)
else:
CedarMetadataTemplate.objects.create(
title=title,
template=json,
cedar_id=cedar_id,
template_version=1
)
except:
pass
json = CedarClient().retrieve_template_by_id(cedar_id)
title = json['title']
older_versions = CedarMetadataTemplate.objects.filter(cedar_id=cedar_id).order_by('-template_version')
latest_version = older_versions.first()
if latest_version and json != latest_version.template:
new_template = CedarMetadataTemplate.objects.create(
title=title,
template=json,
cedar_id=cedar_id,
template_version=latest_version.template_version + 1
)
new_template.save()
else:
new_template = CedarMetadataTemplate.objects.create(
title=title,
template=json,
cedar_id=cedar_id,
template_version=1
)
new_template.save()

0 comments on commit 232d71b

Please sign in to comment.