1 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
2 | ## This program is free software; you can redistribute it and/or modify |
---|
3 | ## it under the terms of the GNU General Public License as published by |
---|
4 | ## the Free Software Foundation; either version 2 of the License, or |
---|
5 | ## (at your option) any later version. |
---|
6 | ## |
---|
7 | ## This program is distributed in the hope that it will be useful, |
---|
8 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
9 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
10 | ## GNU General Public License for more details. |
---|
11 | ## |
---|
12 | ## You should have received a copy of the GNU General Public License |
---|
13 | ## along with this program; if not, write to the Free Software |
---|
14 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
15 | ## |
---|
16 | """UI components for students and related components. |
---|
17 | """ |
---|
18 | import sys |
---|
19 | import grok |
---|
20 | |
---|
21 | from datetime import datetime |
---|
22 | from zope.formlib.widget import CustomWidgetFactory |
---|
23 | from zope.formlib.form import setUpEditWidgets |
---|
24 | from zope.securitypolicy.interfaces import IPrincipalRoleManager |
---|
25 | from zope.traversing.browser import absoluteURL |
---|
26 | from zope.component import ( |
---|
27 | createObject,) |
---|
28 | |
---|
29 | from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState |
---|
30 | from reportlab.pdfgen import canvas |
---|
31 | from reportlab.lib.units import cm |
---|
32 | from reportlab.lib.pagesizes import A4 |
---|
33 | from reportlab.lib.styles import getSampleStyleSheet |
---|
34 | from reportlab.platypus import (Frame, Paragraph, Image, |
---|
35 | Table, Spacer) |
---|
36 | from reportlab.platypus.tables import TableStyle |
---|
37 | |
---|
38 | from waeup.sirp.accesscodes import invalidate_accesscode, get_access_code |
---|
39 | from waeup.sirp.accesscodes.workflow import USED |
---|
40 | from waeup.sirp.browser import ( |
---|
41 | WAeUPPage, WAeUPEditFormPage, WAeUPAddFormPage, WAeUPDisplayFormPage) |
---|
42 | from waeup.sirp.browser.breadcrumbs import Breadcrumb |
---|
43 | from waeup.sirp.browser.layout import NullValidator |
---|
44 | from waeup.sirp.browser.pages import add_local_role, del_local_roles |
---|
45 | from waeup.sirp.browser.resources import datepicker, tabs, datatable |
---|
46 | from waeup.sirp.browser.viewlets import ( |
---|
47 | ManageActionButton, PrimaryNavTab, LeftSidebarLink |
---|
48 | ) |
---|
49 | from waeup.sirp.image.browser.widget import ( |
---|
50 | ThumbnailWidget, EncodingImageFileWidget, |
---|
51 | ) |
---|
52 | from waeup.sirp.image.image import createWAeUPImageFile |
---|
53 | from waeup.sirp.interfaces import IWAeUPObject, ILocalRolesAssignable |
---|
54 | from waeup.sirp.permissions import get_users_with_local_roles |
---|
55 | from waeup.sirp.university.interfaces import ICertificate |
---|
56 | from waeup.sirp.widgets.datewidget import ( |
---|
57 | FriendlyDateWidget, FriendlyDateDisplayWidget) |
---|
58 | from waeup.sirp.widgets.restwidget import ReSTDisplayWidget |
---|
59 | from waeup.sirp.widgets.objectwidget import ( |
---|
60 | WAeUPObjectWidget, WAeUPObjectDisplayWidget) |
---|
61 | from waeup.sirp.widgets.multilistwidget import ( |
---|
62 | MultiListWidget, MultiListDisplayWidget) |
---|
63 | from waeup.sirp.students.interfaces import ( |
---|
64 | IStudentsContainer, IStudent, |
---|
65 | ) |
---|
66 | from waeup.sirp.students.students import ( |
---|
67 | Student, |
---|
68 | ) |
---|
69 | |
---|
70 | class StudentsTab(PrimaryNavTab): |
---|
71 | """Students tab in primary navigation. |
---|
72 | """ |
---|
73 | |
---|
74 | grok.context(IWAeUPObject) |
---|
75 | grok.order(3) |
---|
76 | grok.require('waeup.viewStudents') |
---|
77 | grok.template('primarynavtab') |
---|
78 | |
---|
79 | pnav = 4 |
---|
80 | tab_title = u'Students' |
---|
81 | |
---|
82 | @property |
---|
83 | def link_target(self): |
---|
84 | return self.view.application_url('students') |
---|
85 | |
---|
86 | class StudentsContainerPage(WAeUPDisplayFormPage): |
---|
87 | """The standard view for regular student containers. |
---|
88 | """ |
---|
89 | grok.context(IStudentsContainer) |
---|
90 | grok.name('index') |
---|
91 | grok.require('waeup.viewStudents') |
---|
92 | grok.template('studentscontainerpage') |
---|
93 | |
---|
94 | form_fields = grok.AutoFields(IStudentsContainer) |
---|
95 | #form_fields['description'].custom_widget = ReSTDisplayWidget |
---|
96 | |
---|
97 | @property |
---|
98 | def title(self): |
---|
99 | return "Students" |
---|
100 | |
---|
101 | @property |
---|
102 | def label(self): |
---|
103 | return self.title |
---|
104 | |
---|
105 | class StudentssContainerManageActionButton(ManageActionButton): |
---|
106 | grok.order(1) |
---|
107 | grok.context(IStudentsContainer) |
---|
108 | grok.view(StudentsContainerPage) |
---|
109 | grok.require('waeup.manageStudents') |
---|
110 | text = 'Manage students' |
---|
111 | |
---|
112 | class StudentsContainerManagePage(WAeUPDisplayFormPage): |
---|
113 | """The standard view for regular student containers. |
---|
114 | """ |
---|
115 | grok.context(IStudentsContainer) |
---|
116 | grok.name('manage') |
---|
117 | grok.require('waeup.manageStudents') |
---|
118 | grok.template('studentscontainerpage') |
---|
119 | |
---|
120 | form_fields = grok.AutoFields(IStudentsContainer) |
---|
121 | |
---|
122 | @property |
---|
123 | def title(self): |
---|
124 | return "Students" |
---|
125 | |
---|
126 | @property |
---|
127 | def label(self): |
---|
128 | return self.title |
---|
129 | |
---|
130 | @grok.action('Add student', validator=NullValidator) |
---|
131 | def addStudent(self, **data): |
---|
132 | self.redirect(self.url(self.context, 'addstudent')) |
---|
133 | return |
---|
134 | |
---|
135 | class StudentAddFormPage(WAeUPAddFormPage): |
---|
136 | """Add-form to add a student. |
---|
137 | """ |
---|
138 | grok.context(IStudentsContainer) |
---|
139 | grok.require('waeup.manageStudents') |
---|
140 | grok.name('addstudent') |
---|
141 | grok.template('studentaddpage') |
---|
142 | form_fields = grok.AutoFields(IStudent) |
---|
143 | title = 'Students' |
---|
144 | label = 'Add student' |
---|
145 | |
---|
146 | @grok.action('Create student record') |
---|
147 | def addStudent(self, **data): |
---|
148 | student_id = self.request.form.get('form.student_id') |
---|
149 | student = createObject(u'waeup.Student') |
---|
150 | self.applyData(student, **data) |
---|
151 | #import pdb; pdb.set_trace() |
---|
152 | try: |
---|
153 | self.context[student_id] = student |
---|
154 | except KeyError: |
---|
155 | self.flash('The student id chosen already exists.') |
---|
156 | return |
---|
157 | self.redirect(self.url(self.context[student_id], 'index')) |
---|
158 | return |
---|
159 | |
---|
160 | class DisplayStudent(WAeUPDisplayFormPage): |
---|
161 | grok.context(IStudent) |
---|
162 | grok.name('index') |
---|
163 | grok.require('waeup.viewStudents') |
---|
164 | form_fields = grok.AutoFields(IStudent) |
---|
165 | |
---|
166 | @property |
---|
167 | def title(self): |
---|
168 | return 'Student: %s' % self.context.name |
---|
169 | |
---|
170 | @property |
---|
171 | def label(self): |
---|
172 | return self.context.name |
---|