| 1 | ## $Id: viewlets.py 13380 2015-11-02 11:14:33Z 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 |
|---|
| 20 | from zope.component import getUtility |
|---|
| 21 | from waeup.kofa.interfaces import REGISTERED |
|---|
| 22 | from waeup.kofa.students.interfaces import IStudent, IStudentsUtils |
|---|
| 23 | from waeup.kofa.students.workflow import PAID |
|---|
| 24 | from waeup.kofa.students.viewlets import ( |
|---|
| 25 | AddPreviousPaymentActionButton, AddBalancePaymentActionButton, |
|---|
| 26 | ManageActionButton, StudentBaseDisplayFormPage, |
|---|
| 27 | StudentPassportActionButton) |
|---|
| 28 | from waeup.kofa.students.browser import StudyLevelDisplayFormPage |
|---|
| 29 | |
|---|
| 30 | from waeup.aaue.students.interfaces import ICustomStudentStudyLevel |
|---|
| 31 | from waeup.aaue.interfaces import MessageFactory as _ |
|---|
| 32 | |
|---|
| 33 | class AddPreviousPaymentActionButton(AddPreviousPaymentActionButton): |
|---|
| 34 | |
|---|
| 35 | @property |
|---|
| 36 | def target_url(self): |
|---|
| 37 | return '' |
|---|
| 38 | |
|---|
| 39 | class AddBalancePaymentActionButton(AddBalancePaymentActionButton): |
|---|
| 40 | |
|---|
| 41 | @property |
|---|
| 42 | def target_url(self): |
|---|
| 43 | return '' |
|---|
| 44 | |
|---|
| 45 | class GetMatricNumberActionButton(ManageActionButton): |
|---|
| 46 | grok.order(10) |
|---|
| 47 | grok.context(IStudent) |
|---|
| 48 | grok.view(StudentBaseDisplayFormPage) |
|---|
| 49 | grok.require('waeup.viewStudent') |
|---|
| 50 | #grok.require('waeup.manageStudent') |
|---|
| 51 | icon = 'actionicon_count.png' |
|---|
| 52 | text = _('Get Matriculation Number') |
|---|
| 53 | |
|---|
| 54 | @property |
|---|
| 55 | def target_url(self): |
|---|
| 56 | students_utils = getUtility(IStudentsUtils) |
|---|
| 57 | if self.context.matric_number: |
|---|
| 58 | return '' |
|---|
| 59 | error, matric_number = students_utils.constructMatricNumber( |
|---|
| 60 | self.context) |
|---|
| 61 | if error: |
|---|
| 62 | return '' |
|---|
| 63 | return self.view.url(self.view.context, 'get_matric_number') |
|---|
| 64 | |
|---|
| 65 | class MatricNumberSlipActionButton(ManageActionButton): |
|---|
| 66 | grok.order(10) |
|---|
| 67 | grok.context(IStudent) |
|---|
| 68 | grok.view(StudentBaseDisplayFormPage) |
|---|
| 69 | grok.require('waeup.viewStudent') |
|---|
| 70 | icon = 'actionicon_pdf.png' |
|---|
| 71 | text = _('Download matriculation number slip') |
|---|
| 72 | target = 'matric_number_slip.pdf' |
|---|
| 73 | |
|---|
| 74 | @property |
|---|
| 75 | def target_url(self): |
|---|
| 76 | if self.context.state not in (PAID,) or not self.context.is_fresh \ |
|---|
| 77 | or not self.context.matric_number: |
|---|
| 78 | return '' |
|---|
| 79 | return self.view.url(self.view.context, self.target) |
|---|
| 80 | |
|---|
| 81 | class CourseRegistrationSlipActionButton(ManageActionButton): |
|---|
| 82 | grok.order(5) |
|---|
| 83 | grok.context(ICustomStudentStudyLevel) |
|---|
| 84 | grok.view(StudyLevelDisplayFormPage) |
|---|
| 85 | grok.require('waeup.viewStudent') |
|---|
| 86 | icon = 'actionicon_pdf.png' |
|---|
| 87 | text = _('Download course registration slip') |
|---|
| 88 | target = 'course_registration_slip.pdf' |
|---|
| 89 | |
|---|
| 90 | @property |
|---|
| 91 | def target_url(self): |
|---|
| 92 | is_current = self.context.__parent__.is_current |
|---|
| 93 | if not is_current: |
|---|
| 94 | return '' |
|---|
| 95 | if self.context.student.state != REGISTERED \ |
|---|
| 96 | and self.context.student.current_level == self.context.level: |
|---|
| 97 | return '' |
|---|
| 98 | return self.view.url(self.view.context, self.target) |
|---|
| 99 | |
|---|
| 100 | class StudentPassportActionButton(StudentPassportActionButton): |
|---|
| 101 | """Inherit from same class in base package, not from kofacustom.nigeria |
|---|
| 102 | which requires that no application slip exists. |
|---|
| 103 | """ |
|---|