Ignore:
Timestamp:
24 Oct 2011, 10:23:11 (13 years ago)
Author:
Henrik Bettermann
Message:

Implement purchase_accesscode function which creates access codes for student online payments (tests will follow).

File:
1 edited

Legend:

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

    r6933 r6936  
    143143        """Create the entries for this batch.
    144144        """
    145         for num, pin in enumerate(self._getNewRandomNum(num=self.entry_num)):
     145        for num, pin in enumerate(self.getNewRandomNum(num=self.entry_num)):
    146146            self.addAccessCode(num, pin)
    147147        return
    148148
    149     def _getNewRandomNum(self, num=1):
     149    def getNewRandomNum(self, num=1):
    150150        """Create a set of ``num`` random numbers of 10 digits each.
    151151
     
    177177        return self[ac_id]
    178178
    179     def addAccessCode(self, num, pin):
     179    def addAccessCode(self, num, pin, owner=None):
    180180        """Add an access-code.
    181181        """
    182182        ac = AccessCode(num, pin)
     183        if owner:
     184            ac.owner = owner
    183185        ac.__parent__ = self
    184186        self[ac.representation] = ac
     
    546548    """
    547549    return fire_transition(access_code, 'reenable', comment=comment)
     550
     551def purchase_accesscode(batch_prefix, batch_num, owner):
     552    """
     553    """
     554    batch_id = '%s-%s' % (batch_prefix, batch_num)
     555    try:
     556        batch = grok.getSite()['accesscodes'][batch_id]
     557    except KeyError:
     558        return None, u'No activation code available.'
     559    rand_num = list(batch.getNewRandomNum())[0]
     560    #import pdb; pdb.set_trace()
     561    num = len(batch) + 1
     562    batch.addAccessCode(num, rand_num, owner)
     563    pin = u'%s-%s-%s' % (batch_prefix,batch_num,rand_num)
     564    return pin, None
Note: See TracChangeset for help on using the changeset viewer.