From 2cedfb9a8553d92a288c3ee319b58fba87fe3550 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Sun, 15 Sep 2019 16:35:43 +0200 Subject: TinyUrl: fix decode --- ishtar_common/models.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'ishtar_common/models.py') diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 66de551da..64c8a14f2 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1039,6 +1039,7 @@ class HierarchicalType(GeneralType): class TinyUrl(models.Model): CHAR_MAP = string.ascii_letters + string.digits + CHAR_MAP_LEN = len(CHAR_MAP) link = models.URLField() @classmethod @@ -1049,8 +1050,8 @@ class TinyUrl(models.Model): c_id = self.id digits = [] while c_id > 0: - digits.append(c_id % 62) - c_id //= 62 + digits.append(c_id % self.CHAR_MAP_LEN) + c_id //= self.CHAR_MAP_LEN digits.reverse() return self.index_to_char(digits) @@ -1058,7 +1059,7 @@ class TinyUrl(models.Model): def decode_id(cls, value): i = 0 for c in value: - i = i * 64 + cls.CHAR_MAP.index(c) + i = i * self.CHAR_MAP_LEN + cls.CHAR_MAP.index(c) return i -- cgit v1.2.3