Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #11578: align geoapp metadata update to other resources #11624

Merged
merged 6 commits into from
Oct 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions geonode/geoapps/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,33 +280,19 @@
new_category = TopicCategory.objects.get(id=int(category_form.cleaned_data["category_choice_field"]))
geoapp_form.cleaned_data.pop("ptype")

geoapp_obj = geoapp_form.instance
# update contact roles
geoapp_obj.set_contact_roles_from_metadata_edit(geoapp_form)
geoapp_obj.save()

additional_vals = dict(category=new_category)
vals = dict(category=new_category)

geoapp_form.cleaned_data.pop("metadata")
extra_metadata = geoapp_form.cleaned_data.pop("extra_metadata")

geoapp_form.save_linked_resources()
geoapp_form.cleaned_data.pop("linked_resources")

geoapp_obj = geoapp_form.instance

_vals = dict(**geoapp_form.cleaned_data, **additional_vals)
_vals.update({"resource_type": resource_type, "sourcetype": SOURCE_TYPE_LOCAL})

resource_manager.update(
geoapp_obj.uuid,
instance=geoapp_obj,
keywords=new_keywords,
regions=new_regions,
vals=_vals,
notify=True,
extra_metadata=json.loads(extra_metadata),
)
resource_manager.set_thumbnail(geoapp_obj.uuid, instance=geoapp_obj, overwrite=False)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resource update was performed 2 times for geoapps

vals.update({"resource_type": resource_type, "sourcetype": SOURCE_TYPE_LOCAL})

register_event(request, EventType.EVENT_CHANGE_METADATA, geoapp_obj)
if not ajax:
Expand All @@ -333,13 +319,27 @@
tb = traceback.format_exc()
logger.error(tb)

vals = {}
if "group" in geoapp_form.changed_data:
vals["group"] = geoapp_form.cleaned_data.get("group")
if any([x in geoapp_form.changed_data for x in ["is_approved", "is_published"]]):
vals["is_approved"] = geoapp_form.cleaned_data.get("is_approved", geoapp_obj.is_approved)
vals["is_published"] = geoapp_form.cleaned_data.get("is_published", geoapp_obj.is_published)
resource_manager.update(geoapp_obj.uuid, instance=geoapp_obj, notify=True, vals=vals)
else:
vals.pop("is_approved", None)
vals.pop("is_published", None)

Check warning on line 329 in geonode/geoapps/views.py

View check run for this annotation

Codecov / codecov/patch

geonode/geoapps/views.py#L328-L329

Added lines #L328 - L329 were not covered by tests

resource_manager.update(
geoapp_obj.uuid,
instance=geoapp_obj,
keywords=new_keywords,
regions=new_regions,
notify=True,
vals=vals,
extra_metadata=json.loads(extra_metadata),
)

resource_manager.set_thumbnail(geoapp_obj.uuid, instance=geoapp_obj, overwrite=False)

return HttpResponse(json.dumps({"message": message}))
elif request.method == "POST" and (
not geoapp_form.is_valid() or not category_form.is_valid() or not tkeywords_form.is_valid()
Expand Down
Loading