From 33d86f316adecb6fd48cab9b9ab7c702ae10ff0f Mon Sep 17 00:00:00 2001 From: Longze Chen Date: Fri, 8 Dec 2023 12:16:44 -0500 Subject: [PATCH] Make if statements more intuitive --- .../fetch_cedar_metadata_templates.py | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/osf/management/commands/fetch_cedar_metadata_templates.py b/osf/management/commands/fetch_cedar_metadata_templates.py index 265a75a6b72..793376ebc21 100644 --- a/osf/management/commands/fetch_cedar_metadata_templates.py +++ b/osf/management/commands/fetch_cedar_metadata_templates.py @@ -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()