pytask/utils.py
author Nishanth Amuluru <nishanth@fossee.in>
Tue, 11 Jan 2011 12:30:10 +0530
changeset 140 8fcde6f8f750
parent 69 c6bca38c1cbf
permissions -rw-r--r--
added view_user functionality
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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