-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
52 lines (40 loc) · 1.33 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- coding: utf-8 -*-
from pyjon.reports import ReportFactory
import random
import os
import string
PATH_CURRENT = os.path.dirname(os.path.abspath(__file__))
def main():
factory = ReportFactory()
name = "tombola"
nombre_ticket = 400
# name = "repas"
template = os.path.join(PATH_CURRENT, 'template', "%s.xml" % name)
datas = []
num_random = generate_numbers(nombre_ticket)
for item in xrange(nombre_ticket):
datas.append({'numero': item + 1,
'num_rand': num_random.next()})
factory.render_template(
template_file=template,
title=u'tickets',
data=datas,
path_current = PATH_CURRENT)
factory.render_document('%s.pdf' % name)
factory.cleanup()
def generate_numbers(occurence):
"""Génére une liste de code unique de la forme
CCCLL avec c chiffre et s une lettre"""
l_numbers = []
for item in xrange(occurence):
control = True
while control:
start_num = str(random.randint(0, 999)).rjust(3, "0")
end_num = "".join([string.letters[random.randint(0, 25)] for item in range(0,2)])
num = start_num + end_num
if not num in l_numbers:
yield num
control = False
# return l_numbers
if __name__ == '__main__':
main()