/usr/share/pyshared/schooltool/skin/containers.py is in python-schooltool 1:2.1.0-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 | #
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
"""
SchoolTool skin containers
$Id$
"""
import urllib
from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile
from zope.component import queryMultiAdapter
from zope.publisher.browser import BrowserView
from zope.security.checker import canAccess
from zope.traversing.browser.absoluteurl import absoluteURL
from schooltool.table.batch import IterableBatch
from schooltool.table.table import DependableCheckboxColumn
from schooltool.table.table import url_cell_formatter
from schooltool.table.interfaces import ITableFormatter
class ContainerView(BrowserView):
"""A base view for all containers.
Subclasses must provide the following attributes that are used in the
page template:
`index_title` -- Title of the index page.
"""
@property
def container(self):
return self.context
def update(self):
if 'SEARCH' in self.request and 'CLEAR_SEARCH' not in self.request:
searchstr = self.request['SEARCH'].lower()
results = [item for item in self.container.values()
if searchstr in item.title.lower()]
search_string = self.request['SEARCH'].encode('utf-8')
extra_url = "&SEARCH=%s" % urllib.quote_plus(search_string)
else:
self.request.form['SEARCH'] = ''
results = self.container.values()
extra_url = ""
self.batch = IterableBatch(results, self.request, sort_by='title',
extra_url=extra_url)
@property
def canModify(self):
return canAccess(self.container, '__delitem__')
class ContainerDeleteView(BrowserView):
"""A view for deleting items from container."""
@property
def container(self):
return self.context
def listIdsForDeletion(self):
return [key for key in self.container
if "delete.%s" % key in self.request]
def _listItemsForDeletion(self):
return [self.container[key] for key in self.listIdsForDeletion()]
itemsToDelete = property(_listItemsForDeletion)
def update(self):
if 'CONFIRM' in self.request:
for key in self.listIdsForDeletion():
del self.container[key]
self.request.response.redirect(self.nextURL())
elif 'CANCEL' in self.request:
self.request.response.redirect(self.nextURL())
def nextURL(self):
return absoluteURL(self.container, self.request)
class TableContainerView(BrowserView):
"""A base view for containers that use zc.table to display items.
Subclasses must provide the following attributes that are used in the
page template:
`index_title` -- Title of the index page.
"""
template = ViewPageTemplateFile('templates/table_container.pt')
delete_template = ViewPageTemplateFile('templates/container_delete.pt')
def __init__(self, context, request):
self.request = request
self.context = context
self.table = queryMultiAdapter((context, request), ITableFormatter)
def setUpTableFormatter(self, formatter):
columns_before = []
if self.canModify():
columns_before = [DependableCheckboxColumn(prefix="delete",
name='delete_checkbox',
title=u'')]
formatter.setUp(formatters=[url_cell_formatter],
columns_before=columns_before)
def __call__(self):
if 'DELETE' in self.request:
return self.delete_template()
self.setUpTableFormatter(self.table)
# XXX update should be in here but as the container_delete
# template is shared with the ContainerDeleteView and update
# is called in the template we are not doing it here
return self.template()
def update(self):
if 'CONFIRM' in self.request:
for key in self.listIdsForDeletion():
del self.context[key]
# XXX: Update table formatter. It should be set up in __call__, after
# update(), if rendering the correct template. But as update is
# called from template for some genuine reason, I'll just stick
# it here for now. I hope to find some time to fix this later on.
self.setUpTableFormatter(self.table)
def canModify(self):
return canAccess(self.context, '__delitem__')
def listIdsForDeletion(self):
return [key for key in self.context
if "delete.%s" % key in self.request]
def _listItemsForDeletion(self):
return [self.context[key] for key in self.listIdsForDeletion()]
itemsToDelete = property(_listItemsForDeletion)
|