From 817428ea1f61e6546bf004cf7d697757580e42a2 Mon Sep 17 00:00:00 2001 From: Laetitia Getti Date: Thu, 10 Aug 2023 11:10:47 +0200 Subject: [PATCH] Precise comments in create_code function --- la_chariotte/order/models.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/la_chariotte/order/models.py b/la_chariotte/order/models.py index b5fc867..0b72c1c 100644 --- a/la_chariotte/order/models.py +++ b/la_chariotte/order/models.py @@ -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):