[10765] | 1 | ## $Id: viewlets.py 15942 2020-01-20 17:23:31Z 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 | |
---|
| 19 | import grok |
---|
[15802] | 20 | from zope.component import getUtility |
---|
[15849] | 21 | from waeup.kofa.interfaces import REQUESTED, IExtFileStore |
---|
[10765] | 22 | from waeup.kofa.browser.viewlets import ManageActionButton |
---|
[15802] | 23 | from waeup.kofa.students.interfaces import IStudent, IStudentsUtils |
---|
[15563] | 24 | from kofacustom.iuokada.students.interfaces import ( |
---|
[15859] | 25 | ICustomStudentStudyCourse, ICustomStudentStudyLevel, ICustomStudent) |
---|
[12430] | 26 | from waeup.kofa.students.fileviewlets import ( |
---|
[12450] | 27 | StudentFileDisplay, StudentFileUpload, StudentImage) |
---|
[10765] | 28 | from waeup.kofa.students.browser import ( |
---|
[13062] | 29 | ExportPDFClearanceSlip, StudyCourseDisplayFormPage, |
---|
[15802] | 30 | StudyLevelDisplayFormPage, StudentBaseDisplayFormPage) |
---|
[10765] | 31 | |
---|
| 32 | from kofacustom.nigeria.interfaces import MessageFactory as _ |
---|
[15650] | 33 | |
---|
[15859] | 34 | class SwitchLibraryAccessActionButton(ManageActionButton): |
---|
| 35 | grok.order(7) |
---|
| 36 | grok.context(ICustomStudent) |
---|
| 37 | grok.view(StudentBaseDisplayFormPage) |
---|
| 38 | grok.require('waeup.switchLibraryAccess') |
---|
| 39 | text = _('Switch library access') |
---|
| 40 | target = 'switch_library_access' |
---|
| 41 | icon = 'actionicon_book.png' |
---|
| 42 | |
---|
| 43 | |
---|
[15802] | 44 | class GetMatricNumberActionButton(ManageActionButton): |
---|
| 45 | grok.order(10) |
---|
| 46 | grok.context(IStudent) |
---|
| 47 | grok.view(StudentBaseDisplayFormPage) |
---|
[15805] | 48 | grok.require('waeup.manageStudent') |
---|
[15802] | 49 | icon = 'actionicon_count.png' |
---|
| 50 | text = _('Get Matriculation Number') |
---|
| 51 | |
---|
| 52 | @property |
---|
| 53 | def target_url(self): |
---|
| 54 | students_utils = getUtility(IStudentsUtils) |
---|
| 55 | if self.context.matric_number: |
---|
| 56 | return '' |
---|
| 57 | error, matric_number = students_utils.constructMatricNumber( |
---|
| 58 | self.context) |
---|
| 59 | if error: |
---|
| 60 | return '' |
---|
| 61 | return self.view.url(self.view.context, 'get_matric_number') |
---|
| 62 | |
---|
[15859] | 63 | # Library |
---|
| 64 | |
---|
| 65 | class LibraryIdCardActionButton(ManageActionButton): |
---|
| 66 | grok.order(10) |
---|
| 67 | grok.context(ICustomStudent) |
---|
| 68 | grok.view(StudentBaseDisplayFormPage) |
---|
| 69 | grok.require('waeup.viewStudent') |
---|
| 70 | icon = 'actionicon_pdf.png' |
---|
| 71 | text = _('Download Library Id Card') |
---|
| 72 | target = 'lib_idcard.pdf' |
---|
| 73 | |
---|
| 74 | @property |
---|
| 75 | def target_url(self): |
---|
| 76 | if self.context.library: |
---|
| 77 | return self.view.url(self.view.context, self.target) |
---|
| 78 | return |
---|
| 79 | |
---|
[15650] | 80 | # Signature |
---|
| 81 | |
---|
| 82 | class SignatureDisplay(StudentFileDisplay): |
---|
| 83 | """Signature display viewlet. |
---|
| 84 | """ |
---|
| 85 | grok.order(2) |
---|
| 86 | label = _(u'Signature') |
---|
| 87 | title = _(u'Signature Scan') |
---|
| 88 | download_name = u'signature' |
---|
| 89 | |
---|
| 90 | class SignatureSlip(SignatureDisplay): |
---|
| 91 | grok.view(ExportPDFClearanceSlip) |
---|
| 92 | |
---|
| 93 | class SignatureUpload(StudentFileUpload): |
---|
| 94 | """Signature upload viewlet. |
---|
| 95 | """ |
---|
| 96 | grok.order(2) |
---|
| 97 | label = _(u'Signature') |
---|
| 98 | title = _(u'Signature Scan') |
---|
| 99 | download_name = u'signature' |
---|
| 100 | |
---|
| 101 | class SignatureImage(StudentImage): |
---|
[15942] | 102 | """Renders signature scan. |
---|
[15650] | 103 | """ |
---|
| 104 | grok.name('signature') |
---|
| 105 | download_name = u'signature' |
---|
| 106 | |
---|
[15849] | 107 | class SignatureDownloadButton(ManageActionButton): |
---|
| 108 | |
---|
| 109 | grok.order(12) |
---|
| 110 | grok.context(IStudent) |
---|
| 111 | grok.view(StudentBaseDisplayFormPage) |
---|
| 112 | grok.require('waeup.manageStudent') |
---|
| 113 | target = 'signature' |
---|
| 114 | text = _('Signature') |
---|
| 115 | icon = 'actionicon_signature.png' |
---|
| 116 | |
---|
| 117 | @property |
---|
| 118 | def target_url(self): |
---|
| 119 | image = getUtility(IExtFileStore).getFileByContext( |
---|
| 120 | self.context, attr='signature') |
---|
| 121 | if not image: |
---|
| 122 | return '' |
---|
| 123 | return self.view.url(self.view.context, self.target) |
---|
| 124 | |
---|
[15654] | 125 | # JAMB Result |
---|
| 126 | |
---|
| 127 | class JAMBResultDisplay(StudentFileDisplay): |
---|
| 128 | """JAMB Result display viewlet. |
---|
| 129 | """ |
---|
| 130 | grok.order(9) |
---|
| 131 | label = _(u'JAMB Result') |
---|
| 132 | title = _(u'JAMB Result') |
---|
| 133 | download_name = u'jamb' |
---|
| 134 | |
---|
| 135 | class JAMBResultSlip(JAMBResultDisplay): |
---|
| 136 | grok.view(ExportPDFClearanceSlip) |
---|
| 137 | |
---|
| 138 | class JAMBResultUpload(StudentFileUpload): |
---|
| 139 | """JAMB Result upload viewlet. |
---|
| 140 | """ |
---|
| 141 | grok.order(9) |
---|
| 142 | label = _(u'JAMB Result') |
---|
| 143 | title = _(u'JAMB Result Scan') |
---|
| 144 | download_name = u'jamb' |
---|
| 145 | |
---|
| 146 | class JAMBResultImage(StudentImage): |
---|
| 147 | """Renders JAMB Result scan. |
---|
| 148 | """ |
---|
| 149 | grok.name('jamb') |
---|
| 150 | download_name = u'jamb' |
---|
| 151 | |
---|