Adding the ability to choose upper or lower case ID generation

This commit is contained in:
Elia El Lazkani 2019-10-13 16:42:49 +02:00
parent 71a4ad4a65
commit 126af19e87
2 changed files with 10 additions and 4 deletions

View file

@ -10,4 +10,5 @@ Shortener:
# Even though this guarantees that the ID doesn't exist, this might inflict
# some performance hit.
check_duplicate_id: False
id_length: 32
id_length: 32
id_upper_case: False

View file

@ -11,21 +11,26 @@ class Shortener:
self.uuid = None
self.length = 32
self.check_duplicate = False
self.upper_case = False
self.configuration = configuration
self.init()
def init(self):
length = self.configuration.get('id_length', 32)
length = self.configuration.get("id_length", 32)
if length >= 32 or length <= 0:
self.length = 32
else:
self.length = length
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):
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):
with Document(self.pointer_db, 'pointer') as pointer: