Changeset 947


Ignore:
Timestamp:
27 Nov 2006, 09:39:30 (18 years ago)
Author:
joachim
Message:

import all Pin-Batches from dir import/pins

File:
1 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/trunk/ScratchCards.py

    r805 r947  
    1313import DateTime
    1414import Globals
     15import logging
     16import os,csv,re
     17import Globals
     18MAX_TRANS = 1000
    1519p_home = Globals.package_home(globals())
    1620i_home = Globals.INSTANCE_HOME
     
    2933        return "Pin Batches"
    3034
     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    ###)
    3170
    3271InitializeClass(ScratchCardBatchesFolder)
     
    84123    ###)
    85124
     125
    86126    security.declareProtected(ModifyPortalContent,"getUnusedPins")
    87127    def getUnusedPins(self):
Note: See TracChangeset for help on using the changeset viewer.