source: WAeUP_SRP/trunk/ScratchCards.py @ 605

Last change on this file since 605 was 535, checked in by joachim, 18 years ago

student apply admission should work now
the default_view for campus is now home_index.py
for students and student student_index.py
these script redirect to the appropriate PT

File size: 3.8 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
13import DateTime
14import Globals
15p_home = Globals.package_home(globals())
16i_home = Globals.INSTANCE_HOME
17
18class ScratchCardBatchesFolder(CPSDocument): ###(
19    """
20    WAeUP Student container for the various student data
21    """
22    meta_type = 'ScratchCardBatchesFolder'
23    portal_type = meta_type
24    security = ClassSecurityInfo()
25
26    security.declareProtected(View,"Title")
27    def Title(self):
28        """compose title"""
29        return "Pin Batches"
30
31
32InitializeClass(ScratchCardBatchesFolder)
33
34def addScratchCardBatchesFolder(container, id, REQUEST=None, **kw):
35    """Add a Students personal data."""
36    ob = ScratchCardBatchesFolder(id, **kw)
37    return CPSBase_adder(container, ob, REQUEST=REQUEST)
38
39###)
40
41from Products.WAeUP_SRP.WAeUPTables import PinTable
42
43class ScratchCardBatch(CPSDocument): ###(
44    """
45    WAeUP Student container for the various student data
46    """
47    meta_type = 'ScratchCardBatch'
48    portal_type = meta_type
49    security = ClassSecurityInfo()
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        prefix = batch.prefix
63        sold = batch.sold_by
64        cost = batch.cost
65        import random
66        r = random
67        b_no = batch.batch_no
68        #import pdb;pdb.set_trace()
69        generated = []
70        generated.append('"Serial","Pin","Sold","Cost"' % vars())
71        generated.append('"%(prefix)s","%(b_no)d","%(sold)s","%(cost)f"' % vars())
72        pins = self.portal_pins
73        for i in range(nr):
74            ri = r.randint(1000000000,9999999999)
75            pin = "%s%d%d" % (prefix,b_no,ri)
76            while len(pins.searchResults({'pin': pin})) > 0:
77                ri = r.randint(1000000000,9999999999)
78                pin = "%s%d%d" % (prefix,b_no,ri)
79            pins.addRecord(pin=pin,serial=i,student="",prefix_batch="%s%d" % (prefix, b_no))
80            generated.append('"%(i)d","%(prefix)s-%(b_no)d-%(ri)d"' % vars())
81        print '\n'.join(generated)
82        current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S")
83        open("%s/import/%s-%s-%s" % (i_home,prefix,b_no,current),"w+").write('\n'.join(generated))
84    ###)
85
86    security.declareProtected(ModifyPortalContent,"getUnusedPins")
87    def getUnusedPins(self):
88        """return a list of unused Pins"""
89        max_pins = 30
90        #import pdb;pdb.set_trace()
91        pins_cat = self.portal_pins
92        doc = self.getContent()
93        l = [{'pin': p.pin,
94              'serial': p.serial,
95              } for p in pins_cat.searchResults(prefix_batch = "%s%d"
96                                               % (doc.prefix,doc.batch_no),
97                                               ) if p.student == '']
98        if len (l) <= max_pins:
99            return l
100        return l[:max_pins]
101
102InitializeClass(ScratchCardBatch)
103
104def addScratchCardBatch(container, id, REQUEST=None, **kw):
105    """Add a Students personal data."""
106    ob = ScratchCardBatch(id, **kw)
107    return CPSBase_adder(container, ob, REQUEST=REQUEST)
108
109###)
Note: See TracBrowser for help on using the repository browser.