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

Last change on this file since 5104 was 5104, checked in by uli, 15 years ago
  • Make use of new permission.
  • Provide number of used ACs for each batch.
  • Add link on home page to access codes management screen.
File size: 3.0 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.pages import UniversityPage
8from waeup.sirp.browser.viewlets import AdminTask, AddActionButton, LeftSidebar
9from waeup.sirp.interfaces import IWAeUPObject, IUniversity
10
11from waeup.sirp.accesscodes.accesscodes import AccessCodeBatch
12from waeup.sirp.accesscodes.catalog import invalidated_num
13from waeup.sirp.accesscodes.interfaces import (
14    IAccessCodeBatchContainer, IAccessCodeBatch,
15    )
16
17grok.context(IWAeUPObject)
18
19class BatchContainerPage(WAeUPPage):
20    grok.name('index')
21    grok.context(IAccessCodeBatchContainer)
22    grok.template('batchcontainer')
23    grok.require('waeup.manageACBatches')
24
25    title = 'Access Code Batches'
26    pnav = 0
27
28    def invalidated(self, batch):
29        return invalidated_num(batch.prefix, batch.num)
30
31
32class AddBatchPage(WAeUPAddFormPage):
33    grok.name('add')
34    grok.context(IAccessCodeBatchContainer)
35    grok.require('waeup.manageACBatches')
36
37    title = label = 'Create a WAeUP Scratch Card Batch'
38    pnav = 0
39
40    form_fields = grok.AutoFields(IAccessCodeBatch).select(
41        'batch_prefix', 'entry_num', 'cost')
42
43    @grok.action('Cancel')
44    def cancel(self, *args, **kw):
45        self.flash('Batch creation cancelled.')
46        self.redirect(self.url(self.context))
47
48    @grok.action('Create batch')
49    def createBatch(self, **data):
50        creator = self.request.principal.id
51        creation_date = datetime.now()
52        data.update(creation_date=creation_date, creator=creator)
53        batch = AccessCodeBatch(**data)
54        self.context.addBatch(batch)
55        self.context._p_changed = True
56        self.flash('Batch created (%s entries)' % data['entry_num'])
57        self.redirect(self.url(self.context))
58
59class BatchContainerBreadcrumb(Breadcrumb):
60    """A breadcrumb for ac batch containers.
61    """
62    grok.require('waeup.manageACBatches')
63    grok.context(IAccessCodeBatchContainer)
64    title = u'Access Code Batches'
65    parent_viewname = 'administration'
66
67class AdminTaskManageACBatches(AdminTask):
68    """Entry on administration page that links to batch container.
69    """
70    grok.order(5)
71    grok.require('waeup.manageACBatches')
72    grok.template('admintaskacbatches')
73
74    link_title = 'Manage access-code batches'
75    target_viewname = 'accesscodes'
76
77class CreateBatchButton(AddActionButton):
78    """Action button on batch container page which links to batch creation.
79    """
80    grok.context(IAccessCodeBatchContainer)
81    grok.view(BatchContainerPage)
82    grok.require('waeup.manageACBatches')
83    text = 'Add Scratch Card Batch'
84
85class ManageAccessCodes(grok.Viewlet):
86    """Link on front page to access code management.
87    """
88    grok.viewletmanager(LeftSidebar)
89    grok.context(IUniversity)
90    grok.view(UniversityPage)
91    grok.order(6)
92    grok.require('waeup.manageACBatches')
93
94    def render(self):
95        return u'<div class="portlet"><a href="accesscodes">Manage access-codes</a></div>'
Note: See TracBrowser for help on using the repository browser.