Adding the ability to choose upper or lower case ID generation
This commit is contained in:
parent
71a4ad4a65
commit
126af19e87
2 changed files with 10 additions and 4 deletions
|
@ -10,4 +10,5 @@ Shortener:
|
||||||
# Even though this guarantees that the ID doesn't exist, this might inflict
|
# Even though this guarantees that the ID doesn't exist, this might inflict
|
||||||
# some performance hit.
|
# some performance hit.
|
||||||
check_duplicate_id: False
|
check_duplicate_id: False
|
||||||
id_length: 32
|
id_length: 32
|
||||||
|
id_upper_case: False
|
|
@ -11,21 +11,26 @@ class Shortener:
|
||||||
self.uuid = None
|
self.uuid = None
|
||||||
self.length = 32
|
self.length = 32
|
||||||
self.check_duplicate = False
|
self.check_duplicate = False
|
||||||
|
self.upper_case = False
|
||||||
self.configuration = configuration
|
self.configuration = configuration
|
||||||
self.init()
|
self.init()
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
length = self.configuration.get('id_length', 32)
|
length = self.configuration.get("id_length", 32)
|
||||||
if length >= 32 or length <= 0:
|
if length >= 32 or length <= 0:
|
||||||
self.length = 32
|
self.length = 32
|
||||||
else:
|
else:
|
||||||
self.length = length
|
self.length = length
|
||||||
self.check_duplicate = self.configuration.get(
|
self.check_duplicate = self.configuration.get(
|
||||||
'check_duplicate_id', False)
|
"check_duplicate_id", False)
|
||||||
|
self.upper_case = self.configuration.get(
|
||||||
|
"id_upper_case", False)
|
||||||
|
|
||||||
def generate_short_uuid(self):
|
def generate_short_uuid(self):
|
||||||
short_uuid = uuid.uuid1().hex
|
short_uuid = uuid.uuid1().hex
|
||||||
return short_uuid.upper()[0:self.length]
|
if self.upper_case:
|
||||||
|
return short_uuid.upper()[0:self.length]
|
||||||
|
return short_uuid.lower()[0:self.length]
|
||||||
|
|
||||||
def check_uuid(self, short_uuid):
|
def check_uuid(self, short_uuid):
|
||||||
with Document(self.pointer_db, 'pointer') as pointer:
|
with Document(self.pointer_db, 'pointer') as pointer:
|
||||||
|
|
Loading…
Add table
Reference in a new issue