[7438] | 1 | ## $Id: viewlets.py 16214 2020-08-26 15:39:36Z 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, |
---|
[16058] | 25 | IApplicantOnlinePayment, IApplicantRefereeReport |
---|
[7438] | 26 | ) |
---|
[7811] | 27 | from waeup.kofa.applicants.browser import ( |
---|
[7438] | 28 | ApplicantsRootPage, ApplicantsContainerPage, ApplicantManageFormPage, |
---|
[8563] | 29 | ApplicantDisplayFormPage, OnlinePaymentDisplayFormPage, |
---|
[16058] | 30 | ApplicantsContainerManageFormPage, ApplicantsStatisticsPage, |
---|
| 31 | RefereeReportDisplayFormPage |
---|
[7438] | 32 | ) |
---|
| 33 | |
---|
[7811] | 34 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
[7674] | 35 | |
---|
[7819] | 36 | grok.context(IKofaObject) # Make IKofaObject the default context |
---|
[7438] | 37 | grok.templatedir('browser_templates') |
---|
| 38 | |
---|
| 39 | class ApplicantsAuthTab(PrimaryNavTab): |
---|
| 40 | """Applicants tab in primary navigation. |
---|
| 41 | """ |
---|
[7819] | 42 | grok.context(IKofaObject) |
---|
[7438] | 43 | grok.order(3) |
---|
| 44 | grok.require('waeup.viewApplicantsTab') |
---|
| 45 | pnav = 3 |
---|
[7674] | 46 | tab_title = _(u'Applicants') |
---|
[7438] | 47 | |
---|
| 48 | @property |
---|
| 49 | def link_target(self): |
---|
| 50 | return self.view.application_url('applicants') |
---|
| 51 | |
---|
| 52 | class ApplicantsAnonTab(ApplicantsAuthTab): |
---|
| 53 | """Applicants tab in primary navigation. |
---|
| 54 | |
---|
| 55 | Display tab only for anonymous. Authenticated users can call the |
---|
| 56 | form from the user navigation bar. |
---|
| 57 | """ |
---|
| 58 | grok.require('waeup.Anonymous') |
---|
[7674] | 59 | tab_title = _(u'Application') |
---|
[7438] | 60 | |
---|
| 61 | # Also zope.manager has role Anonymous. |
---|
| 62 | # To avoid displaying this tab, we have to check the principal id too. |
---|
| 63 | @property |
---|
| 64 | def link_target(self): |
---|
| 65 | if self.request.principal.id == 'zope.anybody': |
---|
| 66 | return self.view.application_url('applicants') |
---|
| 67 | return |
---|
| 68 | |
---|
| 69 | class MyApplicationDataTab(PrimaryStudentNavTab): |
---|
| 70 | """MyData-tab in primary navigation. |
---|
| 71 | """ |
---|
| 72 | grok.order(3) |
---|
| 73 | grok.require('waeup.viewMyApplicationDataTab') |
---|
| 74 | pnav = 3 |
---|
[7714] | 75 | tab_title = _(u'My Data') |
---|
[7438] | 76 | |
---|
| 77 | @property |
---|
| 78 | def link_target(self): |
---|
| 79 | try: |
---|
| 80 | container, application_number = self.request.principal.id.split('_') |
---|
| 81 | except ValueError: |
---|
| 82 | return |
---|
| 83 | rel_link = '/applicants/%s/%s' % (container, application_number) |
---|
| 84 | return self.view.application_url() + rel_link |
---|
| 85 | |
---|
[8406] | 86 | class ApplicantsRootSearchActionButton(ManageActionButton): |
---|
[8404] | 87 | grok.order(1) |
---|
| 88 | grok.context(IApplicantsRoot) |
---|
| 89 | grok.view(ApplicantsRootPage) |
---|
| 90 | grok.require('waeup.viewApplication') |
---|
[10644] | 91 | text = _('Find applicants') |
---|
[8404] | 92 | icon = 'actionicon_search.png' |
---|
| 93 | target = '@@search' |
---|
| 94 | |
---|
[8406] | 95 | class ApplicantsRootManageActionButton(ManageActionButton): |
---|
[8404] | 96 | grok.order(2) |
---|
[7438] | 97 | grok.context(IApplicantsRoot) |
---|
| 98 | grok.view(ApplicantsRootPage) |
---|
| 99 | grok.require('waeup.manageApplication') |
---|
[13076] | 100 | text = _('Manage applicants section') |
---|
[7438] | 101 | |
---|
| 102 | class ApplicantRegisterActionButton(ManageActionButton): |
---|
[8563] | 103 | grok.order(1) |
---|
[7438] | 104 | grok.context(IApplicantsContainer) |
---|
| 105 | grok.view(ApplicantsContainerPage) |
---|
| 106 | grok.require('waeup.Anonymous') |
---|
| 107 | icon = 'actionicon_login.png' |
---|
[7714] | 108 | text = _('Register for application') |
---|
[7438] | 109 | target = 'register' |
---|
| 110 | |
---|
[8684] | 111 | class ApplicantsContainerAddActionButton(AddActionButton): |
---|
[8563] | 112 | grok.order(1) |
---|
| 113 | grok.context(IApplicantsContainer) |
---|
| 114 | grok.view(ApplicantsContainerManageFormPage) |
---|
[8684] | 115 | grok.require('waeup.manageApplication') |
---|
| 116 | text = _('Add applicant') |
---|
| 117 | target = 'addapplicant' |
---|
| 118 | |
---|
[13218] | 119 | class ApplicantsContainerPrefillActionButton(ManageActionButton): |
---|
[8684] | 120 | grok.order(2) |
---|
| 121 | grok.context(IApplicantsContainer) |
---|
| 122 | grok.view(ApplicantsContainerManageFormPage) |
---|
[13217] | 123 | grok.require('waeup.manageApplication') |
---|
| 124 | icon = 'actionicon_bucketfill.png' |
---|
| 125 | text = _('Pre-fill container') |
---|
| 126 | target = 'prefill' |
---|
| 127 | |
---|
[13218] | 128 | class ApplicantsContainerPurgeActionButton(ManageActionButton): |
---|
[13217] | 129 | grok.order(3) |
---|
| 130 | grok.context(IApplicantsContainer) |
---|
| 131 | grok.view(ApplicantsContainerManageFormPage) |
---|
[13218] | 132 | grok.require('waeup.manageApplication') |
---|
| 133 | icon = 'actionicon_sweep.png' |
---|
| 134 | text = _('Purge container') |
---|
| 135 | target = 'purge' |
---|
| 136 | |
---|
| 137 | class ApplicantsContainerStatisticsActionButton(ManageActionButton): |
---|
| 138 | grok.order(4) |
---|
| 139 | grok.context(IApplicantsContainer) |
---|
| 140 | grok.view(ApplicantsContainerManageFormPage) |
---|
[8565] | 141 | grok.require('waeup.viewApplicationStatistics') |
---|
[8563] | 142 | icon = 'actionicon_statistics.png' |
---|
| 143 | text = _('Container statistics') |
---|
| 144 | target = 'statistics' |
---|
| 145 | |
---|
[9759] | 146 | class ApplicantsContainerStatisticsActionButton2( |
---|
| 147 | ApplicantsContainerStatisticsActionButton): |
---|
[13218] | 148 | grok.order(5) |
---|
[8563] | 149 | grok.view(ApplicantsContainerPage) |
---|
| 150 | |
---|
| 151 | class ApplicantsContainerManageActionButton(ManageActionButton): |
---|
| 152 | grok.order(2) |
---|
| 153 | grok.context(IApplicantsContainer) |
---|
| 154 | grok.view(ApplicantsContainerPage) |
---|
| 155 | grok.require('waeup.manageApplication') |
---|
| 156 | text = _('Manage container') |
---|
| 157 | target = 'manage' |
---|
| 158 | |
---|
[10655] | 159 | class ExportApplicantsActionButton(ManageActionButton): |
---|
[13951] | 160 | """ 'Export data' button for faculties. |
---|
[10655] | 161 | """ |
---|
| 162 | grok.context(IApplicantsContainer) |
---|
| 163 | grok.view(ApplicantsContainerPage) |
---|
| 164 | grok.require('waeup.manageApplication') |
---|
| 165 | icon = 'actionicon_down.png' |
---|
[13951] | 166 | text = _('Export application data') |
---|
[10655] | 167 | target = 'exports' |
---|
| 168 | grok.order(4) |
---|
| 169 | |
---|
[14934] | 170 | creation_warning = _( |
---|
| 171 | "'The creation process may take a considerably long time " |
---|
| 172 | "depending on the number of student records to be created " |
---|
| 173 | "(appr. 0.5s per student). " |
---|
| 174 | "All users will be logged out and the portal will be in " |
---|
[14935] | 175 | "maintenance mode during record creation. You will be automatically " |
---|
| 176 | "logged in when the creation process is finished. " |
---|
| 177 | "Do you really want to start now?'") |
---|
[14934] | 178 | |
---|
[9901] | 179 | class ApplicantsRootCreateStudentsActionButton(ManageActionButton): |
---|
[9900] | 180 | grok.order(3) |
---|
| 181 | grok.context(IApplicantsRoot) |
---|
| 182 | grok.view(ApplicantsRootPage) |
---|
[14948] | 183 | grok.require('waeup.createStudents') |
---|
[9759] | 184 | icon = 'actionicon_entrance.png' |
---|
[9901] | 185 | text = _('Create students') |
---|
[9759] | 186 | target ='createallstudents' |
---|
| 187 | |
---|
[11874] | 188 | @property |
---|
[14934] | 189 | def onclick(self): |
---|
| 190 | return "return window.confirm(%s);" % creation_warning |
---|
[11874] | 191 | |
---|
[9901] | 192 | class ApplicantsContainerCreateStudentsActionButton(ManageActionButton): |
---|
[13101] | 193 | grok.order(5) |
---|
[9900] | 194 | grok.context(IApplicantsContainer) |
---|
[13101] | 195 | grok.view(ApplicantsContainerPage) |
---|
[14948] | 196 | grok.require('waeup.createStudents') |
---|
[9901] | 197 | icon = 'actionicon_entrance.png' |
---|
| 198 | text = _('Create students') |
---|
| 199 | target ='createallstudents' |
---|
[9900] | 200 | |
---|
[11874] | 201 | @property |
---|
[14934] | 202 | def onclick(self): |
---|
| 203 | return "return window.confirm(%s);" % creation_warning |
---|
[11874] | 204 | |
---|
[7438] | 205 | class ApplicantViewActionButton(ManageActionButton): |
---|
| 206 | grok.context(IApplicant) |
---|
| 207 | grok.view(ApplicantManageFormPage) |
---|
| 208 | grok.require('waeup.viewApplication') |
---|
| 209 | icon = 'actionicon_view.png' |
---|
[7714] | 210 | text = _('View application record') |
---|
[7438] | 211 | target = 'index' |
---|
| 212 | |
---|
| 213 | class ApplicantManageActionButton(ManageActionButton): |
---|
| 214 | grok.order(1) |
---|
| 215 | grok.context(IApplicant) |
---|
| 216 | grok.view(ApplicantDisplayFormPage) |
---|
| 217 | grok.require('waeup.manageApplication') |
---|
[7714] | 218 | text = _('Manage application record') |
---|
[7438] | 219 | target = 'manage' |
---|
| 220 | |
---|
| 221 | class ApplicantEditActionButton(ManageActionButton): |
---|
| 222 | grok.order(2) |
---|
| 223 | grok.context(IApplicant) |
---|
| 224 | grok.view(ApplicantDisplayFormPage) |
---|
| 225 | grok.require('waeup.handleApplication') |
---|
[7714] | 226 | text = _('Edit application record') |
---|
[7438] | 227 | target ='edit' |
---|
| 228 | |
---|
| 229 | @property |
---|
| 230 | def target_url(self): |
---|
| 231 | """Get a URL to the target... |
---|
| 232 | """ |
---|
[8665] | 233 | if self.context.locked or ( |
---|
| 234 | self.context.__parent__.expired and |
---|
| 235 | self.context.__parent__.strict_deadline): |
---|
[7438] | 236 | return |
---|
| 237 | return self.view.url(self.view.context, self.target) |
---|
| 238 | |
---|
| 239 | class PDFActionButton(ManageActionButton): |
---|
| 240 | grok.order(3) |
---|
| 241 | grok.context(IApplicant) |
---|
| 242 | grok.require('waeup.viewApplication') |
---|
[10802] | 243 | grok.name('pdfactionbutton') |
---|
[7438] | 244 | icon = 'actionicon_pdf.png' |
---|
[7714] | 245 | text = _('Download application slip') |
---|
[7438] | 246 | target = 'application_slip.pdf' |
---|
| 247 | |
---|
[8666] | 248 | @property |
---|
| 249 | def target_url(self): |
---|
| 250 | """Get a URL to the target... |
---|
| 251 | """ |
---|
[11599] | 252 | if self.context.state in ('initialized', 'started', 'paid') \ |
---|
| 253 | or self.context.special: |
---|
[8666] | 254 | return |
---|
| 255 | return self.view.url(self.view.context, self.target) |
---|
| 256 | |
---|
[7438] | 257 | class StudentCreateActionButton(ManageActionButton): |
---|
| 258 | grok.order(4) |
---|
| 259 | grok.context(IApplicant) |
---|
[14948] | 260 | grok.require('waeup.createStudents') |
---|
[7438] | 261 | icon = 'actionicon_entrance.png' |
---|
[13108] | 262 | text = _('Create student') |
---|
[7438] | 263 | target ='createstudent' |
---|
| 264 | |
---|
| 265 | @property |
---|
| 266 | def target_url(self): |
---|
| 267 | """Get a URL to the target... |
---|
| 268 | """ |
---|
[8666] | 269 | if self.context.state != 'admitted': |
---|
[7438] | 270 | return |
---|
| 271 | return self.view.url(self.view.context, self.target) |
---|
| 272 | |
---|
[16214] | 273 | class RemindRefereesActionButton(ManageActionButton): |
---|
| 274 | grok.order(5) |
---|
| 275 | grok.context(IApplicant) |
---|
| 276 | grok.require('waeup.manageApplication') |
---|
| 277 | icon = 'actionicon_alarm.png' |
---|
| 278 | text = _('Remind referees') |
---|
| 279 | target ='remind_referees' |
---|
| 280 | |
---|
| 281 | @property |
---|
| 282 | def onclick(self): |
---|
| 283 | return "return window.confirm(%s);" % _( |
---|
| 284 | "'Those referees, who have not yet submitted their report, will be reminded by email. Are you sure?'") |
---|
| 285 | |
---|
| 286 | @property |
---|
| 287 | def target_url(self): |
---|
| 288 | """Get a URL to the target... |
---|
| 289 | """ |
---|
| 290 | if self.context.state != 'submitted': |
---|
| 291 | return |
---|
| 292 | if not self.context.referees: |
---|
| 293 | return |
---|
| 294 | return self.view.url(self.view.context, self.target) |
---|
| 295 | |
---|
[7438] | 296 | class PaymentReceiptActionButton(ManageActionButton): |
---|
[9070] | 297 | grok.order(9) # This button should always be the last one. |
---|
[7438] | 298 | grok.context(IApplicantOnlinePayment) |
---|
| 299 | grok.view(OnlinePaymentDisplayFormPage) |
---|
| 300 | grok.require('waeup.viewApplication') |
---|
| 301 | icon = 'actionicon_pdf.png' |
---|
[8262] | 302 | text = _('Download payment slip') |
---|
| 303 | target = 'payment_slip.pdf' |
---|
[7438] | 304 | |
---|
| 305 | @property |
---|
| 306 | def target_url(self): |
---|
[8262] | 307 | #if self.context.p_state != 'paid': |
---|
| 308 | # return '' |
---|
[7438] | 309 | return self.view.url(self.view.context, self.target) |
---|
| 310 | |
---|
[8420] | 311 | class ApprovePaymentActionButton(ManageActionButton): |
---|
[9070] | 312 | grok.order(8) |
---|
[7438] | 313 | grok.context(IApplicantOnlinePayment) |
---|
| 314 | grok.view(OnlinePaymentDisplayFormPage) |
---|
[8420] | 315 | grok.require('waeup.managePortal') |
---|
[8435] | 316 | icon = 'actionicon_accept.png' |
---|
[8420] | 317 | text = _('Approve payment') |
---|
| 318 | target = 'approve' |
---|
[7438] | 319 | |
---|
| 320 | @property |
---|
| 321 | def target_url(self): |
---|
[15843] | 322 | if self.context.p_state in ('paid', 'waived', 'scholarship'): |
---|
[7438] | 323 | return '' |
---|
[7811] | 324 | return self.view.url(self.view.context, self.target) |
---|
[16059] | 325 | |
---|
| 326 | class ReportSlipActionButton(ManageActionButton): |
---|
| 327 | grok.order(1) |
---|
| 328 | grok.context(IApplicantRefereeReport) |
---|
| 329 | grok.view(RefereeReportDisplayFormPage) |
---|
| 330 | grok.require('waeup.manageApplication') |
---|
| 331 | icon = 'actionicon_pdf.png' |
---|
| 332 | text = _('Download referee report slip') |
---|
| 333 | target = 'referee_report_slip.pdf' |
---|
| 334 | |
---|
| 335 | @property |
---|
| 336 | def target_url(self): |
---|
| 337 | return self.view.url(self.view.context, self.target) |
---|
| 338 | |
---|
| 339 | deletion_warning = _( |
---|
| 340 | "'The report will be irrevocably deleted. Are you sure?'") |
---|
| 341 | |
---|
| 342 | class ReportRemoveActionButton(ManageActionButton): |
---|
| 343 | grok.order(2) |
---|
| 344 | grok.context(IApplicantRefereeReport) |
---|
| 345 | grok.view(RefereeReportDisplayFormPage) |
---|
| 346 | grok.require('waeup.manageApplication') |
---|
| 347 | icon = 'actionicon_reject.png' |
---|
| 348 | text = _('Delete referee report') |
---|
| 349 | target = 'remove' |
---|
| 350 | |
---|
| 351 | @property |
---|
| 352 | def onclick(self): |
---|
| 353 | return "return window.confirm(%s);" % deletion_warning |
---|