Changeset 8321


Ignore:
Timestamp:
2 May 2012, 06:24:42 (13 years ago)
Author:
Henrik Bettermann
Message:

We have to store the cost in AccessCode? not only in AccessCodeBatches?. We need this for access code slips in students.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/accesscodes
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/accesscodes/accesscode.py

    r8194 r8321  
    8585        self.random_num = random_num
    8686        self.owner = None
     87        self.cost = None
    8788        IWorkflowInfo(self).fireTransition('init')
    8889
     
    119120        return self.batch.num
    120121
    121     @property
    122     def cost(self):
    123         """A float representing the price or ``None``. A read-only attribute.
    124         """
    125         if self.batch is None:
    126             return None
    127         return self.batch.cost
     122    #@property
     123    #def cost(self):
     124    #    """A float representing the price or ``None``. A read-only attribute.
     125    #    """
     126    #    if self.batch is None:
     127    #        return None
     128    #    return self.batch.cost
    128129
    129130    @property
     
    167168        """
    168169        for num, pin in enumerate(self.getNewRandomNum(num=self.entry_num)):
    169             self.addAccessCode(num, pin)
     170            self.addAccessCode(num, pin, self.cost)
    170171        return
    171172
     
    200201        return self[ac_id]
    201202
    202     def addAccessCode(self, num, pin, owner=None):
     203    def addAccessCode(self, num, pin, cost=0.0, owner=None):
    203204        """Add an access-code.
    204205        """
     
    206207        if owner:
    207208            ac.owner = owner
     209        ac.cost = cost
    208210        ac.__parent__ = self
    209211        self[ac.representation] = ac
     
    255257            )
    256258        writer = csv.writer(open(csv_path, 'w'), quoting=csv.QUOTE_ALL)
    257         writer.writerow(['prefix', 'serial', 'ac', 'state', 'history'])
     259        writer.writerow(['prefix', 'serial', 'ac', 'state', 'history', 'cost'])
    258260        writer.writerow([self.prefix, '%0.2f' % self.cost, str(self.num),
    259261                         str(self.entry_num)])
     
    264266            writer.writerow([
    265267                    self.prefix, value.batch_serial, value.representation,
    266                     value.state, value.history
     268                    value.state, value.history, value.cost
    267269                    ])
    268270        return os.path.basename(csv_path)
     
    363365            pin = row['ac']
    364366            serial = int(row['serial'])
     367            try:
     368                cost = float(row['cost'])
     369            except ValueError:
     370                cost = 0.0
    365371            rand_num = pin.rsplit('-', 1)[-1]
    366             batch.addAccessCode(serial, rand_num)
     372            batch.addAccessCode(serial, rand_num, cost)
    367373            num_entries += 1
    368374        batch.entry_num = num_entries
    369 
    370375        batch.createCSVLogFile()
    371376        return
  • main/waeup.kofa/trunk/src/waeup/kofa/accesscodes/browser.txt

    r7819 r8321  
    438438    ...                             sorted(os.listdir(ac_storage))[-2])
    439439    >>> print open(archive_file, 'rb').read()
    440     "prefix","serial","ac","state","history"
     440    "prefix","serial","ac","state","history","cost"
    441441    "BLA","19.12","1","3"
    442     "BLA","0","BLA-1-<10-DIGITS>","initialized","..."
    443     "BLA","1","BLA-1-<10-DIGITS>","initialized","..."
    444     "BLA","2","BLA-1-<10-DIGITS>","initialized","..."
     442    "BLA","0","BLA-1-<10-DIGITS>","initialized","...","19.12"
     443    "BLA","1","BLA-1-<10-DIGITS>","initialized","...","19.12"
     444    "BLA","2","BLA-1-<10-DIGITS>","initialized","...","19.12"
    445445
    446446Clean up:
  • main/waeup.kofa/trunk/src/waeup/kofa/accesscodes/interfaces.py

    r8172 r8321  
    4040    cost = schema.Float(
    4141        title = _(u'Cost of access code'),
    42         default = 0.0, min = 0.0,
    4342        )
    4443    state = schema.TextLine(
  • main/waeup.kofa/trunk/src/waeup/kofa/accesscodes/tests/sample_import.csv

    r6543 r8321  
    1 "prefix","serial","ac","state","history"
    2 "FOO","9.99","1","0"
    3 "FOO","0","FOO-1-11111111","used","2011-06-01 12:12:14 - AC initialized by system||2011-06-01 12:14:14 - comment with ""quotes"" by system"
    4 "FOO","1","FOO-1-22222222","initialized","2011-05-30 21:10:12 - AC initialized by system"
    5 "FOO","2","FOO-1-33333333","disabled","2012-05-30 21:12:10 - AC initialized by system||2012-05-30 23:10:10 - AC disabled by system"
     1"prefix","serial","ac","state","history","cost"
     2"FOO","9.99","1","0",""
     3"FOO","0","FOO-1-11111111","used","2011-06-01 12:12:14 - AC initialized by system||2011-06-01 12:14:14 - comment with ""quotes"" by system","1000.0"
     4"FOO","1","FOO-1-22222222","initialized","2011-05-30 21:10:12 - AC initialized by system",""
     5"FOO","2","FOO-1-33333333","disabled","2012-05-30 21:12:10 - AC initialized by system||2012-05-30 23:10:10 - AC disabled by system",""
  • main/waeup.kofa/trunk/src/waeup/kofa/accesscodes/tests/test_accesscode.py

    r8234 r8321  
    238238
    239239    def test_cost(self):
    240         # We get the cost set in batch
     240        # The cost of an access code will be stored by handle_batch_added
     241        # right after the batch has been added to the ZODB. Thus after
     242        # creation of the batch, cost is still 0.0
    241243        cost = self.ac1.cost
    242         assert cost == 6.6
     244        assert cost == 0.0
    243245
    244246class AccessCodeBatchTests(FunctionalTestCase):
     
    264266
    265267        self.ac1 = AccessCode(0, '11111111')
     268        self.ac1.cost = 2345.0
    266269        self.ac2 = AccessCode(1, '22222222')
    267270        self.ac3 = AccessCode(2, '33333333')
     
    298301        result_path = os.path.join(batch._getStoragePath(), basename)
    299302        expected = '''
    300 "prefix","serial","ac","state","history"
     303"prefix","serial","ac","state","history","cost"
    301304"FOO","9.99","1","0"
    302 "FOO","0","FOO-1-11111111","used","<YYYY-MM-DD hh:mm:ss> UTC - ..."
    303 "FOO","1","FOO-1-22222222","initialized","<YYYY-MM-DD hh:mm:ss> UTC - ..."
    304 "FOO","2","FOO-1-33333333","disabled","<YYYY-MM-DD hh:mm:ss> UTC - ..."
     305"FOO","0","FOO-1-11111111","used","<YYYY-MM-DD hh:mm:ss> UTC - ...","2345.0"
     306"FOO","1","FOO-1-22222222","initialized","<YYYY-MM-DD hh:mm:ss> UTC - ...",""
     307"FOO","2","FOO-1-33333333","disabled","<YYYY-MM-DD hh:mm:ss> UTC - ...",""
    305308'''[1:]
    306309        contents = open(result_path, 'rb').read()
     
    366369            keys,
    367370            [u'FOO-1-11111111', u'FOO-1-22222222', u'FOO-1-33333333'])
     371        # Also cost has been stored correctly
     372        self.assertEqual(batch['FOO-1-11111111'].cost,1000.0)
    368373
    369374    def test_getAccessCode(self):
  • main/waeup.kofa/trunk/src/waeup/kofa/accesscodes/tests/test_catalog.py

    r7811 r8321  
    6060        self.ac2 = batch.getAccessCode('APP-1-22222222')
    6161        self.ac3 = batch.getAccessCode('APP-1-33333333')
    62 
    63 
    6462        return
    6563
Note: See TracChangeset for help on using the changeset viewer.