1 | ## $Id: viewlets.py 7714 2012-02-28 10:34:16Z 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 | ## |
---|
18 | import grok |
---|
19 | from hurry.workflow.interfaces import IWorkflowState |
---|
20 | from waeup.sirp.interfaces import ISIRPObject |
---|
21 | from waeup.sirp.students.viewlets import PrimaryStudentNavTab |
---|
22 | from waeup.sirp.browser.viewlets import ManageActionButton, PrimaryNavTab |
---|
23 | from waeup.sirp.applicants.interfaces import ( |
---|
24 | IApplicant, IApplicantsRoot, IApplicantsContainer, |
---|
25 | IApplicantOnlinePayment, |
---|
26 | ) |
---|
27 | from waeup.sirp.applicants.browser import ( |
---|
28 | ApplicantsRootPage, ApplicantsContainerPage, ApplicantManageFormPage, |
---|
29 | ApplicantDisplayFormPage, OnlinePaymentDisplayFormPage |
---|
30 | ) |
---|
31 | |
---|
32 | from waeup.sirp.interfaces import MessageFactory as _ |
---|
33 | |
---|
34 | grok.context(ISIRPObject) # Make ISIRPObject the default context |
---|
35 | grok.templatedir('browser_templates') |
---|
36 | |
---|
37 | class ApplicantsAuthTab(PrimaryNavTab): |
---|
38 | """Applicants tab in primary navigation. |
---|
39 | """ |
---|
40 | grok.context(ISIRPObject) |
---|
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 | |
---|
50 | class 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 | |
---|
67 | class 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 | |
---|
84 | class ManageApplicantsRootActionButton(ManageActionButton): |
---|
85 | grok.context(IApplicantsRoot) |
---|
86 | grok.view(ApplicantsRootPage) |
---|
87 | grok.require('waeup.manageApplication') |
---|
88 | text = _('Manage application section') |
---|
89 | |
---|
90 | class ApplicantsContainerManageActionButton(ManageActionButton): |
---|
91 | grok.order(1) |
---|
92 | grok.context(IApplicantsContainer) |
---|
93 | grok.view(ApplicantsContainerPage) |
---|
94 | grok.require('waeup.manageApplication') |
---|
95 | text = _('Manage applicants container') |
---|
96 | |
---|
97 | class ApplicantRegisterActionButton(ManageActionButton): |
---|
98 | grok.order(2) |
---|
99 | grok.context(IApplicantsContainer) |
---|
100 | grok.view(ApplicantsContainerPage) |
---|
101 | grok.require('waeup.Anonymous') |
---|
102 | icon = 'actionicon_login.png' |
---|
103 | text = _('Register for application') |
---|
104 | target = 'register' |
---|
105 | |
---|
106 | class ApplicantViewActionButton(ManageActionButton): |
---|
107 | grok.context(IApplicant) |
---|
108 | grok.view(ApplicantManageFormPage) |
---|
109 | grok.require('waeup.viewApplication') |
---|
110 | icon = 'actionicon_view.png' |
---|
111 | text = _('View application record') |
---|
112 | target = 'index' |
---|
113 | |
---|
114 | class ApplicantManageActionButton(ManageActionButton): |
---|
115 | grok.order(1) |
---|
116 | grok.context(IApplicant) |
---|
117 | grok.view(ApplicantDisplayFormPage) |
---|
118 | grok.require('waeup.manageApplication') |
---|
119 | text = _('Manage application record') |
---|
120 | target = 'manage' |
---|
121 | |
---|
122 | class ApplicantEditActionButton(ManageActionButton): |
---|
123 | grok.order(2) |
---|
124 | grok.context(IApplicant) |
---|
125 | grok.view(ApplicantDisplayFormPage) |
---|
126 | grok.require('waeup.handleApplication') |
---|
127 | text = _('Edit application record') |
---|
128 | target ='edit' |
---|
129 | |
---|
130 | @property |
---|
131 | def target_url(self): |
---|
132 | """Get a URL to the target... |
---|
133 | """ |
---|
134 | if self.context.locked: |
---|
135 | return |
---|
136 | return self.view.url(self.view.context, self.target) |
---|
137 | |
---|
138 | class PDFActionButton(ManageActionButton): |
---|
139 | grok.order(3) |
---|
140 | grok.context(IApplicant) |
---|
141 | grok.require('waeup.viewApplication') |
---|
142 | icon = 'actionicon_pdf.png' |
---|
143 | text = _('Download application slip') |
---|
144 | target = 'application_slip.pdf' |
---|
145 | |
---|
146 | class StudentCreateActionButton(ManageActionButton): |
---|
147 | grok.order(4) |
---|
148 | grok.context(IApplicant) |
---|
149 | grok.require('waeup.manageApplication') |
---|
150 | icon = 'actionicon_entrance.png' |
---|
151 | text = _('Create student record') |
---|
152 | target ='createstudent' |
---|
153 | |
---|
154 | @property |
---|
155 | def target_url(self): |
---|
156 | """Get a URL to the target... |
---|
157 | """ |
---|
158 | if IWorkflowState(self.context).getState() != 'admitted': |
---|
159 | return |
---|
160 | return self.view.url(self.view.context, self.target) |
---|
161 | |
---|
162 | class PaymentReceiptActionButton(ManageActionButton): |
---|
163 | grok.order(1) |
---|
164 | grok.context(IApplicantOnlinePayment) |
---|
165 | grok.view(OnlinePaymentDisplayFormPage) |
---|
166 | grok.require('waeup.viewApplication') |
---|
167 | icon = 'actionicon_pdf.png' |
---|
168 | text = _('Download payment receipt') |
---|
169 | target = 'payment_receipt.pdf' |
---|
170 | |
---|
171 | @property |
---|
172 | def target_url(self): |
---|
173 | if self.context.p_state != 'paid': |
---|
174 | return '' |
---|
175 | return self.view.url(self.view.context, self.target) |
---|
176 | |
---|
177 | class RequestCallbackActionButton(ManageActionButton): |
---|
178 | grok.order(2) |
---|
179 | grok.context(IApplicantOnlinePayment) |
---|
180 | grok.view(OnlinePaymentDisplayFormPage) |
---|
181 | grok.require('waeup.payApplicant') |
---|
182 | icon = 'actionicon_call.png' |
---|
183 | text = _('Request callback') |
---|
184 | target = 'callback' |
---|
185 | |
---|
186 | @property |
---|
187 | def target_url(self): |
---|
188 | if self.context.p_state != 'unpaid': |
---|
189 | return '' |
---|
190 | return self.view.url(self.view.context, self.target) |
---|