Skip to content

Commit

Permalink
Merge pull request #59 from zalf-rdm/gn_issue_12170_unable_to_set_adv…
Browse files Browse the repository at this point in the history
…anced_contact_roles_in_metadata_editor

 [Fixes GeoNode#12170] unable to set advanced contact roles in metadata editor
  • Loading branch information
mwallschlaeger authored May 6, 2024
2 parents a12ca9d + 0061662 commit 1ba8776
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 26 deletions.
11 changes: 7 additions & 4 deletions geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1940,8 +1940,7 @@ def set_contact_roles_from_metadata_edit(self, resource_base_form) -> bool:
failed = False
for role in self.get_multivalue_role_property_names():
try:
if resource_base_form.cleaned_data[role].exists():
self.__setattr__(role, resource_base_form.cleaned_data[role])
self.__setattr__(role, resource_base_form.cleaned_data[role])
except AttributeError:
logger.warning(f"unable to set contact role {role} for {self} ...")
failed = True
Expand Down Expand Up @@ -1986,9 +1985,13 @@ def __create_role__(
ContactRole.objects.filter(role=role, resource=self).delete()
return __create_role__(self, role, user_profile)

elif isinstance(user_profile, list) and all(isinstance(x, get_user_model()) for x in user_profile):
elif isinstance(user_profile, list) and all(
get_user_model().objects.filter(username=x).exists() for x in user_profile
):
ContactRole.objects.filter(role=role, resource=self).delete()
return [__create_role__(self, role, profile) for profile in user_profile]
return [
__create_role__(self, role, user) for user in get_user_model().objects.filter(username__in=user_profile)
]

elif user_profile is None:
ContactRole.objects.filter(role=role, resource=self).delete()
Expand Down
12 changes: 6 additions & 6 deletions geonode/base/widgets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import List

from dal_select2_taggit.widgets import TaggitSelect2
from django.http.request import QueryDict


class TaggitSelect2Custom(TaggitSelect2):
Expand Down Expand Up @@ -32,9 +33,8 @@ def value_from_datadict(self, data, files, name) -> List[str]:
returns list of selected elements
"""
try:
ret_list = data.getlist(name)
except KeyError:
ret_list = []
finally:
return ret_list
if type(data) is dict and name in data:
return data[name]
elif type(data) is QueryDict:
return data.getlist(name)
return []
16 changes: 0 additions & 16 deletions geonode/documents/templates/layouts/doc_panels.html
Original file line number Diff line number Diff line change
Expand Up @@ -596,22 +596,6 @@
</div>
</div>
{% endblock document_more_contact_roles %}

<div class="panel panel-default">
<div class="panel-heading">{% trans "Responsible and Permissions" %}</div>
<div class="panel-body">
<div>
<span><label for="{{ document_form.owner|id }}">{{ document_form.owner.label }}</label></span>
<!--<p class="xxs-font-size">(Responsible of the cited resource)</p>-->
{{ document_form.owner }}
</div>
<div>
<span><label for="{{ document_form.metadata_author|id }}">{{ document_form.metadata_author.label }}</label></span>
<!--<p class="xxs-font-size">(Author of the metadata)</p>-->
{{ document_form.metadata_author }}
</div>
</div>
</div>
<!--End Contact Roles -->
</div>
</div>
Expand Down

0 comments on commit 1ba8776

Please sign in to comment.