Beispiel #1
0
 def generate_alpha_order_id(self, order):
     """
     Generate a unique order id which can be used to refer to an order
     within an email or over the phone.
     This must be as short as possible and is base 36 encoded.
     """
     rnd = self.get_random()
     d = decimal.Decimal(
         '%d%s' % (0 if order.id == None else order.id, ''.join(
             [unicode(rnd.randint(0, 9)) for i in range(0, 4)])))
     return base36encode(d)
Beispiel #2
0
    def generate_voucher_code(self):
        """
        Generate a unique voucher code.
        """
        found = False
        i = 0
        while not found:
            rnd = random.Random()
            d = decimal.Decimal(''.join(
                [unicode(rnd.randint(0, 9)) for i in range(0, 8)]))
            code = base36encode(d)

            found = (Voucher.objects.filter(code=code).count() == 0)

            i += 1
            if i > 10:
                raise IntegrityError(
                    'Fatal: Unable to find another unique voucher code after %d iterations!'
                    % i)
        return code
Beispiel #3
0
 def test_should_zero_with_first_letter_of_alphabet(self):
     self.assertEqual('2', base36encode(0))
Beispiel #4
0
 def test_should_respect_sign(self):
     self.assertEqual('-5V', base36encode(-123))
Beispiel #5
0
 def test_should_encode_base36(self):
     self.assertEqual('5V', base36encode(123))