def generate_short_id(self, id): if not db.WRITE_CAPABILITY: return None, None id = str(id) id_list = IdList.get_by_jid(self._jid, self._user.shard) if id in id_list.short_id_list: if not self.allow_duplicate: return None, None short_id = id_list.short_id_list.index(id) else: id_list.list_pointer += 1 id_list.list_pointer %= MAX_SHORT_ID_LIST_NUM id_list.short_id_list[id_list.list_pointer] = id IdList.set(self._jid, id_list) short_id = id_list.list_pointer short_id_str = '' t = short_id + 1 while t > 0: if t % 26: short_id_str = chr(t % 26 + 64) + short_id_str t //= 26 else: short_id_str = 'Z' + short_id_str t = t // 26 - 1 return short_id, short_id_str
def generate_short_id(id): if not db.WRITE_CAPABILITY: return None id = str(id) id_list = IdList.get_by_jid(_jid, _user.shard) if id in id_list.short_id_list: return id_list.short_id_list.index(id) else: id_list.list_pointer += 1 id_list.list_pointer %= MAX_SHORT_ID_LIST_NUM id_list.short_id_list[id_list.list_pointer] = id IdList.set(_jid, id_list) return id_list.list_pointer