mirror of
https://framagit.org/la-chariotte/la-chariotte.git
synced 2025-05-02 03:42:26 +02:00
Precise comments in create_code function
This commit is contained in:
parent
cb2373020e
commit
817428ea1f
1 changed files with 6 additions and 1 deletions
|
@ -34,11 +34,16 @@ class GroupedOrder(models.Model):
|
||||||
2. A random int written in base36 (5 digits long)
|
2. A random int written in base36 (5 digits long)
|
||||||
3. Only the 6 first digits of this string
|
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.
|
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)
|
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_string = base36.dumps(
|
||||||
random.randint(pow(36, CODE_LENGTH - 2), pow(36, CODE_LENGTH - 1) - 1)
|
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]
|
self.code = f"{base_36_pk}{random_string}"[:CODE_LENGTH]
|
||||||
|
|
||||||
def compute_total_price(self):
|
def compute_total_price(self):
|
||||||
|
|
Loading…
Reference in a new issue