diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-09-15 16:35:43 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-09-15 16:35:43 +0200 |
commit | 2cedfb9a8553d92a288c3ee319b58fba87fe3550 (patch) | |
tree | 4a78e8c49c9f9ed310df7b54078881161e932cf8 /ishtar_common/models.py | |
parent | e4fc8d697405762c82666d360cf1791aa8093d2a (diff) | |
download | Ishtar-2cedfb9a8553d92a288c3ee319b58fba87fe3550.tar.bz2 Ishtar-2cedfb9a8553d92a288c3ee319b58fba87fe3550.zip |
TinyUrl: fix decode
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r-- | ishtar_common/models.py | 7 |
1 files changed, 4 insertions, 3 deletions
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 |