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

4.2.x issue #12170 unable to set advanced contact roles in metadata editor #12191

6 changes: 3 additions & 3 deletions geonode/base/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1951,10 +1951,10 @@ def test_set_resource_thumbnail(self):
self.assertEqual(response.json(), "The url must be of an image with format (png, jpeg or jpg)")

# using Base64 data as an ASCII byte string
data["file"] = (
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAABHNCSVQICAgI\
data[
"file"
] = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAABHNCSVQICAgI\
fAhkiAAAABl0RVh0U29mdHdhcmUAZ25vbWUtc2NyZWVuc2hvdO8Dvz4AAAANSURBVAiZYzAxMfkPAALYAZzx61+bAAAAAElFTkSuQmCC"
)
with patch("geonode.base.models.is_monochromatic_image") as _mck:
_mck.return_value = False
response = self.client.put(url, data=data, format="json")
Expand Down
1 change: 0 additions & 1 deletion geonode/base/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,6 @@ def linked_resources(self, request, pk, *args, **kwargs):


def base_linked_resources(instance, user, params):

try:
resource_type = params.get("resource_type")
link_type = params.get("link_type")
Expand Down
11 changes: 7 additions & 4 deletions geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1707,8 +1707,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 @@ -1753,9 +1752,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[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