author | Nishanth Amuluru <nishanth@fossee.in> |
Fri, 07 Jan 2011 13:00:58 +0530 | |
changeset 47 | cbb336da00bd |
parent 15 | beb830b0e744 |
permissions | -rw-r--r-- |
13
1773b48559e1
Added make_key to utils
Nishanth Amuluru <nishanth@fossee.in>
parents:
12
diff
changeset
|
1 |
import string,random |
1773b48559e1
Added make_key to utils
Nishanth Amuluru <nishanth@fossee.in>
parents:
12
diff
changeset
|
2 |
|
15
beb830b0e744
modified make_key and used it in the form
Nishanth Amuluru <nishanth@fossee.in>
parents:
13
diff
changeset
|
3 |
def make_key(model_name): |
13
1773b48559e1
Added make_key to utils
Nishanth Amuluru <nishanth@fossee.in>
parents:
12
diff
changeset
|
4 |
""" return a 10 character random key. |
1773b48559e1
Added make_key to utils
Nishanth Amuluru <nishanth@fossee.in>
parents:
12
diff
changeset
|
5 |
""" |
1773b48559e1
Added make_key to utils
Nishanth Amuluru <nishanth@fossee.in>
parents:
12
diff
changeset
|
6 |
|
15
beb830b0e744
modified make_key and used it in the form
Nishanth Amuluru <nishanth@fossee.in>
parents:
13
diff
changeset
|
7 |
while True: |
beb830b0e744
modified make_key and used it in the form
Nishanth Amuluru <nishanth@fossee.in>
parents:
13
diff
changeset
|
8 |
key = ''.join([ random.choice(string.uppercase+string.digits) for i in range(10)]) |
beb830b0e744
modified make_key and used it in the form
Nishanth Amuluru <nishanth@fossee.in>
parents:
13
diff
changeset
|
9 |
try: |
beb830b0e744
modified make_key and used it in the form
Nishanth Amuluru <nishanth@fossee.in>
parents:
13
diff
changeset
|
10 |
model_name.objects.get(uniq_key=key) |
beb830b0e744
modified make_key and used it in the form
Nishanth Amuluru <nishanth@fossee.in>
parents:
13
diff
changeset
|
11 |
except model_name.DoesNotExist: |
beb830b0e744
modified make_key and used it in the form
Nishanth Amuluru <nishanth@fossee.in>
parents:
13
diff
changeset
|
12 |
return key |
beb830b0e744
modified make_key and used it in the form
Nishanth Amuluru <nishanth@fossee.in>
parents:
13
diff
changeset
|
13 |