source: main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/browser.py @ 5088

Last change on this file since 5088 was 5088, checked in by uli, 15 years ago

Fix creation of batches.

File size: 2.3 KB
Line 
1"""UI components for accesscodes.
2"""
3import grok
4from datetime import datetime
5from waeup.sirp.browser import WAeUPPage, WAeUPAddFormPage
6from waeup.sirp.browser.breadcrumbs import Breadcrumb
7from waeup.sirp.browser.viewlets import AdminTask, AddActionButton
8from waeup.sirp.interfaces import IWAeUPObject
9
10from waeup.sirp.accesscodes.accesscodes import AccessCodeBatch
11from waeup.sirp.accesscodes.interfaces import (
12    IAccessCodeBatchContainer, IAccessCodeBatch,
13    )
14
15grok.context(IWAeUPObject)
16
17class BatchContainerPage(WAeUPPage):
18    grok.name('index')
19    grok.context(IAccessCodeBatchContainer)
20    grok.template('batchcontainer')
21
22    title = 'Access Code Batches'
23    pnav = 0
24
25class AddBatchPage(WAeUPAddFormPage):
26    grok.name('add')
27    grok.context(IAccessCodeBatchContainer)
28
29    title = label = 'Create a WAeUP Scratch Card Batch'
30    pnav = 0
31
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
40    @grok.action('Create batch')
41    def createBatch(self, **data):
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'])
49        self.redirect(self.url(self.context))
50
51class 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
58class 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'
67
68class 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'
Note: See TracBrowser for help on using the repository browser.