Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/GeoNode/geonode into ISSU…
Browse files Browse the repository at this point in the history
…E_7154

# Conflicts:
#	geonode/api/tests.py
#	geonode/upload/upload.py
  • Loading branch information
afabiani committed Apr 6, 2021
2 parents 0576419 + 073d9a5 commit 2351069
Show file tree
Hide file tree
Showing 92 changed files with 986 additions and 723 deletions.
453 changes: 453 additions & 0 deletions .pylintrc

Large diffs are not rendered by default.

39 changes: 18 additions & 21 deletions geonode/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ def test_layer_get_detail_unauth_layer_not_public(self):
layer.set_permissions(self.perm_spec)
layer.clear_dirty_state()
self.assertHttpUnauthorized(self.api_client.get(
self.list_url + str(layer.id) + '/'))
f"{self.list_url + str(layer.id)}/"))

self.api_client.client.login(username=self.user, password=self.passwd)
resp = self.api_client.get(self.list_url + str(layer.id) + '/')
resp = self.api_client.get(f"{self.list_url + str(layer.id)}/")
self.assertValidJSONResponse(resp)

# with delayed security
Expand Down Expand Up @@ -288,19 +288,19 @@ def test_profiles_filters(self):
self.assertValidJSONResponse(resp)
self.assertEqual(len(self.deserialize(resp)['objects']), 9)

filter_url = self.profiles_list_url + '?name__icontains=norm'
filter_url = f"{self.profiles_list_url}?name__icontains=norm"

resp = self.api_client.get(filter_url)
self.assertValidJSONResponse(resp)
self.assertEqual(len(self.deserialize(resp)['objects']), 1)

filter_url = self.profiles_list_url + '?name__icontains=NoRmAN'
filter_url = f"{self.profiles_list_url}?name__icontains=NoRmAN"

resp = self.api_client.get(filter_url)
self.assertValidJSONResponse(resp)
self.assertEqual(len(self.deserialize(resp)['objects']), 1)

filter_url = self.profiles_list_url + '?name__icontains=bar'
filter_url = f"{self.profiles_list_url}?name__icontains=bar"

resp = self.api_client.get(filter_url)
self.assertValidJSONResponse(resp)
Expand All @@ -317,19 +317,19 @@ def test_groups_filters(self):
self.assertValidJSONResponse(resp)
self.assertEqual(len(self.deserialize(resp)['objects']), 1)

filter_url = self.groups_list_url + '?name__icontains=bar'
filter_url = f"{self.groups_list_url}?name__icontains=bar"

resp = self.api_client.get(filter_url)
self.assertValidJSONResponse(resp)
self.assertEqual(len(self.deserialize(resp)['objects']), 1)

filter_url = self.groups_list_url + '?name__icontains=BaR'
filter_url = f"{self.groups_list_url}?name__icontains=BaR"

resp = self.api_client.get(filter_url)
self.assertValidJSONResponse(resp)
self.assertEqual(len(self.deserialize(resp)['objects']), 1)

filter_url = self.groups_list_url + '?name__icontains=foo'
filter_url = f"{self.groups_list_url}?name__icontains=foo"

resp = self.api_client.get(filter_url)
self.assertValidJSONResponse(resp)
Expand All @@ -340,14 +340,13 @@ def test_category_filters(self):

# check we get the correct layers number returnered filtering on one
# and then two different categories
filter_url = self.list_url + '?category__identifier=location'
filter_url = f"{self.list_url}?category__identifier=location"

resp = self.api_client.get(filter_url)
self.assertValidJSONResponse(resp)
self.assertEqual(len(self.deserialize(resp)['objects']), 3)

filter_url = self.list_url + \
'?category__identifier__in=location&category__identifier__in=biota'
filter_url = f"{self.list_url}?category__identifier__in=location&category__identifier__in=biota"

resp = self.api_client.get(filter_url)
self.assertValidJSONResponse(resp)
Expand All @@ -358,14 +357,13 @@ def test_tag_filters(self):

# check we get the correct layers number returnered filtering on one
# and then two different keywords
filter_url = self.list_url + '?keywords__slug=layertagunique'
filter_url = f"{self.list_url}?keywords__slug=layertagunique"

resp = self.api_client.get(filter_url)
self.assertValidJSONResponse(resp)
self.assertEqual(len(self.deserialize(resp)['objects']), 1)

filter_url = self.list_url + \
'?keywords__slug__in=layertagunique&keywords__slug__in=populartag'
filter_url = f"{self.list_url}?keywords__slug__in=layertagunique&keywords__slug__in=populartag"

resp = self.api_client.get(filter_url)
self.assertValidJSONResponse(resp)
Expand All @@ -376,14 +374,13 @@ def test_owner_filters(self):

# check we get the correct layers number returnered filtering on one
# and then two different owners
filter_url = self.list_url + '?owner__username=user1'
filter_url = f"{self.list_url}?owner__username=user1"

resp = self.api_client.get(filter_url)
self.assertValidJSONResponse(resp)
self.assertEqual(len(self.deserialize(resp)['objects']), 1)

filter_url = self.list_url + \
'?owner__username__in=user1&owner__username__in=foo'
filter_url = f"{self.list_url}?owner__username__in=user1&owner__username__in=foo"

resp = self.api_client.get(filter_url)
self.assertValidJSONResponse(resp)
Expand All @@ -394,7 +391,7 @@ def test_title_filter(self):

# check we get the correct layers number returnered filtering on the
# title
filter_url = self.list_url + '?title=layer2'
filter_url = f"{self.list_url}?title=layer2"

resp = self.api_client.get(filter_url)
self.assertValidJSONResponse(resp)
Expand All @@ -413,21 +410,21 @@ def to_date(val):
return val.date().strftime(fstring)

d1 = to_date(now - step)
filter_url = self.list_url + f'?date__exact={d1}'
filter_url = f"{self.list_url}?date__exact={d1}"

resp = self.api_client.get(filter_url)
self.assertValidJSONResponse(resp)
self.assertEqual(len(self.deserialize(resp)['objects']), 0)

d3 = to_date(now - (3 * step))
filter_url = self.list_url + f'?date__gte={d3}'
filter_url = f"{self.list_url}?date__gte={d3}"

resp = self.api_client.get(filter_url)
self.assertValidJSONResponse(resp)
self.assertEqual(len(self.deserialize(resp)['objects']), 3)

d4 = to_date(now - (4 * step))
filter_url = self.list_url + f'?date__range={d4},{to_date(now)}'
filter_url = f"{self.list_url}?date__range={d4},{to_date(now)}"

resp = self.api_client.get(filter_url)
self.assertValidJSONResponse(resp)
Expand Down
3 changes: 2 additions & 1 deletion geonode/base/api/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ class IsOwnerOrReadOnly(permissions.BasePermission):
Object-level permission to only allow owners of an object to edit it.
Assumes the model instance has an `owner` attribute.
"""

def has_object_permission(self, request, view, obj):
if request.user is None or \
(not request.user.is_anonymous and not request.user.is_active):
(not request.user.is_anonymous and not request.user.is_active):
return False
if request.user.is_superuser:
return True
Expand Down
2 changes: 1 addition & 1 deletion geonode/base/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def _filtered(self, request, filter):
exclude = []
for resource in resources:
if not request.user.is_superuser and \
not request.user.has_perm('view_resourcebase', resource.get_self_resource()):
not request.user.has_perm('view_resourcebase', resource.get_self_resource()):
exclude.append(resource.id)
resources = resources.exclude(id__in=exclude)
result_page = paginator.paginate_queryset(resources, request)
Expand Down
1 change: 1 addition & 0 deletions geonode/base/bbox_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class BBOXHelper:
A bounding box representation to avoid use of list indices when
dealing with bounding boxes.
"""

def __init__(self, minmaxform):
self.xmin, self.ymin, self.xmax, self.ymax = minmaxform

Expand Down
12 changes: 6 additions & 6 deletions geonode/base/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def rectree(parent, path):
children_list_of_tuples.append(
tuple((path + parent.name, tuple((child.id, child.name))))
)
childrens = rectree(child, parent.name + '/')
childrens = rectree(child, f"{parent.name}/")
if childrens:
children_list_of_tuples.extend(childrens)

Expand Down Expand Up @@ -105,10 +105,10 @@ def _get_choices(self):

def label_from_instance(self, obj):
return '<i class="fa ' + obj.fa_class + ' fa-2x unchecked"></i>' \
'<i class="fa ' + obj.fa_class + ' fa-2x checked"></i>' \
'<span class="has-popover" data-container="body" data-toggle="popover" data-placement="top" ' \
'data-content="' + obj.description + '" trigger="hover">' \
'<br/><strong>' + obj.gn_description + '</strong></span>'
'<i class="fa ' + obj.fa_class + ' fa-2x checked"></i>' \
'<span class="has-popover" data-container="body" data-toggle="popover" data-placement="top" ' \
'data-content="' + obj.description + '" trigger="hover">' \
'<br/><strong>' + obj.gn_description + '</strong></span>'


# NOTE: This is commented as it needs updating to work with select2 and autocomlete light.
Expand Down Expand Up @@ -276,7 +276,7 @@ def _region_id_from_choice(choice):
class CategoryForm(forms.Form):
category_choice_field = CategoryChoiceField(
required=False,
label='*' + _('Category'),
label=f"*{_('Category')}",
empty_label=None,
queryset=TopicCategory.objects.filter(
is_choice=True).extra(
Expand Down
12 changes: 6 additions & 6 deletions geonode/base/management/commands/load_thesaurus.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def load_thesaurus(self, input_file, name, store):
RDF_URI = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
XML_URI = 'http://www.w3.org/XML/1998/namespace'

ABOUT_ATTRIB = '{' + RDF_URI + '}about'
LANG_ATTRIB = '{' + XML_URI + '}lang'
ABOUT_ATTRIB = f"{{{RDF_URI}}}about"
LANG_ATTRIB = f"{{{XML_URI}}}lang"

ns = {
'rdf': RDF_URI,
Expand Down Expand Up @@ -161,7 +161,7 @@ def create_fake_thesaurus(self, name):
thesaurus = Thesaurus()
thesaurus.identifier = name

thesaurus.title = "Title: " + name
thesaurus.title = f"Title: {name}"
thesaurus.description = "SAMPLE FAKE THESAURUS USED FOR TESTING"
thesaurus.date = "2016-10-01"

Expand All @@ -170,15 +170,15 @@ def create_fake_thesaurus(self, name):
for keyword in ['aaa', 'bbb', 'ccc']:
tk = ThesaurusKeyword()
tk.thesaurus = thesaurus
tk.about = keyword + '_about'
tk.alt_label = keyword + '_alt'
tk.about = f"{keyword}_about"
tk.alt_label = f"{keyword}_alt"
tk.save()

for _l in ['it', 'en', 'es']:
tkl = ThesaurusKeywordLabel()
tkl.keyword = tk
tkl.lang = _l
tkl.label = keyword + "_l_" + _l + "_t_" + name
tkl.label = f"{keyword}_l_{_l}_t_{name}"
tkl.save()


Expand Down
12 changes: 6 additions & 6 deletions geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def name_long(self):
if self.abbreviation is None or len(self.abbreviation) == 0:
return self.name
else:
return self.name + " (" + self.abbreviation + ")"
return f"{self.name} ({self.abbreviation})"

@property
def description_bullets(self):
Expand All @@ -312,7 +312,7 @@ def description_bullets(self):
bullets = []
lines = self.description.split("\n")
for line in lines:
bullets.append("+ " + line)
bullets.append(f"+ {line}")
return bullets

class Meta:
Expand Down Expand Up @@ -959,7 +959,7 @@ def save(self, notify=False, *args, **kwargs):
Send a notification when a resource is created or updated
"""
if not self.resource_type and self.polymorphic_ctype and \
self.polymorphic_ctype.model:
self.polymorphic_ctype.model:
self.resource_type = self.polymorphic_ctype.model.lower()

if hasattr(self, 'class_name') and (self.pk is None or notify):
Expand Down Expand Up @@ -1157,20 +1157,20 @@ def license_light(self):
if self.license.name is not None and (len(self.license.name) > 0):
a.append(self.license.name)
if self.license.url is not None and (len(self.license.url) > 0):
a.append("(" + self.license.url + ")")
a.append(f"({self.license.url})")
return " ".join(a)

@property
def license_verbose(self):
a = []
if self.license.name_long is not None and (
len(self.license.name_long) > 0):
a.append(self.license.name_long + ":")
a.append(f"{self.license.name_long}:")
if self.license.description is not None and (
len(self.license.description) > 0):
a.append(self.license.description)
if self.license.url is not None and (len(self.license.url) > 0):
a.append("(" + self.license.url + ")")
a.append(f"({self.license.url})")
return " ".join(a)

@property
Expand Down
8 changes: 4 additions & 4 deletions geonode/base/populate_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,13 @@ def dump_models(path=None):

def create_single_layer(name):
get_user_model().objects.create(
username='admin',
is_superuser=True,
first_name='admin')
username='admin',
is_superuser=True,
first_name='admin')
test_datetime = datetime.strptime('2020-01-01', '%Y-%m-%d')
user = get_user_model().objects.get(username='AnonymousUser')
ll = (name, 'lorem ipsum', name, f'geonode:{name}', [
0, 22, 0, 22], test_datetime, ('populartag',), "farming")
0, 22, 0, 22], test_datetime, ('populartag',), "farming")
title, abstract, name, alternate, (bbox_x0, bbox_x1, bbox_y0, bbox_y1), start, kws, category = ll
layer = Layer(
title=title,
Expand Down
2 changes: 1 addition & 1 deletion geonode/base/templatetags/base_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def _has_owner_his_permissions():
_owner_set == set(['change_resourcebase_permissions', 'publish_resourcebase'])

if not _has_owner_his_permissions() and \
(user.is_superuser or resource.owner.pk == user.pk):
(user.is_superuser or resource.owner.pk == user.pk):
return True
return False

Expand Down
2 changes: 1 addition & 1 deletion geonode/base/templatetags/user_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ def get_item(dictionary, key):
def show_notification(notice_type_label, current_user):
adms_notice_types = getattr(settings, 'ADMINS_ONLY_NOTICE_TYPES', [])
if not current_user.is_superuser and adms_notice_types and \
notice_type_label in adms_notice_types:
notice_type_label in adms_notice_types:
return False
return True
8 changes: 3 additions & 5 deletions geonode/base/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,9 @@ def remove_duplicate_links(resource):
if isinstance(resource, Layer):
# fixup Legend links
layer = resource
legend_url_template = \
ogc_server_settings.PUBLIC_LOCATION + \
'ows?service=WMS&request=GetLegendGraphic&format=image/png&WIDTH=20&HEIGHT=20&LAYER=' + \
'{alternate}&STYLE={style_name}' + \
'&legend_options=fontAntiAliasing:true;fontSize:12;forceLabels:on'
legend_url_template = (f"{ogc_server_settings.PUBLIC_LOCATION}ows?"
"service=WMS&request=GetLegendGraphic&format=image/png&WIDTH=20&HEIGHT=20&"
f"LAYER={{alternate}}&STYLE={{style_name}}&legend_options=fontAntiAliasing:true;fontSize:12;forceLabels:on")
if layer.default_style and not layer.get_legend_url(style_name=layer.default_style.name):
Link.objects.update_or_create(
resource=layer.resourcebase_ptr,
Expand Down
9 changes: 4 additions & 5 deletions geonode/br/management/commands/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def execute_backup(self, **options):
# skip dumping of static files of apps not located under LOCAL_ROOT path
# (check to prevent saving files from site-packages in project-template based GeoNode projects)
if getattr(settings, 'LOCAL_ROOT', None) and \
not static_files_folder.startswith(settings.LOCAL_ROOT):
not static_files_folder.startswith(settings.LOCAL_ROOT):
print(f"Skipping static directory: {static_files_folder}. "
f"It's not located under LOCAL_ROOT path: {settings.LOCAL_ROOT}.")
continue
Expand Down Expand Up @@ -225,7 +225,7 @@ def execute_backup(self, **options):
# skip dumping of template files of apps not located under LOCAL_ROOT path
# (check to prevent saving files from site-packages in project-template based GeoNode projects)
if getattr(settings, 'LOCAL_ROOT', None) and \
not template_files_folder.startswith(settings.LOCAL_ROOT):
not template_files_folder.startswith(settings.LOCAL_ROOT):
print(f"Skipping template directory: {template_files_folder}. "
f"It's not located under LOCAL_ROOT path: {settings.LOCAL_ROOT}.")
continue
Expand All @@ -250,7 +250,7 @@ def execute_backup(self, **options):
# skip dumping of locale files of apps not located under LOCAL_ROOT path
# (check to prevent saving files from site-packages in project-template based GeoNode projects)
if getattr(settings, 'LOCAL_ROOT', None) and \
not locale_files_folder.startswith(settings.LOCAL_ROOT):
not locale_files_folder.startswith(settings.LOCAL_ROOT):
logger.info(f"Skipping locale directory: {locale_files_folder}. "
f"It's not located under LOCAL_ROOT path: {settings.LOCAL_ROOT}.")
continue
Expand Down Expand Up @@ -306,8 +306,7 @@ def create_geoserver_backup(self, config, settings, target_folder, ignore_errors
if r.status_code != 200:
raise ValueError('Could not reload GeoServer catalog!')

error_backup = 'Could not successfully backup GeoServer ' + \
'catalog [{}rest/br/backup/]: {} - {}'
error_backup = "Could not successfully backup GeoServer catalog [{{}}rest/br/backup/]: {{}} - {{}}"

_options = [
'BK_CLEANUP_TEMP=true',
Expand Down
Loading

0 comments on commit 2351069

Please sign in to comment.