/usr/lib/python2.7/dist-packages/schooltool/gradebook/browser/category.py is in python-schooltool.gradebook 2.6.3-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | #
# SchoolTool - common information systems platform for school administration
# Copyright (c) 2005 Shuttleworth Foundation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""Category Views
"""
__docformat__ = 'reStructuredText'
import urllib
import zope.interface
import zope.component
import zope.schema
from zope.security.proxy import removeSecurityProxy
from zope.app.form import utility
from zope.formlib.interfaces import IInputWidget
from zope.traversing.browser import absoluteURL
from zope.publisher.interfaces.browser import IBrowserRequest
from zope.publisher.browser import BrowserView
from zope.traversing.browser.interfaces import IAbsoluteURL
from z3c.form import field, button, form
from z3c.form.interfaces import HIDDEN_MODE
from schooltool.app.interfaces import ISchoolToolApplication
from schooltool.table.table import simple_form_key
from schooltool.gradebook import GradebookMessage as _
from schooltool.gradebook.interfaces import ICategoryContainer
from schooltool.skin import flourish
def getKey(name):
name = name.replace(' ', '')
name = name.lower()
return name.encode('utf-8').encode('punycode')
class ICategoriesForm(zope.interface.Interface):
"""Schema for the form."""
categories = zope.schema.Set(
title=_('Categories'),
value_type=zope.schema.Choice(
vocabulary="schooltool.gradebook.category-vocabulary")
)
newCategory = zope.schema.TextLine(
title=_("New Category"),
required=False)
defaultCategory = zope.schema.Choice(
title=_("Default Category"),
vocabulary="schooltool.gradebook.category-vocabulary")
class CategoryOverview(object):
message = None
def __init__(self, context, request):
self.categories = ICategoryContainer(ISchoolToolApplication(None))
super(CategoryOverview, self).__init__(context, request)
def getData(self):
return {'categories': [],
'newCategory': '',
'defaultCategory': self.categories.default_key}
def update(self):
if 'REMOVE' in self.request:
keys = utility.getWidgetsData(
self, ICategoriesForm, names=['categories'])['categories']
if not keys:
return
for key in keys:
del self.categories[key]
self.message = _('Categories successfully deleted.')
elif 'ADD' in self.request:
value = utility.getWidgetsData(
self, ICategoriesForm, names=['newCategory'])['newCategory']
if not value:
return
name = unicode(value).encode('punycode')
self.categories[name] = value
self.message = _('Category successfully added.')
elif 'CHANGE' in self.request:
key = utility.getWidgetsData(self, ICategoriesForm,
names=['defaultCategory'])['defaultCategory']
self.categories.default_key = key
self.message = _('Default category successfully changed.')
utility.setUpWidgets(
self, self.schema, IInputWidget, initial=self.getData(),
ignoreStickyValues=True, names=self.fieldNames)
class CategoryContainerAbsoluteURL(BrowserView):
zope.component.adapts(ICategoryContainer, IBrowserRequest)
zope.interface.implements(IAbsoluteURL)
def __str__(self):
app = ISchoolToolApplication(None)
url = str(zope.component.getMultiAdapter(
(app, self.request), name='absolute_url'))
return url + '/activity_categories'
__call__ = __str__
class CategoriesAddLinks(flourish.page.RefineLinksViewlet):
"""Manager for Add links."""
class ICategoryForm(zope.interface.Interface):
title = zope.schema.TextLine(
title=_(u'Title'),
required=True)
class FlourishCategoryAddView(flourish.form.AddForm):
legend = _('Category')
fields = field.Fields(ICategoryForm)
def nextURL(self):
return absoluteURL(self.context, self.request)
@button.buttonAndHandler(_('Add'))
def handle_add_action(self, action):
flourish.form.AddForm.handleAdd.func(self, action)
@button.buttonAndHandler(_('Cancel'))
def handle_cancel_action(self, action):
self.request.response.redirect(self.nextURL())
def create(self, data):
return data['title']
def add(self, title):
key = unicode(title).encode('punycode')
self.context[key] = title
def updateActions(self):
super(FlourishCategoryAddView, self).updateActions()
self.actions['add'].addClass('button-ok')
self.actions['cancel'].addClass('button-cancel')
class ICategoryEditForm(ICategoryForm):
title = zope.schema.TextLine(
title=_(u'Title'),
required=True)
category = zope.schema.TextLine(
title=_(u'Category'),
required=True)
class FlourishCategoryEditView(flourish.form.Form, form.EditForm):
legend = _('Category')
fields = field.Fields(ICategoryEditForm)
data = None
def nextURL(self):
return absoluteURL(self.context, self.request)
@button.buttonAndHandler(_('Submit'), name='submit')
def handleSubmit(self, action):
data, errors = self.extractData()
if errors:
self.status = self.formErrorsMessage
return
changes = self.applyChanges(data)
category = self.data['category']
if (changes and category and
category in self.context):
# XXX: stupid Zope.
del self.context[category]
self.context[category] = self.data['title']
self.status = self.successMessage
else:
self.status = self.noChangesMessage
self.request.response.redirect(self.nextURL())
@button.buttonAndHandler(_('Make Default'), name='make_default')
def handleMakeDefault(self, action):
data, errors = self.extractData()
category = data['category']
if (category and category in self.context):
self.context.default_key = category
self.request.response.redirect(self.nextURL())
@button.buttonAndHandler(_('Cancel'))
def handle_cancel_action(self, action):
self.request.response.redirect(self.nextURL())
def getContent(self):
return self.data
def update(self):
self.data = {}
self.data['category'] = self.request.get('category', '')
if self.data['category']:
self.data['title'] = removeSecurityProxy(
self.context.get(self.data['category']))
# XXX: ContainedProxy fails on unicode(title)
# when there are non-ascii characters
# so we get a real unicode object here
if self.data['title'] is not None:
title = self.data['title']
self.data['title'] = title.encode('utf-8').decode('utf-8')
if self.context.default_key == self.data['category']:
self.data['default'] = True
else:
self.data['title'] = None
super(FlourishCategoryEditView, self).update()
self.widgets['category'].mode = HIDDEN_MODE
def updateActions(self):
super(FlourishCategoryEditView, self).updateActions()
self.actions['submit'].addClass('button-ok')
self.actions['make_default'].addClass('button-ok')
self.actions['cancel'].addClass('button-cancel')
class FlourishCategoriesView(flourish.page.Page):
def table(self):
result = []
for key, category in sorted(self.context.items()):
result.append({
'key': key,
'form_key': urllib.quote(key),
'title': removeSecurityProxy(category),
})
return result
def update(self):
deleted = False
for key in list(self.context):
delete_url = 'delete.%s' % urllib.quote(key)
if delete_url in self.request:
del self.context[key]
deleted = True
if deleted:
self.request.response.redirect(self.request.URL)
def appTitleContentFactory(context, request, view, name):
app = ISchoolToolApplication(None)
return flourish.content.queryContentProvider(
app, request, view, 'title')
|