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