source: main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py @ 6630

Last change on this file since 6630 was 6629, checked in by Henrik Bettermann, 13 years ago

Add students section breadcrumb.

  • Property svn:keywords set to Id
File size: 7.8 KB
Line 
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"""
18import sys
19import grok
20
21from datetime import datetime
22from zope.formlib.widget import CustomWidgetFactory
23from zope.formlib.form import setUpEditWidgets
24from zope.securitypolicy.interfaces import IPrincipalRoleManager
25from zope.traversing.browser import absoluteURL
26from zope.component import (
27    createObject,)
28
29from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
30from reportlab.pdfgen import canvas
31from reportlab.lib.units import cm
32from reportlab.lib.pagesizes import A4
33from reportlab.lib.styles import getSampleStyleSheet
34from reportlab.platypus import (Frame, Paragraph, Image,
35    Table, Spacer)
36from reportlab.platypus.tables import TableStyle
37
38from waeup.sirp.accesscodes import invalidate_accesscode, get_access_code
39from waeup.sirp.accesscodes.workflow import USED
40from waeup.sirp.browser import (
41    WAeUPPage, WAeUPEditFormPage, WAeUPAddFormPage, WAeUPDisplayFormPage)
42from waeup.sirp.browser.breadcrumbs import Breadcrumb
43from waeup.sirp.browser.layout import NullValidator
44from waeup.sirp.browser.pages import add_local_role, del_local_roles
45from waeup.sirp.browser.resources import datepicker, tabs, datatable
46from waeup.sirp.browser.viewlets import (
47    ManageActionButton, PrimaryNavTab, LeftSidebarLink, AddActionButton,
48    )
49from waeup.sirp.image.browser.widget import (
50    ThumbnailWidget, EncodingImageFileWidget,
51    )
52from waeup.sirp.image.image import createWAeUPImageFile
53from waeup.sirp.interfaces import IWAeUPObject, ILocalRolesAssignable
54from waeup.sirp.permissions import get_users_with_local_roles
55from waeup.sirp.university.interfaces import ICertificate
56from waeup.sirp.widgets.datewidget import (
57    FriendlyDateWidget, FriendlyDateDisplayWidget)
58from waeup.sirp.widgets.restwidget import ReSTDisplayWidget
59from waeup.sirp.widgets.objectwidget import (
60    WAeUPObjectWidget, WAeUPObjectDisplayWidget)
61from waeup.sirp.widgets.multilistwidget import (
62    MultiListWidget, MultiListDisplayWidget)
63from waeup.sirp.students.interfaces import (
64    IStudentsContainer, IStudent,
65    )
66from waeup.sirp.students.students import (
67    Student,
68    )
69from waeup.sirp.students.catalog import search
70
71class StudentsTab(PrimaryNavTab):
72    """Students tab in primary navigation.
73    """
74
75    grok.context(IWAeUPObject)
76    grok.order(3)
77    grok.require('waeup.viewStudents')
78    grok.template('primarynavtab')
79
80    pnav = 4
81    tab_title = u'Students'
82
83    @property
84    def link_target(self):
85        return self.view.application_url('students')
86
87class StudentsBreadcrumb(Breadcrumb):
88    """A breadcrumb for the students container.
89    """
90    grok.context(IStudentsContainer)
91    title = u'Students'
92
93class StudentsContainerPage(WAeUPPage):
94    """The standard view for student containers.
95    """
96    grok.context(IStudentsContainer)
97    grok.name('index')
98    grok.require('waeup.viewStudents')
99    grok.template('studentscontainerpage')
100
101    @property
102    def title(self):
103        return "Students"
104
105    @property
106    def label(self):
107        return self.title
108
109    def update(self, *args, **kw):
110        datatable.need()
111        form = self.request.form
112        self.hitlist = []
113        if 'searchterm' in form and form['searchterm']:
114            self.searchterm = form['searchterm']
115            self.searchtype = form['searchtype']
116        elif 'old_searchterm' in form:
117            self.searchterm = form['old_searchterm']
118            self.searchtype = form['old_searchtype']
119        else:
120            if 'search' in form:
121                self.flash('Empty search string.')
122            return
123        self.hitlist = search(query=self.searchterm,
124            searchtype=self.searchtype, view=self)
125        if not self.hitlist:
126            self.flash('No student found.')
127        return
128
129class StudentsContainerManageActionButton(ManageActionButton):
130    grok.order(1)
131    grok.context(IStudentsContainer)
132    grok.view(StudentsContainerPage)
133    grok.require('waeup.manageStudents')
134    text = 'Manage students'
135
136
137class StudentsContainerManagePage(WAeUPPage):
138    """The manage page for student containers.
139    """
140    grok.context(IStudentsContainer)
141    grok.name('manage')
142    grok.require('waeup.manageStudents')
143    grok.template('studentscontainermanagepage')
144
145    @property
146    def title(self):
147        return "Students"
148
149    @property
150    def label(self):
151        return self.title
152
153    def update(self, *args, **kw):
154        datatable.need()
155        form = self.request.form
156        self.hitlist = []
157        if 'searchterm' in form and form['searchterm']:
158            self.searchterm = form['searchterm']
159            self.searchtype = form['searchtype']
160        elif 'old_searchterm' in form:
161            self.searchterm = form['old_searchterm']
162            self.searchtype = form['old_searchtype']
163        else:
164            if 'search' in form:
165                self.flash('Empty search string.')
166            return
167        #import pdb; pdb.set_trace()
168        if not 'entries' in form:
169            self.hitlist = search(query=self.searchterm,
170                searchtype=self.searchtype, view=self)
171            if not self.hitlist:
172                self.flash('No student found.')
173            return
174        entries = form['entries']
175        if isinstance(entries, basestring):
176            entries = [entries]
177        deleted = []
178        for entry in entries:
179            if 'remove' in form:
180                del self.context[entry]
181                deleted.append(entry)
182        self.hitlist = search(query=self.searchterm,
183            searchtype=self.searchtype, view=self)
184        if len(deleted):
185            self.flash('Successfully removed: %s' % ', '.join(deleted))
186        return
187
188class StudentsContainerAddActionButton(AddActionButton):
189    grok.order(1)
190    grok.context(IStudentsContainer)
191    grok.view(StudentsContainerManagePage)
192    grok.require('waeup.manageStudents')
193    text = 'Add student'
194    target = 'addstudent'
195
196class StudentAddFormPage(WAeUPAddFormPage):
197    """Add-form to add a student.
198    """
199    grok.context(IStudentsContainer)
200    grok.require('waeup.manageStudents')
201    grok.name('addstudent')
202    grok.template('studentaddpage')
203    form_fields = grok.AutoFields(IStudent)
204    title = 'Students'
205    label = 'Add student'
206
207    @grok.action('Create student record')
208    def addStudent(self, **data):
209        student_id = self.request.form.get('form.student_id')
210        student = createObject(u'waeup.Student')
211        self.applyData(student, **data)
212        #import pdb; pdb.set_trace()
213        try:
214            self.context[student_id] = student
215        except KeyError:
216            self.flash('The student id chosen already exists.')
217            return
218        self.flash('Student record created.')
219        self.redirect(self.url(self.context[student_id], 'index'))
220        return
221
222class DisplayStudent(WAeUPDisplayFormPage):
223    grok.context(IStudent)
224    grok.name('index')
225    grok.require('waeup.viewStudents')
226    form_fields = grok.AutoFields(IStudent)
227
228    @property
229    def title(self):
230        return 'Student: %s' % self.context.name
231
232    @property
233    def label(self):
234        return self.context.name
Note: See TracBrowser for help on using the repository browser.