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

Last change on this file since 14194 was 13951, checked in by Henrik Bettermann, 8 years ago

Rename button.

  • Property svn:keywords set to Id
File size: 9.5 KB
Line 
1## $Id: viewlets.py 13951 2016-06-17 11:55: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 (
22    ManageActionButton, PrimaryNavTab, AddActionButton)
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    ApplicantsContainerManageFormPage, ApplicantsStatisticsPage
31    )
32
33from waeup.kofa.interfaces import MessageFactory as _
34
35grok.context(IKofaObject) # Make IKofaObject the default context
36grok.templatedir('browser_templates')
37
38class ApplicantsAuthTab(PrimaryNavTab):
39    """Applicants tab in primary navigation.
40    """
41    grok.context(IKofaObject)
42    grok.order(3)
43    grok.require('waeup.viewApplicantsTab')
44    pnav = 3
45    tab_title = _(u'Applicants')
46
47    @property
48    def link_target(self):
49        return self.view.application_url('applicants')
50
51class ApplicantsAnonTab(ApplicantsAuthTab):
52    """Applicants tab in primary navigation.
53
54    Display tab only for anonymous. Authenticated users can call the
55    form from the user navigation bar.
56    """
57    grok.require('waeup.Anonymous')
58    tab_title = _(u'Application')
59
60    # Also zope.manager has role Anonymous.
61    # To avoid displaying this tab, we have to check the principal id too.
62    @property
63    def link_target(self):
64        if self.request.principal.id == 'zope.anybody':
65            return self.view.application_url('applicants')
66        return
67
68class MyApplicationDataTab(PrimaryStudentNavTab):
69    """MyData-tab in primary navigation.
70    """
71    grok.order(3)
72    grok.require('waeup.viewMyApplicationDataTab')
73    pnav = 3
74    tab_title = _(u'My Data')
75
76    @property
77    def link_target(self):
78        try:
79            container, application_number = self.request.principal.id.split('_')
80        except ValueError:
81            return
82        rel_link = '/applicants/%s/%s' % (container, application_number)
83        return self.view.application_url() + rel_link
84
85class ApplicantsRootSearchActionButton(ManageActionButton):
86    grok.order(1)
87    grok.context(IApplicantsRoot)
88    grok.view(ApplicantsRootPage)
89    grok.require('waeup.viewApplication')
90    text = _('Find applicants')
91    icon = 'actionicon_search.png'
92    target = '@@search'
93
94class ApplicantsRootManageActionButton(ManageActionButton):
95    grok.order(2)
96    grok.context(IApplicantsRoot)
97    grok.view(ApplicantsRootPage)
98    grok.require('waeup.manageApplication')
99    text = _('Manage applicants section')
100
101class ApplicantRegisterActionButton(ManageActionButton):
102    grok.order(1)
103    grok.context(IApplicantsContainer)
104    grok.view(ApplicantsContainerPage)
105    grok.require('waeup.Anonymous')
106    icon = 'actionicon_login.png'
107    text = _('Register for application')
108    target = 'register'
109
110class ApplicantsContainerAddActionButton(AddActionButton):
111    grok.order(1)
112    grok.context(IApplicantsContainer)
113    grok.view(ApplicantsContainerManageFormPage)
114    grok.require('waeup.manageApplication')
115    text = _('Add applicant')
116    target = 'addapplicant'
117
118class ApplicantsContainerPrefillActionButton(ManageActionButton):
119    grok.order(2)
120    grok.context(IApplicantsContainer)
121    grok.view(ApplicantsContainerManageFormPage)
122    grok.require('waeup.manageApplication')
123    icon = 'actionicon_bucketfill.png'
124    text = _('Pre-fill container')
125    target = 'prefill'
126
127class ApplicantsContainerPurgeActionButton(ManageActionButton):
128    grok.order(3)
129    grok.context(IApplicantsContainer)
130    grok.view(ApplicantsContainerManageFormPage)
131    grok.require('waeup.manageApplication')
132    icon = 'actionicon_sweep.png'
133    text = _('Purge container')
134    target = 'purge'
135
136class ApplicantsContainerStatisticsActionButton(ManageActionButton):
137    grok.order(4)
138    grok.context(IApplicantsContainer)
139    grok.view(ApplicantsContainerManageFormPage)
140    grok.require('waeup.viewApplicationStatistics')
141    icon = 'actionicon_statistics.png'
142    text = _('Container statistics')
143    target = 'statistics'
144
145class ApplicantsContainerStatisticsActionButton2(
146        ApplicantsContainerStatisticsActionButton):
147    grok.order(5)
148    grok.view(ApplicantsContainerPage)
149
150class ApplicantsContainerManageActionButton(ManageActionButton):
151    grok.order(2)
152    grok.context(IApplicantsContainer)
153    grok.view(ApplicantsContainerPage)
154    grok.require('waeup.manageApplication')
155    text = _('Manage container')
156    target = 'manage'
157
158class ExportApplicantsActionButton(ManageActionButton):
159    """ 'Export data' button for faculties.
160    """
161    grok.context(IApplicantsContainer)
162    grok.view(ApplicantsContainerPage)
163    grok.require('waeup.manageApplication')
164    icon = 'actionicon_down.png'
165    text = _('Export application data')
166    target = 'exports'
167    grok.order(4)
168
169class ApplicantsRootCreateStudentsActionButton(ManageActionButton):
170    grok.order(3)
171    grok.context(IApplicantsRoot)
172    grok.view(ApplicantsRootPage)
173    grok.require('waeup.managePortal')
174    icon = 'actionicon_entrance.png'
175    text = _('Create students')
176    target ='createallstudents'
177
178    @property
179    def target_url(self):
180        if self.target and self.request.principal.id == 'admin':
181            return self.view.url(self.view.context, self.target)
182        return
183
184class ApplicantsContainerCreateStudentsActionButton(ManageActionButton):
185    grok.order(5)
186    grok.context(IApplicantsContainer)
187    grok.view(ApplicantsContainerPage)
188    grok.require('waeup.managePortal')
189    icon = 'actionicon_entrance.png'
190    text = _('Create students')
191    target ='createallstudents'
192
193    @property
194    def target_url(self):
195        if self.target and self.request.principal.id == 'admin':
196            return self.view.url(self.view.context, self.target)
197        return
198
199class ApplicantViewActionButton(ManageActionButton):
200    grok.context(IApplicant)
201    grok.view(ApplicantManageFormPage)
202    grok.require('waeup.viewApplication')
203    icon = 'actionicon_view.png'
204    text = _('View application record')
205    target = 'index'
206
207class ApplicantManageActionButton(ManageActionButton):
208    grok.order(1)
209    grok.context(IApplicant)
210    grok.view(ApplicantDisplayFormPage)
211    grok.require('waeup.manageApplication')
212    text = _('Manage application record')
213    target = 'manage'
214
215class ApplicantEditActionButton(ManageActionButton):
216    grok.order(2)
217    grok.context(IApplicant)
218    grok.view(ApplicantDisplayFormPage)
219    grok.require('waeup.handleApplication')
220    text = _('Edit application record')
221    target ='edit'
222
223    @property
224    def target_url(self):
225        """Get a URL to the target...
226        """
227        if self.context.locked or (
228            self.context.__parent__.expired and
229            self.context.__parent__.strict_deadline):
230            return
231        return self.view.url(self.view.context, self.target)
232
233class PDFActionButton(ManageActionButton):
234    grok.order(3)
235    grok.context(IApplicant)
236    grok.require('waeup.viewApplication')
237    grok.name('pdfactionbutton')
238    icon = 'actionicon_pdf.png'
239    text = _('Download application slip')
240    target = 'application_slip.pdf'
241
242    @property
243    def target_url(self):
244        """Get a URL to the target...
245        """
246        if self.context.state in ('initialized', 'started', 'paid') \
247            or self.context.special:
248            return
249        return self.view.url(self.view.context, self.target)
250
251class StudentCreateActionButton(ManageActionButton):
252    grok.order(4)
253    grok.context(IApplicant)
254    grok.require('waeup.manageApplication')
255    icon = 'actionicon_entrance.png'
256    text = _('Create student')
257    target ='createstudent'
258
259    @property
260    def target_url(self):
261        """Get a URL to the target...
262        """
263        if self.context.state != 'admitted':
264            return
265        return self.view.url(self.view.context, self.target)
266
267class PaymentReceiptActionButton(ManageActionButton):
268    grok.order(9) # This button should always be the last one.
269    grok.context(IApplicantOnlinePayment)
270    grok.view(OnlinePaymentDisplayFormPage)
271    grok.require('waeup.viewApplication')
272    icon = 'actionicon_pdf.png'
273    text = _('Download payment slip')
274    target = 'payment_slip.pdf'
275
276    @property
277    def target_url(self):
278        #if self.context.p_state != 'paid':
279        #    return ''
280        return self.view.url(self.view.context, self.target)
281
282class ApprovePaymentActionButton(ManageActionButton):
283    grok.order(8)
284    grok.context(IApplicantOnlinePayment)
285    grok.view(OnlinePaymentDisplayFormPage)
286    grok.require('waeup.managePortal')
287    icon = 'actionicon_accept.png'
288    text = _('Approve payment')
289    target = 'approve'
290
291    @property
292    def target_url(self):
293        if self.context.p_state == 'paid':
294            return ''
295        return self.view.url(self.view.context, self.target)
Note: See TracBrowser for help on using the repository browser.