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

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

Add some basic UI stuff to start and to play with.

  • Property svn:keywords set to Id
File size: 5.6 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
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    )
69
70class 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
86class 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
105class StudentssContainerManageActionButton(ManageActionButton):
106    grok.order(1)
107    grok.context(IStudentsContainer)
108    grok.view(StudentsContainerPage)
109    grok.require('waeup.manageStudents')
110    text = 'Manage students'
111
112class 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
135class 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
160class 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
Note: See TracBrowser for help on using the repository browser.