1 | #-*- mode: python; mode: fold -*- |
---|
2 | # $Id: Students.py 472 2006-09-02 14:51:14Z henrik $ |
---|
3 | from Globals import InitializeClass |
---|
4 | from AccessControl import ClassSecurityInfo |
---|
5 | from AccessControl.SecurityManagement import newSecurityManager |
---|
6 | from zExceptions import BadRequest |
---|
7 | from Products.CMFCore.utils import UniqueObject, getToolByName |
---|
8 | from Products.CMFCore.permissions import View |
---|
9 | from Products.CMFCore.permissions import ModifyPortalContent |
---|
10 | from Products.CPSCore.CPSBase import CPSBase_adder, CPSBaseFolder |
---|
11 | #from Products.CPSCore.CPSBase import CPSBaseDocument as BaseDocument |
---|
12 | from Products.CPSDocument.CPSDocument import CPSDocument |
---|
13 | |
---|
14 | class ScratchCardBatchesFolder(CPSDocument): ###( |
---|
15 | """ |
---|
16 | WAeUP Student container for the various student data |
---|
17 | """ |
---|
18 | meta_type = 'ScratchCardBatchesFolder' |
---|
19 | portal_type = meta_type |
---|
20 | security = ClassSecurityInfo() |
---|
21 | |
---|
22 | security.declareProtected(View,"Title") |
---|
23 | def Title(self): |
---|
24 | """compose title""" |
---|
25 | return "Pin Batches" |
---|
26 | |
---|
27 | |
---|
28 | InitializeClass(ScratchCardBatchesFolder) |
---|
29 | |
---|
30 | def addScratchCardBatchesFolder(container, id, REQUEST=None, **kw): |
---|
31 | """Add a Students personal data.""" |
---|
32 | ob = ScratchCardBatchesFolder(id, **kw) |
---|
33 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
34 | |
---|
35 | ###) |
---|
36 | |
---|
37 | from Products.WAeUP_SRP.WAeUPTables import PinTable |
---|
38 | |
---|
39 | class ScratchCardBatch(CPSDocument): ###( |
---|
40 | """ |
---|
41 | WAeUP Student container for the various student data |
---|
42 | """ |
---|
43 | meta_type = 'ScratchCardBatch' |
---|
44 | portal_type = meta_type |
---|
45 | security = ClassSecurityInfo() |
---|
46 | |
---|
47 | def __init__(self,id,**kw): |
---|
48 | CPSDocument.__init__(self,id,**kw) |
---|
49 | self.table = PinTable() |
---|
50 | |
---|
51 | security.declareProtected(View,"Title") |
---|
52 | def Title(self): |
---|
53 | """compose title""" |
---|
54 | doc = self.getContent() |
---|
55 | return "Pin Batch %s BatchNo %d" % (doc.prefix, doc.batch_no) |
---|
56 | |
---|
57 | security.declareProtected(ModifyPortalContent,"makePins") |
---|
58 | def makePins(self): |
---|
59 | """generate Pins""" |
---|
60 | batch = self.getContent() |
---|
61 | nr = batch.no_of_pins |
---|
62 | import random |
---|
63 | r = random |
---|
64 | b_no = batch.batch_no |
---|
65 | for i in range(nr): |
---|
66 | pin = "%d%d" % (b_no,r.randint(999999999,1000000000)) |
---|
67 | import pdp;pdb.set_trace() |
---|
68 | while len(res) > 0: |
---|
69 | pin = "%d%d" % (b_no,r.randint(9999,1000000000)) |
---|
70 | res = self.table.searchResults(uid=pin) |
---|
71 | self.table.addRecord(pin=pin,serial=i,student="") |
---|
72 | print i,pin |
---|
73 | |
---|
74 | |
---|
75 | InitializeClass(ScratchCardBatch) |
---|
76 | |
---|
77 | def addScratchCardBatch(container, id, REQUEST=None, **kw): |
---|
78 | """Add a Students personal data.""" |
---|
79 | ob = ScratchCardBatch(id, **kw) |
---|
80 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
81 | |
---|
82 | ###) |
---|