Renamed the variables used in the stored_post utility in the Mia core application.

This commit is contained in:
依瑪貓 2020-08-09 13:53:47 +08:00
parent 19ea58e7a3
commit 006c817609

View File

@ -71,26 +71,26 @@ def _store(request, post):
""" """
if STORAGE_KEY not in request.session: if STORAGE_KEY not in request.session:
request.session[STORAGE_KEY] = {} request.session[STORAGE_KEY] = {}
id = _new_post_id(request.session[STORAGE_KEY]) post_id = _new_post_id(request.session[STORAGE_KEY])
request.session[STORAGE_KEY][id] = post request.session[STORAGE_KEY][post_id] = post
return id return post_id
def _retrieve(request, id): def _retrieve(request, post_id):
"""Retrieves the POST data from the storage. """Retrieves the POST data from the storage.
Args: Args:
request (HttpRequest): The request. request (HttpRequest): The request.
id (str): The POST data ID. post_id (str): The POST data ID.
Returns: Returns:
dict: The POST data, or None if the corresponding data does not exist. dict: The POST data, or None if the corresponding data does not exist.
""" """
if STORAGE_KEY not in request.session: if STORAGE_KEY not in request.session:
return None return None
if id not in request.session[STORAGE_KEY]: if post_id not in request.session[STORAGE_KEY]:
return None return None
return request.session[STORAGE_KEY][id] return request.session[STORAGE_KEY][post_id]
def _new_post_id(post_store): def _new_post_id(post_store):
@ -103,16 +103,16 @@ def _new_post_id(post_store):
str: The newly-generated POST ID. str: The newly-generated POST ID.
""" """
while True: while True:
id = "" post_id = ""
while len(id) < 16: while len(post_id) < 16:
n = random.randint(1, 64) n = random.randint(1, 64)
if n < 26: if n < 26:
id = id + chr(ord("a") + n) post_id = post_id + chr(ord("a") + n)
elif n < 52: elif n < 52:
id = id + chr(ord("a") + (n - 26)) post_id = post_id + chr(ord("a") + (n - 26))
elif n < 62: elif n < 62:
id = id + chr(ord("0") + (n - 52)) post_id = post_id + chr(ord("0") + (n - 52))
else: else:
id = id + "-_."[n - 62] post_id = post_id + "-_."[n - 62]
if id not in post_store: if post_id not in post_store:
return id return post_id