Skip to content

Commit

Permalink
Make if statements more intuitive
Browse files Browse the repository at this point in the history
  • Loading branch information
cslzchen committed Dec 8, 2023
1 parent 0403c29 commit 33d86f3
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions osf/management/commands/fetch_cedar_metadata_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@ def handle(self, *args, **kwargs):
schema_name = template['schema:name']
pav_last_updated_on = template['pav:lastUpdatedOn']
existing_versions = CedarMetadataTemplate.objects.filter(cedar_id=cedar_id)
if not existing_versions:
if existing_versions:
latest_version = existing_versions.order_by('-template_version').first()
if pav_last_updated_on != latest_version.template['pav:lastUpdatedOn']:
CedarMetadataTemplate.objects.create(
schema_name=schema_name,
template=template,
cedar_id=cedar_id,
template_version=latest_version.template_version + 1
)
latest_version.active = False
latest_version.save()
else:
CedarMetadataTemplate.objects.create(
schema_name=schema_name,
template=template,
cedar_id=cedar_id,
template_version=1
)
latest_version = existing_versions.order_by('-template_version').first()
if pav_last_updated_on != latest_version.template['pav:lastUpdatedOn']:
CedarMetadataTemplate.objects.create(
schema_name=schema_name,
template=template,
cedar_id=cedar_id,
template_version=latest_version.template_version + 1
)
latest_version.active = False
latest_version.save()

0 comments on commit 33d86f3

Please sign in to comment.