Skip to content

Commit

Permalink
refactor(import): update created and updated, return False when error…
Browse files Browse the repository at this point in the history
… at save

Signed-off-by: David Wallace <[email protected]>
  • Loading branch information
MyPyDavid committed Jul 12, 2024
1 parent f88f180 commit e717725
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 0 additions & 1 deletion rdmo/management/import_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def strip_uri_prefix_endswith_slash(element: dict) -> dict:

def apply_field_values(instance, element, import_helper, uploaded_uris, original) -> None:
"""Applies the field values from the element to the instance."""
element = strip_uri_prefix_endswith_slash(element)
# start to set values on the instance
# set common field values from element on instance
for field in import_helper.common_fields:
Expand Down
14 changes: 9 additions & 5 deletions rdmo/management/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,8 @@ def import_element(
element["errors"].append(perms_error_msg)
return element

updated = not created
element['created'] = created
element['updated'] = updated
element['updated'] = not created and original is not None
# INFO: the dict element[FieldNames.diff.value] is filled by calling track_changes_on_element

element = strip_uri_prefix_endswith_slash(element)
Expand All @@ -126,16 +125,21 @@ def import_element(

if element.get('errors'):
# when there is an error msg, the import can be stopped and return
if save:
element['created'] = False
element['updated'] = False
return element

if save:
logger.info(msg)
instance.save()

if save or updated:
update_related_fields(instance, element, import_helper, original, save)

if save and settings.MULTISITE:
add_current_site_to_sites_and_editor(instance, current_site, import_helper)
if created and settings.MULTISITE:
add_current_site_to_sites_and_editor(instance, current_site, import_helper)

elif not created: # when an element will be updated but not saved
update_related_fields(instance, element, import_helper, original, save)

return element

0 comments on commit e717725

Please sign in to comment.