Changeset 6450 for main/waeup.sirp/trunk/src
- Timestamp:
- 22 Jun 2011, 09:47:22 (14 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp/accesscodes
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/accesscodes.py
r6449 r6450 52 52 53 53 @property 54 def status(self): 55 return IWorkflowState(self).getState() 56 57 @property 54 58 def disabled(self): 55 59 return IWorkflowState(self).getState() == DISABLED … … 62 66 def history(self): 63 67 history = IObjectHistory(self) 64 return ' \n'.join(history.messages)68 return '<br />'.join(history.messages) 65 69 66 70 class AccessCodeBatch(grok.Container): … … 288 292 return 289 293 290 def search(self, searchterm, searchtype, ): 291 """Look for access-codes that comply with the given params. 292 """ 293 results = [] 294 if searchtype == 'serial': 295 try: 296 searchterm = int(searchterm) 297 except: 298 return [] 299 for batchname in self.keys(): 300 part_result = self[batchname].search(searchterm, searchtype) 301 results.extend(part_result) 302 return results 294 #def search(self, searchterm, searchtype): 295 # """Look for access-codes that comply with the given params. 296 # """ 297 # results = [] 298 # return results 303 299 304 300 def getAccessCode(self, ac_id): … … 322 318 if ac is None: 323 319 return 324 ac.__parent__.disable(ac_id, user_id)325 return 326 327 def enable(self, ac_id ):320 disable_accesscode(ac_id, user_id) 321 return 322 323 def enable(self, ac_id, user_id): 328 324 """(Re-)enable the AC with ID ``ac_id``. 329 325 … … 334 330 if ac is None: 335 331 return 336 ac.__parent__.enable(ac_id)337 return 338 339 def invalidate(self, ac_id):340 """Invalidate the AC with ID ``ac_id``.341 """342 ac = self.getAccessCode(ac_id)343 if ac is None:344 return345 ac.__parent__.invalidate(ac_id)346 return332 reenable_accesscode(ac_id, user_id) 333 return 334 335 #def invalidate(self, ac_id): 336 # """Invalidate the AC with ID ``ac_id``. 337 # """ 338 # ac = self.getAccessCode(ac_id) 339 # if ac is None: 340 # return 341 # ac.__parent__.invalidate(ac_id) 342 # return 347 343 348 344 -
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/browser.py
r6417 r6450 3 3 import grok 4 4 from datetime import datetime 5 from hurry.workflow.interfaces import InvalidTransitionError 5 6 from waeup.sirp.browser import WAeUPPage, WAeUPAddFormPage 6 7 from waeup.sirp.browser.breadcrumbs import Breadcrumb … … 12 13 IAccessCodeBatchContainer, IAccessCodeBatch, 13 14 ) 15 from waeup.sirp.accesscodes.catalog import search 14 16 15 17 grok.context(IWAeUPObject) … … 46 48 grok.require('waeup.manageACBatches') 47 49 48 title = 'Create Scratch CardBatch'50 title = 'Create Access Code Batch' 49 51 pnav = 0 50 52 … … 109 111 grok.require('waeup.manageACBatches') 110 112 111 title = 'Search Scratch Cards' 112 pnav = 0 113 114 def update(self, search=None, searchterm=None, searchtype=None, 115 entries=None, disable=None, enable=None): 116 self.searchresults = None 117 if search is not None: 118 searchresults = self.context.search(searchterm, searchtype) 119 if len(searchresults) == 0: 120 return 121 self.searchresults = [] 122 for result in searchresults: 123 status = u'unused' 124 if result.disabled is True: 125 status = u'disabled by %s on %s' % ( 126 result.student_id, 127 result.invalidation_date.strftime('%c') 128 ) 129 elif result.invalidation_date is not None: 130 status = u'invalidated by %s on %s' % ( 131 result.student_id, 132 result.invalidation_date.strftime('%c') 133 ) 134 entry = dict( 135 serial = result.batch_serial, 136 code = result.representation, 137 status = status) 138 self.searchresults.append(entry) 139 if entries is None: 140 return 113 title = 'Access Codes' 114 pnav = 0 115 label = 'Search and manage access codes' 116 117 def update(self, *args, **kw): 118 form = self.request.form 119 self.hitlist = [] 120 if 'searchterm' in form and form['searchterm']: 121 self.searchterm = form['searchterm'] 122 self.searchtype = form['searchtype'] 123 elif 'old_searchterm' in form: 124 self.searchterm = form['old_searchterm'] 125 self.searchtype = form['old_searchtype'] 126 else: 127 return 128 #import pdb; pdb.set_trace() 129 if not 'entries' in form: 130 self.hitlist = search(query=self.searchterm, 131 searchtype=self.searchtype, view=self) 132 return 133 entries = form['entries'] 141 134 if isinstance(entries, basestring): 142 135 entries = [entries] 143 136 for entry in entries: 144 if disable is not None: 145 self.context.disable(entry, self.request.principal.id) 146 self.flash('disabled %s' % entry) 147 elif enable is not None: 148 self.context.enable(entry) 149 self.flash('(re-)enabled %s' % entry) 137 if 'disable' in form: 138 try: 139 self.context.disable(entry, self.request.principal.id) 140 self.flash('%s disabled.' % entry) 141 except InvalidTransitionError: 142 self.flash('Transition not allowed.') 143 elif 'enable' in form: 144 try: 145 self.context.enable(entry, self.request.principal.id) 146 self.flash('%s (re-)enabled.' % entry) 147 except InvalidTransitionError: 148 self.flash('Transition not allowed.') 149 self.hitlist = search(query=self.searchterm, 150 searchtype=self.searchtype, view=self) 150 151 return 151 152 … … 164 165 grok.context(IAccessCodeBatchContainer) 165 166 grok.name('search') 166 title = u'Search Scratch Cards'167 title = u'Search Access Codes' 167 168 viewname = 'search' 168 169 parent_viewname = 'index' … … 184 185 grok.view(BatchContainerPage) 185 186 grok.require('waeup.manageACBatches') 186 text = 'Add Scratch CardBatch'187 text = 'Add Access Code Batch' 187 188 188 189 class ReimportBatchButton(BatchOpButton): … … 193 194 grok.require('waeup.manageACBatches') 194 195 target = 'reimport' 195 text = 'Reimport Scratch CardBatch'196 text = 'Reimport Access Code Batch' 196 197 197 198 class SearchAccessCodeButton(SearchActionButton): … … 201 202 grok.view(BatchContainerPage) 202 203 grok.require('waeup.manageACBatches') 203 text = 'Search Scratch Cards'204 text = 'Search Access Codes' 204 205 205 206 class ManageAccessCodes(ManageLink): -
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/browser.txt
r6439 r6450 70 70 action bar: 71 71 72 >>> browser.getLink('Add Scratch CardBatch').click()72 >>> browser.getLink('Add Access Code Batch').click() 73 73 74 74 The add screen shows a form where we have to enter a prefix, the … … 92 92 'Create batch' in the form: 93 93 94 >>> browser.getLink('Add Scratch CardBatch').click()94 >>> browser.getLink('Add Access Code Batch').click() 95 95 >>> browser.getControl(name='form.prefix').value = 'APP' 96 96 >>> browser.getControl(name='form.entry_num').value = '5' … … 126 126 works: 127 127 128 >>> browser.getLink('Add Scratch CardBatch').click()128 >>> browser.getLink('Add Access Code Batch').click() 129 129 >>> browser.getControl(name='form.prefix').value = 'APP' 130 130 >>> browser.getControl(name='form.entry_num').value = '5' … … 134 134 And a third one that can be deleted afterwards: 135 135 136 >>> browser.getLink('Add Scratch CardBatch').click()136 >>> browser.getLink('Add Access Code Batch').click() 137 137 >>> browser.getControl(name='form.prefix').value = 'BLA' 138 138 >>> browser.getControl(name='form.entry_num').value = '3' … … 192 192 list of importable files is empty: 193 193 194 >>> browser.getLink('Reimport Scratch CardBatch').click()194 >>> browser.getLink('Reimport Access Code Batch').click() 195 195 >>> print browser.contents 196 196 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" … … 218 218 Now the file will be presented as import source: 219 219 220 >>> browser.getLink('Reimport Scratch CardBatch').click()220 >>> browser.getLink('Reimport Access Code Batch').click() 221 221 >>> filename in browser.contents 222 222 True … … 232 232 Now let's really reimport the batch: 233 233 234 >>> browser.getLink('Reimport Scratch CardBatch').click()234 >>> browser.getLink('Reimport Access Code Batch').click() 235 235 >>> ctrl = browser.getControl(name='filenames') 236 236 >>> ctrl.getControl(value=filename).selected = True … … 246 246 If we try to reimport an existing batch, that won't work: 247 247 248 >>> browser.getLink('Reimport Scratch CardBatch').click()248 >>> browser.getLink('Reimport Access Code Batch').click() 249 249 >>> ctrl = browser.getControl(name='filenames') 250 250 >>> ctrl.getControl(value=filename).selected = True -
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/browser_templates/searchpage.pt
r5918 r6450 1 1 <form method="POST"> 2 3 <br /> 4 2 5 <input type="submit" name="search" value="Search" /> 3 for scratch cards6 for access codes 4 7 5 8 <select name="searchtype"> 6 <option value="stud_id"> 7 used by student with ID 8 </option> 9 <option value="pin">with PIN</option> 10 <option value="serial">with serial</option> 11 </select>: 9 <option value="code">with PIN</option> 10 <option value="batch_serial">with serial</option> 11 <option value="history">with message term</option> 12 </select> 12 13 13 14 <input type="text" name="searchterm" /> 14 <br /><br />15 <b>complete numbers only</b>16 (Student ID means registration number for APP SCs)17 <br />18 15 19 16 <p> </p> 20 <div tal:condition="view/ searchresults">17 <div tal:condition="view/hitlist"> 21 18 <h3>Search Results</h3> 22 <table> 19 <input type="hidden" name="old_searchterm" 20 tal:attributes="value view/searchterm" /> 21 <input type="hidden" name="old_searchtype" 22 tal:attributes="value view/searchtype" /> 23 <table class = "zebra"> 23 24 <thead> 24 <tr>25 <th> </th>26 <th>Serial</th><th>AC</th><th>Status</th>27 </tr>25 <tr> 26 <th> </th> 27 <th>Serial</th><th>AC</th><th>Status</th><th>History</th> 28 </tr> 28 29 </thead> 29 30 <tbody> 30 <tr tal:repeat="item view/searchresults" 31 tal:attributes="class python: repeat['item'].odd() and 'even' or 'odd'"> 32 <td><input type="checkbox" name="entries" 33 tal:attributes="value item/code" /></td>34 <td tal:content="item/serial">1</td>35 <td tal:content="item/code">APP-1-1234567890</td>36 <td tal:content="item/status">unused</td>37 </tr>31 <tr tal:repeat="item view/hitlist"> 32 <td><input type="checkbox" name="entries" 33 tal:attributes="value item/code" /></td> 34 <td tal:content="item/batch_serial">1</td> 35 <td tal:content="item/code">APP-1-1234567890</td> 36 <td tal:content="item/status">unused</td> 37 <td tal:content="structure item/history">history</td> 38 </tr> 38 39 </tbody> 39 40 </table> -
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/catalog.py
r6446 r6450 2 2 """ 3 3 import grok 4 from waeup.sirp.interfaces import IUniversity 4 from hurry.query import Eq, Text 5 from hurry.query.query import Query 6 from zope.index.text.parsetree import ParseError 7 from waeup.sirp.interfaces import IUniversity, IQueryResultItem 5 8 from waeup.sirp.accesscodes.interfaces import IAccessCode 6 9 … … 16 19 disabled = grok.index.Field(attribute='disabled') 17 20 used = grok.index.Field(attribute='used') 21 batch_serial = grok.index.Field(attribute='batch_serial') 22 status = grok.index.Field(attribute='status') 23 24 class AccessCodeQueryResultItem(object): 25 grok.implements(IQueryResultItem) 26 27 def __init__(self, context, view): 28 self.context = context 29 #self.url = view.url(context) 30 self.code = context.representation 31 self.history = context.history 32 self.status = context.status 33 self.batch_serial = context.batch_serial 34 35 def search(query=None, searchtype=None, view=None): 36 if not query: 37 view.flash('Empty search string.') 38 return 39 hitlist = [] 40 try: 41 if searchtype == 'history': 42 results = Query().searchResults( 43 Text(('accesscodes_catalog', searchtype), query)) 44 elif searchtype == 'batch_serial': 45 results = Query().searchResults( 46 Eq(('accesscodes_catalog', searchtype), int(query))) 47 else: 48 results = Query().searchResults( 49 Eq(('accesscodes_catalog', searchtype), query)) 50 for result in results: 51 hitlist.append(AccessCodeQueryResultItem(result, view=view)) 52 except ParseError: 53 view.flash('Search string not allowed.') 54 return 55 return hitlist 56 57 -
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/interfaces.py
r6425 r6450 23 23 title = u'Cost of access code', 24 24 default = 0.0, min = 0.0, 25 ) 26 status = schema.TextLine( 27 title = u'Workflow status', 25 28 ) 26 29 disabled = schema.Bool(
Note: See TracChangeset for help on using the changeset viewer.