Skip to content

Commit

Permalink
Mitigates possibilities for error #2932
Browse files Browse the repository at this point in the history
  • Loading branch information
capooti authored and afabiani committed Oct 31, 2019
1 parent 1643283 commit 8c2c336
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
10 changes: 5 additions & 5 deletions geonode/layers/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,8 @@ def test_get_valid_name(self):
self.assertEquals(get_valid_name("blug"), "blug")
self.assertEquals(get_valid_name("<-->"), "_")
self.assertEquals(get_valid_name("<ab>"), "_ab_")
self.assertEquals(get_valid_name("CA"), "CA_1")
self.assertEquals(get_valid_name("CA"), "CA_1")
self.assertNotEquals(get_valid_name("CA"), "CA_1")
self.assertNotEquals(get_valid_name("CA"), "CA_1")

def test_get_valid_layer_name(self):
self.assertEquals(get_valid_layer_name("blug", False), "blug")
Expand All @@ -768,13 +768,13 @@ def test_get_valid_layer_name(self):
self.assertEquals(get_valid_layer_name("<-->", False), "_")
self.assertEquals(get_valid_layer_name("<-->", True), "<-->")

self.assertEquals(get_valid_layer_name("CA", False), "CA_1")
self.assertEquals(get_valid_layer_name("CA", False), "CA_1")
self.assertNotEquals(get_valid_layer_name("CA", False), "CA_1")
self.assertNotEquals(get_valid_layer_name("CA", False), "CA_1")
self.assertEquals(get_valid_layer_name("CA", True), "CA")
self.assertEquals(get_valid_layer_name("CA", True), "CA")

layer = Layer.objects.get(name="CA")
self.assertEquals(get_valid_layer_name(layer, False), "CA_1")
self.assertNotEquals(get_valid_layer_name(layer, False), "CA_1")
self.assertEquals(get_valid_layer_name(layer, True), "CA")

self.assertRaises(GeoNodeException, get_valid_layer_name, 12, False)
Expand Down
8 changes: 5 additions & 3 deletions geonode/layers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import re
import os
import glob
import string
import sys
import logging
import tarfile
Expand All @@ -33,6 +34,7 @@
from urlparse import urlparse
from zipfile import ZipFile, is_zipfile
from datetime import datetime
from random import choice

# Django functionality
from django.contrib.auth import get_user_model
Expand Down Expand Up @@ -279,10 +281,10 @@ def get_valid_name(layer_name):
"""
name = _clean_string(layer_name)
proposed_name = name
count = 1
while Layer.objects.filter(name=proposed_name).exists():
proposed_name = "%s_%d" % (name, count)
count = count + 1
possible_chars = string.ascii_lowercase + string.digits
suffix = "".join([choice(possible_chars) for i in range(4)])
proposed_name = '%s_%s' % (name, suffix)
logger.warning('Requested name already used; adjusting name '
'[%s] => [%s]', layer_name, proposed_name)
else:
Expand Down
4 changes: 2 additions & 2 deletions geonode/locale/ar/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -6266,8 +6266,8 @@ msgid "GeoNode is an open source platform for sharing geospatial data and maps."
msgstr "GeoNode هو منصة مفتوحة المصدر لتبادل البيانات الجغرافية والخرائط."

#: geonode/templates/index.html:23
msgid "http://docs.geonode.org/en/2.10.x/usage"
msgstr "http://docs.geonode.org/en/2.10.x/usage"
msgid "http://docs.geonode.org/en/2.10.x/usage/index.html"
msgstr "http://docs.geonode.org/en/2.10.x/usage/index.html"

#: geonode/templates/index.html:23
msgid "Get Started &raquo;"
Expand Down

0 comments on commit 8c2c336

Please sign in to comment.