Changeset 5155 for main


Ignore:
Timestamp:
13 Apr 2010, 16:47:45 (15 years ago)
Author:
uli
Message:

Add UI components for searching access codes.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes
Files:
1 added
1 edited

Legend:

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

    r5132 r5155  
    77from waeup.sirp.browser.pages import UniversityPage
    88from waeup.sirp.browser.viewlets import (
    9     AdminTask, AddActionButton, LeftSidebar, BatchOpButton)
     9    AdminTask, AddActionButton, SearchActionButton, LeftSidebar, BatchOpButton)
    1010from waeup.sirp.interfaces import IWAeUPObject, IUniversity
    1111
     
    105105        self.redirect(self.url(self.context))
    106106       
    107    
     107class BatchContainerSearchPage(WAeUPPage):
     108    grok.name('search')
     109    grok.context(IAccessCodeBatchContainer)
     110    grok.template('searchpage')
     111    grok.require('waeup.manageACBatches')
     112
     113    title = 'Search Scratch Cards'
     114    pnav = 0
     115
     116    def update(self, search=None, searchterm=None, searchtype=None,
     117               entries=None, disable=None, enable=None):
     118        self.searchresults = None
     119        if search is not None:
     120            searchresults = self.context.search(searchterm, searchtype)
     121            if len(searchresults) == 0:
     122                return
     123            self.searchresults = []
     124            for result in searchresults:
     125                status = u'unused'
     126                if result.disabled is True:
     127                    status = u'disabled by %s on %s' % (
     128                        result.student_id,
     129                        result.invalidation_date.strftime('%c')
     130                        )
     131                elif result.invalidation_date is not None:
     132                    status = u'invalidated by %s on %s' % (
     133                        result.student_id,
     134                        result.invalidation_date.strftime('%c')
     135                        )
     136                entry = dict(
     137                    serial = result.batch_serial,
     138                    code = result.representation,
     139                    status = status)
     140                self.searchresults.append(entry)
     141        if entries is None:
     142            return
     143        if isinstance(entries, basestring):
     144            entries = [entries]
     145        for entry in entries:
     146            if disable is not None:
     147                self.context.disable(entry, self.request.principal.id)
     148                self.flash('disabled %s' % entry)
     149            elif enable is not None:
     150                self.context.enable(entry)
     151                self.flash('(re-)enabled %s' % entry)
     152        return
     153
    108154class BatchContainerBreadcrumb(Breadcrumb):
    109155    """A breadcrumb for ac batch containers.
     
    114160    parent_viewname = 'administration'
    115161
     162class BatchContainerSearchBreadcrumb(Breadcrumb):
     163    """A breadcrumb for ac batch containers search page.
     164    """
     165    grok.require('waeup.manageACBatches')
     166    grok.context(IAccessCodeBatchContainer)
     167    grok.name('search')
     168    title = u'Search Scratch Cards'
     169    viewname = 'search'
     170    parent_viewname = 'index'
     171
    116172class AdminTaskManageACBatches(AdminTask):
    117173    """Entry on administration page that links to batch container.
     
    141197    text = 'Reimport Scratch Card Batch'
    142198
     199class SearchAccessCodeButton(SearchActionButton):
     200    """Action button on batch container page which links to search.
     201    """
     202    grok.context(IAccessCodeBatchContainer)
     203    grok.view(BatchContainerPage)
     204    grok.require('waeup.manageACBatches')
     205    text = 'Search Scratch Cards'   
     206   
    143207class ManageAccessCodes(grok.Viewlet):
    144208    """Link on front page to access code management.
Note: See TracChangeset for help on using the changeset viewer.