Changeset 947
- Timestamp:
- 27 Nov 2006, 09:39:30 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/trunk/ScratchCards.py
r805 r947 13 13 import DateTime 14 14 import Globals 15 import logging 16 import os,csv,re 17 import Globals 18 MAX_TRANS = 1000 15 19 p_home = Globals.package_home(globals()) 16 20 i_home = Globals.INSTANCE_HOME … … 29 33 return "Pin Batches" 30 34 35 security.declareProtected(ModifyPortalContent,"importPinBatch") ###( 36 def importPinBatch(self): 37 """import PinBatch""" 38 name = "PINS" 39 logger = logging.getLogger('%s_import' % name) 40 logger.info('Start loading from %s.csv' % name) 41 pins_section = self.portal_url.getPortalObject().campus.pins 42 p_pins = self.portal_pins 43 base_dir = "%s/import/pins" % (i_home) 44 files = os.listdir(base_dir) 45 for fn in files: 46 pins = csv.DictReader(open("%s/import/%s" % (i_home,fn),"rb")) 47 n = 0 48 for pin in pins: 49 if n == 0: 50 bid = "%(Serial)s_%(Pin)s" % pin 51 pins_section.invokeFactory('ScratchCardBatch', bid) 52 batch = getattr(pins_section,bid) 53 dict = {} 54 prefix = pin['Serial'] 55 dict['prefix'] = pin['Serial'] 56 batch_no = pin['Pin'] 57 dict['batch_no'] = int(batch_no) 58 dict['cost'] = float(pin['Cost']) 59 dict['sold_by'] = pin['Sold'] 60 #import pdb;pdb.set_trace() 61 n += 1 62 continue 63 p_pins.addRecord(pin=pin['Pin'],serial=n,student="",prefix_batch="%s%s" % (prefix, batch_no)) 64 n += 1 65 dict['no_of_pins'] = n - 1 66 batch.getContent().edit(mapping=dict) 67 logger.info('Added %s with %d Pins' % (bid,n-1)) 68 return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) 69 ###) 31 70 32 71 InitializeClass(ScratchCardBatchesFolder) … … 84 123 ###) 85 124 125 86 126 security.declareProtected(ModifyPortalContent,"getUnusedPins") 87 127 def getUnusedPins(self):
Note: See TracChangeset for help on using the changeset viewer.