Precise comments in create_code function

This commit is contained in:
Laetitia Getti 2023-08-10 11:10:47 +02:00
parent cb2373020e
commit 817428ea1f

View file

@ -34,11 +34,16 @@ class GroupedOrder(models.Model):
2. A random int written in base36 (5 digits long)
3. Only the 6 first digits of this string
The use of pk in the beginning of the string guarantees the uniqueness, and the random part makes that we cannot guess the url path.
We use this kind of code, that is small and can contain a large number of values, in order to keep it simple enough to be
manually written, so that people can share information about grouped orders more easily
"""
base_36_pk = base36.dumps(self.pk)
# generate a 5 digits long string : the random int is between 11111[in base 36] and zzzzz[in base 36],
# which are the smallest and the biggest values with 5 digits
random_string = base36.dumps(
random.randint(pow(36, CODE_LENGTH - 2), pow(36, CODE_LENGTH - 1) - 1)
) # generates a 5 digits long string
)
self.code = f"{base_36_pk}{random_string}"[:CODE_LENGTH]
def compute_total_price(self):