Skip to content

Commit af1f465

Browse files
committed
[Flying] Replace "+" concatenated strings with f{strings}
(cherry picked from commit 21b3db4cbde8b7f3279289e563ddd7ca8e8b3a42) # Conflicts: # geonode/api/tests.py
1 parent 8fcd482 commit af1f465

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1004
-730
lines changed

.pylintrc

+453
Large diffs are not rendered by default.

geonode/api/tests.py

+56-48
Large diffs are not rendered by default.

geonode/base/api/permissions.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@ class IsOwnerOrReadOnly(permissions.BasePermission):
105105
Object-level permission to only allow owners of an object to edit it.
106106
Assumes the model instance has an `owner` attribute.
107107
"""
108+
108109
def has_object_permission(self, request, view, obj):
109110
if request.user is None or \
110-
(not request.user.is_anonymous and not request.user.is_active):
111+
(not request.user.is_anonymous and not request.user.is_active):
111112
return False
112113
if request.user.is_superuser:
113114
return True

geonode/base/api/views.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def _filtered(self, request, filter):
162162
exclude = []
163163
for resource in resources:
164164
if not request.user.is_superuser and \
165-
not request.user.has_perm('view_resourcebase', resource.get_self_resource()):
165+
not request.user.has_perm('view_resourcebase', resource.get_self_resource()):
166166
exclude.append(resource.id)
167167
resources = resources.exclude(id__in=exclude)
168168
result_page = paginator.paginate_queryset(resources, request)

geonode/base/bbox_utils.py

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class BBOXHelper:
2828
A bounding box representation to avoid use of list indices when
2929
dealing with bounding boxes.
3030
"""
31+
3132
def __init__(self, minmaxform):
3233
self.xmin, self.ymin, self.xmax, self.ymax = minmaxform
3334

geonode/base/forms.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def rectree(parent, path):
6262
children_list_of_tuples.append(
6363
tuple((path + parent.name, tuple((child.id, child.name))))
6464
)
65-
childrens = rectree(child, parent.name + '/')
65+
childrens = rectree(child, f"{parent.name}/")
6666
if childrens:
6767
children_list_of_tuples.extend(childrens)
6868

@@ -105,10 +105,10 @@ def _get_choices(self):
105105

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

113113

114114
# NOTE: This is commented as it needs updating to work with select2 and autocomlete light.
@@ -276,7 +276,7 @@ def _region_id_from_choice(choice):
276276
class CategoryForm(forms.Form):
277277
category_choice_field = CategoryChoiceField(
278278
required=False,
279-
label='*' + _('Category'),
279+
label=f"*{_('Category')}",
280280
empty_label=None,
281281
queryset=TopicCategory.objects.filter(
282282
is_choice=True).extra(

geonode/base/management/commands/load_thesaurus.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ def load_thesaurus(self, input_file, name, store):
7474
RDF_URI = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
7575
XML_URI = 'http://www.w3.org/XML/1998/namespace'
7676

77-
ABOUT_ATTRIB = '{' + RDF_URI + '}about'
78-
LANG_ATTRIB = '{' + XML_URI + '}lang'
77+
ABOUT_ATTRIB = f"{{{RDF_URI}}}about"
78+
LANG_ATTRIB = f"{{{XML_URI}}}lang"
7979

8080
ns = {
8181
'rdf': RDF_URI,
@@ -161,7 +161,7 @@ def create_fake_thesaurus(self, name):
161161
thesaurus = Thesaurus()
162162
thesaurus.identifier = name
163163

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

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

177177
for _l in ['it', 'en', 'es']:
178178
tkl = ThesaurusKeywordLabel()
179179
tkl.keyword = tk
180180
tkl.lang = _l
181-
tkl.label = keyword + "_l_" + _l + "_t_" + name
181+
tkl.label = f"{keyword}_l_{_l}_t_{name}"
182182
tkl.save()
183183

184184

geonode/base/models.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def name_long(self):
302302
if self.abbreviation is None or len(self.abbreviation) == 0:
303303
return self.name
304304
else:
305-
return self.name + " (" + self.abbreviation + ")"
305+
return f"{self.name} ({self.abbreviation})"
306306

307307
@property
308308
def description_bullets(self):
@@ -312,7 +312,7 @@ def description_bullets(self):
312312
bullets = []
313313
lines = self.description.split("\n")
314314
for line in lines:
315-
bullets.append("+ " + line)
315+
bullets.append(f"+ {line}")
316316
return bullets
317317

318318
class Meta:
@@ -959,7 +959,7 @@ def save(self, notify=False, *args, **kwargs):
959959
Send a notification when a resource is created or updated
960960
"""
961961
if not self.resource_type and self.polymorphic_ctype and \
962-
self.polymorphic_ctype.model:
962+
self.polymorphic_ctype.model:
963963
self.resource_type = self.polymorphic_ctype.model.lower()
964964

965965
if hasattr(self, 'class_name') and (self.pk is None or notify):
@@ -1157,20 +1157,20 @@ def license_light(self):
11571157
if self.license.name is not None and (len(self.license.name) > 0):
11581158
a.append(self.license.name)
11591159
if self.license.url is not None and (len(self.license.url) > 0):
1160-
a.append("(" + self.license.url + ")")
1160+
a.append(f"({self.license.url})")
11611161
return " ".join(a)
11621162

11631163
@property
11641164
def license_verbose(self):
11651165
a = []
11661166
if self.license.name_long is not None and (
11671167
len(self.license.name_long) > 0):
1168-
a.append(self.license.name_long + ":")
1168+
a.append(f"{self.license.name_long}:")
11691169
if self.license.description is not None and (
11701170
len(self.license.description) > 0):
11711171
a.append(self.license.description)
11721172
if self.license.url is not None and (len(self.license.url) > 0):
1173-
a.append("(" + self.license.url + ")")
1173+
a.append(f"({self.license.url})")
11741174
return " ".join(a)
11751175

11761176
@property

geonode/base/populate_test_data.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -319,13 +319,13 @@ def dump_models(path=None):
319319

320320
def create_single_layer(name):
321321
get_user_model().objects.create(
322-
username='admin',
323-
is_superuser=True,
324-
first_name='admin')
322+
username='admin',
323+
is_superuser=True,
324+
first_name='admin')
325325
test_datetime = datetime.strptime('2020-01-01', '%Y-%m-%d')
326326
user = get_user_model().objects.get(username='AnonymousUser')
327327
ll = (name, 'lorem ipsum', name, f'geonode:{name}', [
328-
0, 22, 0, 22], test_datetime, ('populartag',), "farming")
328+
0, 22, 0, 22], test_datetime, ('populartag',), "farming")
329329
title, abstract, name, alternate, (bbox_x0, bbox_x1, bbox_y0, bbox_y1), start, kws, category = ll
330330
layer = Layer(
331331
title=title,

geonode/base/templatetags/base_tags.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def _has_owner_his_permissions():
407407
_owner_set == set(['change_resourcebase_permissions', 'publish_resourcebase'])
408408

409409
if not _has_owner_his_permissions() and \
410-
(user.is_superuser or resource.owner.pk == user.pk):
410+
(user.is_superuser or resource.owner.pk == user.pk):
411411
return True
412412
return False
413413

geonode/base/templatetags/user_messages.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ def get_item(dictionary, key):
7878
def show_notification(notice_type_label, current_user):
7979
adms_notice_types = getattr(settings, 'ADMINS_ONLY_NOTICE_TYPES', [])
8080
if not current_user.is_superuser and adms_notice_types and \
81-
notice_type_label in adms_notice_types:
81+
notice_type_label in adms_notice_types:
8282
return False
8383
return True

geonode/base/utils.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,9 @@ def remove_duplicate_links(resource):
9898
if isinstance(resource, Layer):
9999
# fixup Legend links
100100
layer = resource
101-
legend_url_template = \
102-
ogc_server_settings.PUBLIC_LOCATION + \
103-
'ows?service=WMS&request=GetLegendGraphic&format=image/png&WIDTH=20&HEIGHT=20&LAYER=' + \
104-
'{alternate}&STYLE={style_name}' + \
105-
'&legend_options=fontAntiAliasing:true;fontSize:12;forceLabels:on'
101+
legend_url_template = (f"{ogc_server_settings.PUBLIC_LOCATION}ows?"
102+
"service=WMS&request=GetLegendGraphic&format=image/png&WIDTH=20&HEIGHT=20&"
103+
f"LAYER={{alternate}}&STYLE={{style_name}}&legend_options=fontAntiAliasing:true;fontSize:12;forceLabels:on")
106104
if layer.default_style and not layer.get_legend_url(style_name=layer.default_style.name):
107105
Link.objects.update_or_create(
108106
resource=layer.resourcebase_ptr,

geonode/br/management/commands/backup.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def execute_backup(self, **options):
193193
# skip dumping of static files of apps not located under LOCAL_ROOT path
194194
# (check to prevent saving files from site-packages in project-template based GeoNode projects)
195195
if getattr(settings, 'LOCAL_ROOT', None) and \
196-
not static_files_folder.startswith(settings.LOCAL_ROOT):
196+
not static_files_folder.startswith(settings.LOCAL_ROOT):
197197
print(f"Skipping static directory: {static_files_folder}. "
198198
f"It's not located under LOCAL_ROOT path: {settings.LOCAL_ROOT}.")
199199
continue
@@ -225,7 +225,7 @@ def execute_backup(self, **options):
225225
# skip dumping of template files of apps not located under LOCAL_ROOT path
226226
# (check to prevent saving files from site-packages in project-template based GeoNode projects)
227227
if getattr(settings, 'LOCAL_ROOT', None) and \
228-
not template_files_folder.startswith(settings.LOCAL_ROOT):
228+
not template_files_folder.startswith(settings.LOCAL_ROOT):
229229
print(f"Skipping template directory: {template_files_folder}. "
230230
f"It's not located under LOCAL_ROOT path: {settings.LOCAL_ROOT}.")
231231
continue
@@ -250,7 +250,7 @@ def execute_backup(self, **options):
250250
# skip dumping of locale files of apps not located under LOCAL_ROOT path
251251
# (check to prevent saving files from site-packages in project-template based GeoNode projects)
252252
if getattr(settings, 'LOCAL_ROOT', None) and \
253-
not locale_files_folder.startswith(settings.LOCAL_ROOT):
253+
not locale_files_folder.startswith(settings.LOCAL_ROOT):
254254
logger.info(f"Skipping locale directory: {locale_files_folder}. "
255255
f"It's not located under LOCAL_ROOT path: {settings.LOCAL_ROOT}.")
256256
continue
@@ -306,8 +306,7 @@ def create_geoserver_backup(self, config, settings, target_folder, ignore_errors
306306
if r.status_code != 200:
307307
raise ValueError('Could not reload GeoServer catalog!')
308308

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

312311
_options = [
313312
'BK_CLEANUP_TEMP=true',

geonode/br/management/commands/restore.py

+8-12
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ def execute_restore(self, **options):
358358
# Restore Fixtures
359359
abortlater = False
360360
for app_name, dump_name in zip(config.app_names, config.dump_names):
361-
fixture_file = os.path.join(target_folder, dump_name+'.json')
361+
fixture_file = os.path.join(target_folder, f"{dump_name}.json")
362362

363363
print(f"Deserializing '{fixture_file}'")
364364
try:
@@ -405,7 +405,7 @@ def execute_restore(self, **options):
405405
# (check to prevent overriding files from site-packages
406406
# in project-template based GeoNode projects)
407407
if getattr(settings, 'LOCAL_ROOT', None) and \
408-
not static_files_folder.startswith(settings.LOCAL_ROOT):
408+
not static_files_folder.startswith(settings.LOCAL_ROOT):
409409
print(
410410
f"Skipping static directory: {static_files_folder}. "
411411
f"It's not located under LOCAL_ROOT path: {settings.LOCAL_ROOT}.")
@@ -430,7 +430,7 @@ def execute_restore(self, **options):
430430
# (check to prevent overriding files from site-packages
431431
# in project-template based GeoNode projects)
432432
if getattr(settings, 'LOCAL_ROOT', None) and \
433-
not template_files_folder.startswith(settings.LOCAL_ROOT):
433+
not template_files_folder.startswith(settings.LOCAL_ROOT):
434434
print(
435435
f"Skipping template directory: {template_files_folder}. "
436436
f"It's not located under LOCAL_ROOT path: {settings.LOCAL_ROOT}.")
@@ -455,7 +455,7 @@ def execute_restore(self, **options):
455455
# (check to prevent overriding files from site-packages
456456
# in project-template based GeoNode projects)
457457
if getattr(settings, 'LOCAL_ROOT', None) and \
458-
not locale_files_folder.startswith(settings.LOCAL_ROOT):
458+
not locale_files_folder.startswith(settings.LOCAL_ROOT):
459459
print(
460460
f"Skipping locale directory: {locale_files_folder}. "
461461
f"It's not located under LOCAL_ROOT path: {settings.LOCAL_ROOT}.")
@@ -663,8 +663,7 @@ def restore_geoserver_backup(self, config, settings, target_folder,
663663
}
664664
r = requests.post(f'{url}rest/br/restore/', data=json.dumps(data),
665665
headers=headers, auth=HTTPBasicAuth(user, passwd))
666-
error_backup = 'Could not successfully restore GeoServer ' + \
667-
'catalog [{}rest/br/restore/]: {} - {}'
666+
error_backup = "Could not successfully restore GeoServer catalog [{{}}rest/br/restore/]: {{}} - {{}}"
668667

669668
if r.status_code in (200, 201, 406):
670669
try:
@@ -761,8 +760,7 @@ def restore_geoserver_raster_data(self, config, settings, target_folder):
761760
copy_tree(gs_data_folder, gs_data_root)
762761
print(f"GeoServer Uploaded Raster Data Restored to '{gs_data_root}'.")
763762
else:
764-
print(('Skipping geoserver raster data restore: ' +
765-
f'directory "{gs_data_folder}" not found.'))
763+
print(f"Skipping geoserver raster data restore: directory \"{gs_data_folder}\" not found.")
766764

767765
# Restore '$config.gs_data_dir/data/geonode'
768766
gs_data_folder = os.path.join(target_folder, 'gs_data_dir', 'data', 'geonode')
@@ -777,17 +775,15 @@ def restore_geoserver_raster_data(self, config, settings, target_folder):
777775
copy_tree(gs_data_folder, gs_data_root)
778776
print(f"GeoServer Uploaded Data Restored to '{gs_data_root}'.")
779777
else:
780-
print(('Skipping geoserver raster data restore: ' +
781-
f'directory "{gs_data_folder}" not found.'))
778+
print(f"Skipping geoserver raster data restore: directory \"{gs_data_folder}\" not found.")
782779

783780
def restore_geoserver_vector_data(self, config, settings, target_folder, soft_reset):
784781
"""Restore Vectorial Data from DB"""
785782
if (config.gs_dump_vector_data):
786783

787784
gs_data_folder = os.path.join(target_folder, 'gs_data_dir', 'geonode')
788785
if not os.path.exists(gs_data_folder):
789-
print(('Skipping geoserver vector data restore: ' +
790-
f'directory "{gs_data_folder}" not found.'))
786+
print(f"Skipping geoserver vector data restore: directory \"{gs_data_folder}\" not found.")
791787
return
792788

793789
datastore = settings.OGC_SERVER['default']['DATASTORE']

0 commit comments

Comments
 (0)