source: main/waeup.kofa/trunk/src/waeup/kofa/applicants/viewlets.py @ 8420

Last change on this file since 8420 was 8420, checked in by Henrik Bettermann, 12 years ago

Add methods for approving payments and implement pages for approving payments (work in progress).

  • Property svn:keywords set to Id
File size: 6.4 KB
Line 
1## $Id: viewlets.py 8420 2012-05-11 14:18:47Z henrik $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18import grok
19from hurry.workflow.interfaces import IWorkflowState
20from waeup.kofa.interfaces import IKofaObject
21from waeup.kofa.students.viewlets import PrimaryStudentNavTab
22from waeup.kofa.browser.viewlets import ManageActionButton, PrimaryNavTab
23from waeup.kofa.applicants.interfaces import (
24    IApplicant, IApplicantsRoot, IApplicantsContainer,
25    IApplicantOnlinePayment,
26    )
27from waeup.kofa.applicants.browser import (
28    ApplicantsRootPage, ApplicantsContainerPage, ApplicantManageFormPage,
29    ApplicantDisplayFormPage, OnlinePaymentDisplayFormPage
30    )
31
32from waeup.kofa.interfaces import MessageFactory as _
33
34grok.context(IKofaObject) # Make IKofaObject the default context
35grok.templatedir('browser_templates')
36
37class ApplicantsAuthTab(PrimaryNavTab):
38    """Applicants tab in primary navigation.
39    """
40    grok.context(IKofaObject)
41    grok.order(3)
42    grok.require('waeup.viewApplicantsTab')
43    pnav = 3
44    tab_title = _(u'Applicants')
45
46    @property
47    def link_target(self):
48        return self.view.application_url('applicants')
49
50class ApplicantsAnonTab(ApplicantsAuthTab):
51    """Applicants tab in primary navigation.
52
53    Display tab only for anonymous. Authenticated users can call the
54    form from the user navigation bar.
55    """
56    grok.require('waeup.Anonymous')
57    tab_title = _(u'Application')
58
59    # Also zope.manager has role Anonymous.
60    # To avoid displaying this tab, we have to check the principal id too.
61    @property
62    def link_target(self):
63        if self.request.principal.id == 'zope.anybody':
64            return self.view.application_url('applicants')
65        return
66
67class MyApplicationDataTab(PrimaryStudentNavTab):
68    """MyData-tab in primary navigation.
69    """
70    grok.order(3)
71    grok.require('waeup.viewMyApplicationDataTab')
72    pnav = 3
73    tab_title = _(u'My Data')
74
75    @property
76    def link_target(self):
77        try:
78            container, application_number = self.request.principal.id.split('_')
79        except ValueError:
80            return
81        rel_link = '/applicants/%s/%s' % (container, application_number)
82        return self.view.application_url() + rel_link
83
84class ApplicantsRootSearchActionButton(ManageActionButton):
85    grok.order(1)
86    grok.context(IApplicantsRoot)
87    grok.view(ApplicantsRootPage)
88    grok.require('waeup.viewApplication')
89    text = _('Search applicants')
90    icon = 'actionicon_search.png'
91    target = '@@search'
92
93class ApplicantsRootManageActionButton(ManageActionButton):
94    grok.order(2)
95    grok.context(IApplicantsRoot)
96    grok.view(ApplicantsRootPage)
97    grok.require('waeup.manageApplication')
98    text = _('Manage application section')
99
100#class ApplicantsContainerManageActionButton(ManageActionButton):
101#    grok.order(1)
102#    grok.context(IApplicantsContainer)
103#    grok.view(ApplicantsContainerPage)
104#    grok.require('waeup.manageApplication')
105#    text = _('Manage application records')
106
107class ApplicantRegisterActionButton(ManageActionButton):
108    grok.order(2)
109    grok.context(IApplicantsContainer)
110    grok.view(ApplicantsContainerPage)
111    grok.require('waeup.Anonymous')
112    icon = 'actionicon_login.png'
113    text = _('Register for application')
114    target = 'register'
115
116class ApplicantViewActionButton(ManageActionButton):
117    grok.context(IApplicant)
118    grok.view(ApplicantManageFormPage)
119    grok.require('waeup.viewApplication')
120    icon = 'actionicon_view.png'
121    text = _('View application record')
122    target = 'index'
123
124class ApplicantManageActionButton(ManageActionButton):
125    grok.order(1)
126    grok.context(IApplicant)
127    grok.view(ApplicantDisplayFormPage)
128    grok.require('waeup.manageApplication')
129    text = _('Manage application record')
130    target = 'manage'
131
132class ApplicantEditActionButton(ManageActionButton):
133    grok.order(2)
134    grok.context(IApplicant)
135    grok.view(ApplicantDisplayFormPage)
136    grok.require('waeup.handleApplication')
137    text = _('Edit application record')
138    target ='edit'
139
140    @property
141    def target_url(self):
142        """Get a URL to the target...
143        """
144        if self.context.locked:
145            return
146        return self.view.url(self.view.context, self.target)
147
148class PDFActionButton(ManageActionButton):
149    grok.order(3)
150    grok.context(IApplicant)
151    grok.require('waeup.viewApplication')
152    icon = 'actionicon_pdf.png'
153    text = _('Download application slip')
154    target = 'application_slip.pdf'
155
156class StudentCreateActionButton(ManageActionButton):
157    grok.order(4)
158    grok.context(IApplicant)
159    grok.require('waeup.manageApplication')
160    icon = 'actionicon_entrance.png'
161    text = _('Create student record')
162    target ='createstudent'
163
164    @property
165    def target_url(self):
166        """Get a URL to the target...
167        """
168        if IWorkflowState(self.context).getState() != 'admitted':
169            return
170        return self.view.url(self.view.context, self.target)
171
172class PaymentReceiptActionButton(ManageActionButton):
173    grok.order(1)
174    grok.context(IApplicantOnlinePayment)
175    grok.view(OnlinePaymentDisplayFormPage)
176    grok.require('waeup.viewApplication')
177    icon = 'actionicon_pdf.png'
178    text = _('Download payment slip')
179    target = 'payment_slip.pdf'
180
181    @property
182    def target_url(self):
183        #if self.context.p_state != 'paid':
184        #    return ''
185        return self.view.url(self.view.context, self.target)
186
187class ApprovePaymentActionButton(ManageActionButton):
188    grok.order(2)
189    grok.context(IApplicantOnlinePayment)
190    grok.view(OnlinePaymentDisplayFormPage)
191    grok.require('waeup.managePortal')
192    icon = 'actionicon_call.png'
193    text = _('Approve payment')
194    target = 'approve'
195
196    @property
197    def target_url(self):
198        if self.context.p_state == 'paid':
199            return ''
200        return self.view.url(self.view.context, self.target)
Note: See TracBrowser for help on using the repository browser.