[5082] | 1 | """UI components for accesscodes. |
---|
| 2 | """ |
---|
| 3 | import grok |
---|
[5088] | 4 | from datetime import datetime |
---|
[5084] | 5 | from waeup.sirp.browser import WAeUPPage, WAeUPAddFormPage |
---|
[5082] | 6 | from waeup.sirp.browser.breadcrumbs import Breadcrumb |
---|
[5084] | 7 | from waeup.sirp.browser.viewlets import AdminTask, AddActionButton |
---|
[5082] | 8 | from waeup.sirp.interfaces import IWAeUPObject |
---|
| 9 | |
---|
[5088] | 10 | from waeup.sirp.accesscodes.accesscodes import AccessCodeBatch |
---|
| 11 | from waeup.sirp.accesscodes.interfaces import ( |
---|
| 12 | IAccessCodeBatchContainer, IAccessCodeBatch, |
---|
| 13 | ) |
---|
[5082] | 14 | |
---|
| 15 | grok.context(IWAeUPObject) |
---|
| 16 | |
---|
| 17 | class BatchContainerPage(WAeUPPage): |
---|
| 18 | grok.name('index') |
---|
| 19 | grok.context(IAccessCodeBatchContainer) |
---|
| 20 | grok.template('batchcontainer') |
---|
| 21 | |
---|
| 22 | title = 'Access Code Batches' |
---|
| 23 | pnav = 0 |
---|
| 24 | |
---|
[5084] | 25 | class AddBatchPage(WAeUPAddFormPage): |
---|
| 26 | grok.name('add') |
---|
| 27 | grok.context(IAccessCodeBatchContainer) |
---|
| 28 | |
---|
| 29 | title = label = 'Create a WAeUP Scratch Card Batch' |
---|
| 30 | pnav = 0 |
---|
| 31 | |
---|
[5088] | 32 | form_fields = grok.AutoFields(IAccessCodeBatch).select( |
---|
| 33 | 'batch_prefix', 'entry_num', 'cost') |
---|
| 34 | |
---|
| 35 | @grok.action('Cancel') |
---|
| 36 | def cancel(self): |
---|
| 37 | self.flash('Batch creation cancelled.') |
---|
| 38 | self.redirect(self.url(self.context)) |
---|
| 39 | |
---|
[5084] | 40 | @grok.action('Create batch') |
---|
| 41 | def createBatch(self, **data): |
---|
[5088] | 42 | creator = self.request.principal.id |
---|
| 43 | creation_date = datetime.now() |
---|
| 44 | data.update(creation_date=creation_date, creator=creator) |
---|
| 45 | batch = AccessCodeBatch(**data) |
---|
| 46 | self.context.addBatch(batch) |
---|
| 47 | self.context._p_changed = True |
---|
| 48 | self.flash('Batch created (%s entries)' % data['entry_num']) |
---|
[5084] | 49 | self.redirect(self.url(self.context)) |
---|
| 50 | |
---|
[5082] | 51 | class BatchContainerBreadcrumb(Breadcrumb): |
---|
| 52 | """A breadcrumb for ac batch containers. |
---|
| 53 | """ |
---|
| 54 | grok.context(IAccessCodeBatchContainer) |
---|
| 55 | title = u'Access Code Batches' |
---|
| 56 | parent_viewname = 'administration' |
---|
| 57 | |
---|
| 58 | class AdminTaskManageACBatches(AdminTask): |
---|
| 59 | """Entry on administration page that links to batch container. |
---|
| 60 | """ |
---|
| 61 | grok.order(5) |
---|
| 62 | grok.require('waeup.manageUniversity') |
---|
| 63 | grok.template('admintaskacbatches') |
---|
| 64 | |
---|
| 65 | link_title = 'Manage access-code batches' |
---|
| 66 | target_viewname = 'accesscodes' |
---|
[5084] | 67 | |
---|
| 68 | class CreateBatchButton(AddActionButton): |
---|
| 69 | """Action button on batch container page which links to batch creation. |
---|
| 70 | """ |
---|
| 71 | grok.context(IAccessCodeBatchContainer) |
---|
| 72 | grok.view(BatchContainerPage) |
---|
| 73 | grok.require('waeup.manageUniversity') |
---|
| 74 | text = 'Add Scratch Card Batch' |
---|