source: WAeUP_SRP/trunk/ScratchCards.py @ 499

Last change on this file since 499 was 490, checked in by joachim, 18 years ago

A trunk/skins/waeup_student/widget_scratch_card_pin_render.pt
M trunk/WAeUPTables.py
M trunk/ScratchCards.py

File size: 2.6 KB
Line 
1#-*- mode: python; mode: fold -*-
2# $Id: Students.py 472 2006-09-02 14:51:14Z henrik $
3from Globals import InitializeClass
4from AccessControl import ClassSecurityInfo
5from AccessControl.SecurityManagement import newSecurityManager
6from zExceptions import BadRequest
7from Products.CMFCore.utils import UniqueObject, getToolByName
8from Products.CMFCore.permissions import View
9from Products.CMFCore.permissions import ModifyPortalContent
10from Products.CPSCore.CPSBase import CPSBase_adder, CPSBaseFolder
11#from Products.CPSCore.CPSBase import CPSBaseDocument as BaseDocument
12from Products.CPSDocument.CPSDocument import CPSDocument
13
14class 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
28InitializeClass(ScratchCardBatchesFolder)
29
30def 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
37from Products.WAeUP_SRP.WAeUPTables import PinTable
38
39class 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
75InitializeClass(ScratchCardBatch)
76
77def 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###)
Note: See TracBrowser for help on using the repository browser.