[7438] | 1 | ## $Id: viewlets.py 13076 2015-06-19 05:49:57Z 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 |
---|
[7819] | 19 | from waeup.kofa.interfaces import IKofaObject |
---|
[7811] | 20 | from waeup.kofa.students.viewlets import PrimaryStudentNavTab |
---|
[8684] | 21 | from waeup.kofa.browser.viewlets import ( |
---|
| 22 | ManageActionButton, PrimaryNavTab, AddActionButton) |
---|
[7811] | 23 | from waeup.kofa.applicants.interfaces import ( |
---|
[7438] | 24 | IApplicant, IApplicantsRoot, IApplicantsContainer, |
---|
[8563] | 25 | IApplicantOnlinePayment |
---|
[7438] | 26 | ) |
---|
[7811] | 27 | from waeup.kofa.applicants.browser import ( |
---|
[7438] | 28 | ApplicantsRootPage, ApplicantsContainerPage, ApplicantManageFormPage, |
---|
[8563] | 29 | ApplicantDisplayFormPage, OnlinePaymentDisplayFormPage, |
---|
| 30 | ApplicantsContainerManageFormPage, ApplicantsStatisticsPage |
---|
[7438] | 31 | ) |
---|
| 32 | |
---|
[7811] | 33 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
[7674] | 34 | |
---|
[7819] | 35 | grok.context(IKofaObject) # Make IKofaObject the default context |
---|
[7438] | 36 | grok.templatedir('browser_templates') |
---|
| 37 | |
---|
| 38 | class ApplicantsAuthTab(PrimaryNavTab): |
---|
| 39 | """Applicants tab in primary navigation. |
---|
| 40 | """ |
---|
[7819] | 41 | grok.context(IKofaObject) |
---|
[7438] | 42 | grok.order(3) |
---|
| 43 | grok.require('waeup.viewApplicantsTab') |
---|
| 44 | pnav = 3 |
---|
[7674] | 45 | tab_title = _(u'Applicants') |
---|
[7438] | 46 | |
---|
| 47 | @property |
---|
| 48 | def link_target(self): |
---|
| 49 | return self.view.application_url('applicants') |
---|
| 50 | |
---|
| 51 | class 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') |
---|
[7674] | 58 | tab_title = _(u'Application') |
---|
[7438] | 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 | |
---|
| 68 | class MyApplicationDataTab(PrimaryStudentNavTab): |
---|
| 69 | """MyData-tab in primary navigation. |
---|
| 70 | """ |
---|
| 71 | grok.order(3) |
---|
| 72 | grok.require('waeup.viewMyApplicationDataTab') |
---|
| 73 | pnav = 3 |
---|
[7714] | 74 | tab_title = _(u'My Data') |
---|
[7438] | 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 | |
---|
[8406] | 85 | class ApplicantsRootSearchActionButton(ManageActionButton): |
---|
[8404] | 86 | grok.order(1) |
---|
| 87 | grok.context(IApplicantsRoot) |
---|
| 88 | grok.view(ApplicantsRootPage) |
---|
| 89 | grok.require('waeup.viewApplication') |
---|
[10644] | 90 | text = _('Find applicants') |
---|
[8404] | 91 | icon = 'actionicon_search.png' |
---|
| 92 | target = '@@search' |
---|
| 93 | |
---|
[8406] | 94 | class ApplicantsRootManageActionButton(ManageActionButton): |
---|
[8404] | 95 | grok.order(2) |
---|
[7438] | 96 | grok.context(IApplicantsRoot) |
---|
| 97 | grok.view(ApplicantsRootPage) |
---|
| 98 | grok.require('waeup.manageApplication') |
---|
[13076] | 99 | text = _('Manage applicants section') |
---|
[7438] | 100 | |
---|
| 101 | class ApplicantRegisterActionButton(ManageActionButton): |
---|
[8563] | 102 | grok.order(1) |
---|
[7438] | 103 | grok.context(IApplicantsContainer) |
---|
| 104 | grok.view(ApplicantsContainerPage) |
---|
| 105 | grok.require('waeup.Anonymous') |
---|
| 106 | icon = 'actionicon_login.png' |
---|
[7714] | 107 | text = _('Register for application') |
---|
[7438] | 108 | target = 'register' |
---|
| 109 | |
---|
[8684] | 110 | class ApplicantsContainerAddActionButton(AddActionButton): |
---|
[8563] | 111 | grok.order(1) |
---|
| 112 | grok.context(IApplicantsContainer) |
---|
| 113 | grok.view(ApplicantsContainerManageFormPage) |
---|
[8684] | 114 | grok.require('waeup.manageApplication') |
---|
| 115 | text = _('Add applicant') |
---|
| 116 | target = 'addapplicant' |
---|
| 117 | |
---|
| 118 | class ApplicantsContainerStatisticsActionButton(ManageActionButton): |
---|
| 119 | grok.order(2) |
---|
| 120 | grok.context(IApplicantsContainer) |
---|
| 121 | grok.view(ApplicantsContainerManageFormPage) |
---|
[8565] | 122 | grok.require('waeup.viewApplicationStatistics') |
---|
[8563] | 123 | icon = 'actionicon_statistics.png' |
---|
| 124 | text = _('Container statistics') |
---|
| 125 | target = 'statistics' |
---|
| 126 | |
---|
[9759] | 127 | class ApplicantsContainerStatisticsActionButton2( |
---|
| 128 | ApplicantsContainerStatisticsActionButton): |
---|
[8563] | 129 | grok.order(3) |
---|
| 130 | grok.view(ApplicantsContainerPage) |
---|
| 131 | |
---|
| 132 | class ApplicantsContainerManageActionButton(ManageActionButton): |
---|
| 133 | grok.order(2) |
---|
| 134 | grok.context(IApplicantsContainer) |
---|
| 135 | grok.view(ApplicantsContainerPage) |
---|
| 136 | grok.require('waeup.manageApplication') |
---|
| 137 | text = _('Manage container') |
---|
| 138 | target = 'manage' |
---|
| 139 | |
---|
[10655] | 140 | class ExportApplicantsActionButton(ManageActionButton): |
---|
| 141 | """ 'Export applicants' button for faculties. |
---|
| 142 | """ |
---|
| 143 | grok.context(IApplicantsContainer) |
---|
| 144 | grok.view(ApplicantsContainerPage) |
---|
| 145 | grok.require('waeup.manageApplication') |
---|
| 146 | icon = 'actionicon_down.png' |
---|
| 147 | text = _('Export applicants') |
---|
| 148 | target = 'exports' |
---|
| 149 | grok.order(4) |
---|
| 150 | |
---|
[9901] | 151 | class ApplicantsRootCreateStudentsActionButton(ManageActionButton): |
---|
[9900] | 152 | grok.order(3) |
---|
| 153 | grok.context(IApplicantsRoot) |
---|
| 154 | grok.view(ApplicantsRootPage) |
---|
[9759] | 155 | grok.require('waeup.managePortal') |
---|
| 156 | icon = 'actionicon_entrance.png' |
---|
[9901] | 157 | text = _('Create students') |
---|
[9759] | 158 | target ='createallstudents' |
---|
| 159 | |
---|
[11874] | 160 | @property |
---|
| 161 | def target_url(self): |
---|
| 162 | if self.target and self.request.principal.id == 'admin': |
---|
| 163 | return self.view.url(self.view.context, self.target) |
---|
| 164 | return |
---|
| 165 | |
---|
[9901] | 166 | class ApplicantsContainerCreateStudentsActionButton(ManageActionButton): |
---|
| 167 | grok.order(1) |
---|
[9900] | 168 | grok.context(IApplicantsContainer) |
---|
| 169 | grok.view(ApplicantsStatisticsPage) |
---|
[9901] | 170 | grok.require('waeup.managePortal') |
---|
| 171 | icon = 'actionicon_entrance.png' |
---|
| 172 | text = _('Create students') |
---|
| 173 | target ='createallstudents' |
---|
[9900] | 174 | |
---|
[11874] | 175 | @property |
---|
| 176 | def target_url(self): |
---|
| 177 | if self.target and self.request.principal.id == 'admin': |
---|
| 178 | return self.view.url(self.view.context, self.target) |
---|
| 179 | return |
---|
| 180 | |
---|
[7438] | 181 | class ApplicantViewActionButton(ManageActionButton): |
---|
| 182 | grok.context(IApplicant) |
---|
| 183 | grok.view(ApplicantManageFormPage) |
---|
| 184 | grok.require('waeup.viewApplication') |
---|
| 185 | icon = 'actionicon_view.png' |
---|
[7714] | 186 | text = _('View application record') |
---|
[7438] | 187 | target = 'index' |
---|
| 188 | |
---|
| 189 | class ApplicantManageActionButton(ManageActionButton): |
---|
| 190 | grok.order(1) |
---|
| 191 | grok.context(IApplicant) |
---|
| 192 | grok.view(ApplicantDisplayFormPage) |
---|
| 193 | grok.require('waeup.manageApplication') |
---|
[7714] | 194 | text = _('Manage application record') |
---|
[7438] | 195 | target = 'manage' |
---|
| 196 | |
---|
| 197 | class ApplicantEditActionButton(ManageActionButton): |
---|
| 198 | grok.order(2) |
---|
| 199 | grok.context(IApplicant) |
---|
| 200 | grok.view(ApplicantDisplayFormPage) |
---|
| 201 | grok.require('waeup.handleApplication') |
---|
[7714] | 202 | text = _('Edit application record') |
---|
[7438] | 203 | target ='edit' |
---|
| 204 | |
---|
| 205 | @property |
---|
| 206 | def target_url(self): |
---|
| 207 | """Get a URL to the target... |
---|
| 208 | """ |
---|
[8665] | 209 | if self.context.locked or ( |
---|
| 210 | self.context.__parent__.expired and |
---|
| 211 | self.context.__parent__.strict_deadline): |
---|
[7438] | 212 | return |
---|
| 213 | return self.view.url(self.view.context, self.target) |
---|
| 214 | |
---|
| 215 | class PDFActionButton(ManageActionButton): |
---|
| 216 | grok.order(3) |
---|
| 217 | grok.context(IApplicant) |
---|
| 218 | grok.require('waeup.viewApplication') |
---|
[10802] | 219 | grok.name('pdfactionbutton') |
---|
[7438] | 220 | icon = 'actionicon_pdf.png' |
---|
[7714] | 221 | text = _('Download application slip') |
---|
[7438] | 222 | target = 'application_slip.pdf' |
---|
| 223 | |
---|
[8666] | 224 | @property |
---|
| 225 | def target_url(self): |
---|
| 226 | """Get a URL to the target... |
---|
| 227 | """ |
---|
[11599] | 228 | if self.context.state in ('initialized', 'started', 'paid') \ |
---|
| 229 | or self.context.special: |
---|
[8666] | 230 | return |
---|
| 231 | return self.view.url(self.view.context, self.target) |
---|
| 232 | |
---|
[7438] | 233 | class StudentCreateActionButton(ManageActionButton): |
---|
| 234 | grok.order(4) |
---|
| 235 | grok.context(IApplicant) |
---|
| 236 | grok.require('waeup.manageApplication') |
---|
| 237 | icon = 'actionicon_entrance.png' |
---|
[7714] | 238 | text = _('Create student record') |
---|
[7438] | 239 | target ='createstudent' |
---|
| 240 | |
---|
| 241 | @property |
---|
| 242 | def target_url(self): |
---|
| 243 | """Get a URL to the target... |
---|
| 244 | """ |
---|
[8666] | 245 | if self.context.state != 'admitted': |
---|
[7438] | 246 | return |
---|
| 247 | return self.view.url(self.view.context, self.target) |
---|
| 248 | |
---|
| 249 | class PaymentReceiptActionButton(ManageActionButton): |
---|
[9070] | 250 | grok.order(9) # This button should always be the last one. |
---|
[7438] | 251 | grok.context(IApplicantOnlinePayment) |
---|
| 252 | grok.view(OnlinePaymentDisplayFormPage) |
---|
| 253 | grok.require('waeup.viewApplication') |
---|
| 254 | icon = 'actionicon_pdf.png' |
---|
[8262] | 255 | text = _('Download payment slip') |
---|
| 256 | target = 'payment_slip.pdf' |
---|
[7438] | 257 | |
---|
| 258 | @property |
---|
| 259 | def target_url(self): |
---|
[8262] | 260 | #if self.context.p_state != 'paid': |
---|
| 261 | # return '' |
---|
[7438] | 262 | return self.view.url(self.view.context, self.target) |
---|
| 263 | |
---|
[8420] | 264 | class ApprovePaymentActionButton(ManageActionButton): |
---|
[9070] | 265 | grok.order(8) |
---|
[7438] | 266 | grok.context(IApplicantOnlinePayment) |
---|
| 267 | grok.view(OnlinePaymentDisplayFormPage) |
---|
[8420] | 268 | grok.require('waeup.managePortal') |
---|
[8435] | 269 | icon = 'actionicon_accept.png' |
---|
[8420] | 270 | text = _('Approve payment') |
---|
| 271 | target = 'approve' |
---|
[7438] | 272 | |
---|
| 273 | @property |
---|
| 274 | def target_url(self): |
---|
[8243] | 275 | if self.context.p_state == 'paid': |
---|
[7438] | 276 | return '' |
---|
[7811] | 277 | return self.view.url(self.view.context, self.target) |
---|