Changeset 6936 for main/waeup.sirp/trunk
- Timestamp:
- 24 Oct 2011, 10:23:11 (13 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/__init__.py
r6632 r6936 18 18 from waeup.sirp.accesscodes.accesscode import ( 19 19 get_access_code, invalidate_accesscode, disable_accesscode, 20 reenable_accesscode, AccessCode, AccessCodeBatch, AccessCodeBatchContainer) 20 reenable_accesscode, purchase_accesscode, 21 AccessCode, AccessCodeBatch, AccessCodeBatchContainer) 21 22 22 23 # Public API of this submodule … … 29 30 'disable_accesscode', 30 31 'reenable_accesscode', 32 'purchase_accesscode', 31 33 ] -
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/accesscode.py
r6933 r6936 143 143 """Create the entries for this batch. 144 144 """ 145 for num, pin in enumerate(self. _getNewRandomNum(num=self.entry_num)):145 for num, pin in enumerate(self.getNewRandomNum(num=self.entry_num)): 146 146 self.addAccessCode(num, pin) 147 147 return 148 148 149 def _getNewRandomNum(self, num=1):149 def getNewRandomNum(self, num=1): 150 150 """Create a set of ``num`` random numbers of 10 digits each. 151 151 … … 177 177 return self[ac_id] 178 178 179 def addAccessCode(self, num, pin ):179 def addAccessCode(self, num, pin, owner=None): 180 180 """Add an access-code. 181 181 """ 182 182 ac = AccessCode(num, pin) 183 if owner: 184 ac.owner = owner 183 185 ac.__parent__ = self 184 186 self[ac.representation] = ac … … 546 548 """ 547 549 return fire_transition(access_code, 'reenable', comment=comment) 550 551 def 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 -
main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py
r6930 r6936 21 21 from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState 22 22 from zope.component import createObject 23 from waeup.sirp.accesscodes import invalidate_accesscode, get_access_code 23 from waeup.sirp.accesscodes import ( 24 invalidate_accesscode, get_access_code, purchase_accesscode) 24 25 from waeup.sirp.accesscodes.workflow import USED 25 26 from waeup.sirp.browser import ( … … 924 925 # from the incoming request. 925 926 def update(self): 927 student = self.context.getStudent() 926 928 self.context.r_amount_approved = self.context.amount_auth 927 929 self.context.r_card_num = u'0000' … … 930 932 self.context.payment_date = datetime.now() 931 933 if self.context.p_category == 'clearance': 932 # Find valid CLR access code 933 pass 934 # Create CLR access code 935 pin, error = purchase_accesscode('CLR',0,student.student_id) 936 if error: 937 self.flash(error) 938 return 939 self.context.ac = pin 940 return 934 941 elif self.context.p_category == 'schoolfee': 935 # Find valid SFE access code 936 pass 937 return 942 # Create SFE access code 943 pin, error = purchase_accesscode('SFE',0) 944 if error: 945 self.flash(error) 946 return 947 self.context.ac = pin 948 return 938 949 939 950 def render(self): … … 1076 1087 1077 1088 def update(self, SUBMIT=None): 1089 if not self.context.state == 'admitted': 1090 self.flash("Wrong state.") 1091 self.redirect(self.url(self.context)) 1092 return 1078 1093 self.ac_series = self.request.form.get('ac_series', None) 1079 1094 self.ac_number = self.request.form.get('ac_number', None) … … 1084 1099 code = get_access_code(pin) 1085 1100 if not code: 1086 self.flash('Ac cesscode is invalid.')1101 self.flash('Activation code is invalid.') 1087 1102 return 1088 1103 # Mark pin as used (this also fires a pin related transition) 1089 1104 # and fire transition start_clearance 1090 1105 if code.state == USED: 1091 self.flash('Ac cesscode has already been used.')1106 self.flash('Activation code has already been used.') 1092 1107 return 1093 1108 else:
Note: See TracChangeset for help on using the changeset viewer.