"""UI components for accesscodes. """ import grok from datetime import datetime from waeup.sirp.browser import WAeUPPage, WAeUPAddFormPage from waeup.sirp.browser.breadcrumbs import Breadcrumb from waeup.sirp.browser.viewlets import AdminTask, AddActionButton from waeup.sirp.interfaces import IWAeUPObject from waeup.sirp.accesscodes.accesscodes import AccessCodeBatch from waeup.sirp.accesscodes.interfaces import ( IAccessCodeBatchContainer, IAccessCodeBatch, ) grok.context(IWAeUPObject) class BatchContainerPage(WAeUPPage): grok.name('index') grok.context(IAccessCodeBatchContainer) grok.template('batchcontainer') title = 'Access Code Batches' pnav = 0 class AddBatchPage(WAeUPAddFormPage): grok.name('add') grok.context(IAccessCodeBatchContainer) title = label = 'Create a WAeUP Scratch Card Batch' pnav = 0 form_fields = grok.AutoFields(IAccessCodeBatch).select( 'batch_prefix', 'entry_num', 'cost') @grok.action('Cancel') def cancel(self): self.flash('Batch creation cancelled.') self.redirect(self.url(self.context)) @grok.action('Create batch') def createBatch(self, **data): creator = self.request.principal.id creation_date = datetime.now() data.update(creation_date=creation_date, creator=creator) batch = AccessCodeBatch(**data) self.context.addBatch(batch) self.context._p_changed = True self.flash('Batch created (%s entries)' % data['entry_num']) self.redirect(self.url(self.context)) class BatchContainerBreadcrumb(Breadcrumb): """A breadcrumb for ac batch containers. """ grok.context(IAccessCodeBatchContainer) title = u'Access Code Batches' parent_viewname = 'administration' class AdminTaskManageACBatches(AdminTask): """Entry on administration page that links to batch container. """ grok.order(5) grok.require('waeup.manageUniversity') grok.template('admintaskacbatches') link_title = 'Manage access-code batches' target_viewname = 'accesscodes' class CreateBatchButton(AddActionButton): """Action button on batch container page which links to batch creation. """ grok.context(IAccessCodeBatchContainer) grok.view(BatchContainerPage) grok.require('waeup.manageUniversity') text = 'Add Scratch Card Batch'