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

Last change on this file since 8667 was 8666, checked in by Henrik Bettermann, 13 years ago

Disable application slip download in state initialized (managers only) and started.

  • Property svn:keywords set to Id
File size: 7.2 KB
Line 
1## $Id: viewlets.py 8666 2012-06-10 20:13:34Z 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 waeup.kofa.interfaces import IKofaObject
20from waeup.kofa.students.viewlets import PrimaryStudentNavTab
21from waeup.kofa.browser.viewlets import ManageActionButton, PrimaryNavTab
22from waeup.kofa.applicants.interfaces import (
23    IApplicant, IApplicantsRoot, IApplicantsContainer,
24    IApplicantOnlinePayment
25    )
26from waeup.kofa.applicants.browser import (
27    ApplicantsRootPage, ApplicantsContainerPage, ApplicantManageFormPage,
28    ApplicantDisplayFormPage, OnlinePaymentDisplayFormPage,
29    ApplicantsContainerManageFormPage, ApplicantsStatisticsPage
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
100class ApplicantRegisterActionButton(ManageActionButton):
101    grok.order(1)
102    grok.context(IApplicantsContainer)
103    grok.view(ApplicantsContainerPage)
104    grok.require('waeup.Anonymous')
105    icon = 'actionicon_login.png'
106    text = _('Register for application')
107    target = 'register'
108
109class ApplicantsContainerStatisticsActionButton(ManageActionButton):
110    grok.order(1)
111    grok.context(IApplicantsContainer)
112    grok.view(ApplicantsContainerManageFormPage)
113    grok.require('waeup.viewApplicationStatistics')
114    icon = 'actionicon_statistics.png'
115    text = _('Container statistics')
116    target = 'statistics'
117
118class ApplicantsContainerStatisticsActionButton2(ApplicantsContainerStatisticsActionButton):
119    grok.order(3)
120    grok.view(ApplicantsContainerPage)
121
122class ApplicantsContainerManageActionButton(ManageActionButton):
123    grok.order(2)
124    grok.context(IApplicantsContainer)
125    grok.view(ApplicantsContainerPage)
126    grok.require('waeup.manageApplication')
127    text = _('Manage container')
128    target = 'manage'
129
130class ApplicantViewActionButton(ManageActionButton):
131    grok.context(IApplicant)
132    grok.view(ApplicantManageFormPage)
133    grok.require('waeup.viewApplication')
134    icon = 'actionicon_view.png'
135    text = _('View application record')
136    target = 'index'
137
138class ApplicantManageActionButton(ManageActionButton):
139    grok.order(1)
140    grok.context(IApplicant)
141    grok.view(ApplicantDisplayFormPage)
142    grok.require('waeup.manageApplication')
143    text = _('Manage application record')
144    target = 'manage'
145
146class ApplicantEditActionButton(ManageActionButton):
147    grok.order(2)
148    grok.context(IApplicant)
149    grok.view(ApplicantDisplayFormPage)
150    grok.require('waeup.handleApplication')
151    text = _('Edit application record')
152    target ='edit'
153
154    @property
155    def target_url(self):
156        """Get a URL to the target...
157        """
158        if self.context.locked or (
159            self.context.__parent__.expired and
160            self.context.__parent__.strict_deadline):
161            return
162        return self.view.url(self.view.context, self.target)
163
164class PDFActionButton(ManageActionButton):
165    grok.order(3)
166    grok.context(IApplicant)
167    grok.require('waeup.viewApplication')
168    icon = 'actionicon_pdf.png'
169    text = _('Download application slip')
170    target = 'application_slip.pdf'
171
172    @property
173    def target_url(self):
174        """Get a URL to the target...
175        """
176        if self.context.state in ('initialized', 'started'):
177            return
178        return self.view.url(self.view.context, self.target)
179
180class StudentCreateActionButton(ManageActionButton):
181    grok.order(4)
182    grok.context(IApplicant)
183    grok.require('waeup.manageApplication')
184    icon = 'actionicon_entrance.png'
185    text = _('Create student record')
186    target ='createstudent'
187
188    @property
189    def target_url(self):
190        """Get a URL to the target...
191        """
192        if self.context.state != 'admitted':
193            return
194        return self.view.url(self.view.context, self.target)
195
196class PaymentReceiptActionButton(ManageActionButton):
197    grok.order(1)
198    grok.context(IApplicantOnlinePayment)
199    grok.view(OnlinePaymentDisplayFormPage)
200    grok.require('waeup.viewApplication')
201    icon = 'actionicon_pdf.png'
202    text = _('Download payment slip')
203    target = 'payment_slip.pdf'
204
205    @property
206    def target_url(self):
207        #if self.context.p_state != 'paid':
208        #    return ''
209        return self.view.url(self.view.context, self.target)
210
211class ApprovePaymentActionButton(ManageActionButton):
212    grok.order(2)
213    grok.context(IApplicantOnlinePayment)
214    grok.view(OnlinePaymentDisplayFormPage)
215    grok.require('waeup.managePortal')
216    icon = 'actionicon_accept.png'
217    text = _('Approve payment')
218    target = 'approve'
219
220    @property
221    def target_url(self):
222        if self.context.p_state == 'paid':
223            return ''
224        return self.view.url(self.view.context, self.target)
Note: See TracBrowser for help on using the repository browser.