Changeset 6386 for main/waeup.sirp/trunk
- Timestamp:
- 16 Jun 2011, 21:06:35 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/accesscodes.py
r6383 r6386 20 20 grok.implements(IAccessCode) 21 21 22 def __init__(self, batch_serial, random_num, invalidation_date=None, 23 student_id=None, disabled=False): 22 def __init__(self, batch_serial, random_num): 24 23 self.batch_serial = batch_serial 25 24 self.random_num = random_num 26 self._invalidation_date = invalidation_date27 self.student_id = student_id28 self._disabled = disabled29 25 IWorkflowInfo(self).fireTransition('init') 30 26 … … 55 51 return None 56 52 return self.batch.cost 57 58 @property59 def invalidation_date(self):60 # We define this as a property to make it unwritable.61 # This attribute should be set by the surrounding batch only.62 return self._invalidation_date63 64 @property65 def disabled(self):66 # We define this as a property to make it unwritable.67 # This attribute should be set by the surrounding batch only.68 return self._disabled69 53 70 54 class AccessCodeBatch(grok.Model): … … 86 70 self._entries = list() 87 71 self._acids = OIBTree() 88 self._studids = OIBTree()89 72 self._createEntries() 90 73 … … 94 77 for num, pin in enumerate(self._getNewRandomNum(num=self.entry_num)): 95 78 self.addAccessCode(num, pin) 96 self._p_changed = True # XXX: most probably not needed.97 79 return 98 80 … … 133 115 return self._entries[self._acids[ac_id]] 134 116 135 def getAccessCodeForStudentId(self, stud_id):136 """Get any AccessCode invalidated for ``stud_id`` or ``KeyError``.137 """138 return self._entries[self._studids[stud_id]]139 140 117 def addAccessCode(self, num, pin): 141 118 """Add an access-code. … … 151 128 """ 152 129 num = self._acids[ac_id] 153 ac = self.getAccessCode(ac_id)154 ac._invalidation_date = datetime.now()155 ac.student_id = student_id156 if student_id is not None:157 self._studids.update({student_id: num})158 130 self.invalidated_num += 1 159 131 … … 168 140 if ac._disabled == True: 169 141 return 170 ac._disabled = True171 old_student_id = ac.student_id172 if old_student_id is not None:173 del self._studids[old_student_id]174 self._studids.update({user_id: num})175 ac.student_id = user_id176 ac._invalidation_date = datetime.now()177 142 self.disabled_num += 1 178 143 … … 184 149 """ 185 150 num = self._acids[ac_id] 186 ac = self.getAccessCode(ac_id)187 if ac._disabled == False:188 return189 ac.student_id = None190 ac._disabled = False191 ac._invalidation_date = None192 151 self.disabled_num -= 1 193 152 … … 234 193 ) 235 194 writer = csv.writer(open(csv_path, 'w'), quoting=csv.QUOTE_ALL) 236 writer.writerow(['prefix', 'serial', 'ac', ' student', 'date'])195 writer.writerow(['prefix', 'serial', 'ac', 'date']) 237 196 writer.writerow([self.prefix, '%0.2f' % self.cost, str(self.num), 238 197 str(self.entry_num)]) 239 198 for value in self._entries: 240 date = ''241 if value.invalidation_date is not None:242 date = value.invalidation_date.strftime(243 '%Y-%m-%d-%H-%M-%S')244 199 writer.writerow([ 245 200 self.prefix, value.batch_serial, value.representation, 246 value.student_id, date247 201 ]) 248 202 return os.path.basename(csv_path) … … 259 213 except KeyError: 260 214 return [] 261 if searchtype != 'stud_id':262 return []263 try:264 entry = self.getAccessCodeForStudentId(searchterm)265 return [entry]266 except KeyError:267 pass268 return []269 215 270 216 class AccessCodeBatchContainer(grok.Container):
Note: See TracChangeset for help on using the changeset viewer.