/usr/share/pyshared/schooltool/resource/resource.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 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 | #
# 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 resource object
$Id$
"""
__docformat__ = 'restructuredtext'
from persistent import Persistent
from persistent.dict import PersistentDict
from zope.component import adapts, adapter
from zope.interface import implements, implementer
from zope.interface import Interface
from zope.annotation.interfaces import IAttributeAnnotatable
from zope.container.contained import Contained
from zope.container.btree import BTreeContainer
from zope.container.ordered import OrderedContainer
from zope.location.location import Location
from zope.schema import TextLine, Bool, Date, Choice
from zope.schema.vocabulary import SimpleVocabulary
from zope.schema.vocabulary import SimpleTerm
from schooltool.app.app import Asset
from schooltool.app.app import InitBase, StartUpBase
from schooltool.app.utils import vocabulary
from schooltool.app.security import LeaderCrowd
from schooltool.app.interfaces import ICalendarParentCrowd
from schooltool.app.interfaces import ISchoolToolApplication
from schooltool.app.utils import vocabulary
from schooltool.basicperson.demographics import PersonDemographicsData
from schooltool.basicperson.demographics import DemographicsFields
from schooltool.basicperson.demographics import IDemographicsForm
from schooltool.basicperson.interfaces import IFieldFilterVocabulary
from schooltool.resource import interfaces
from schooltool.securitypolicy.crowds import TeachersCrowd
from schooltool.securitypolicy.crowds import ConfigurableCrowd, AggregateCrowd
from schooltool.securitypolicy.crowds import AuthenticatedCrowd
from schooltool.common import SchoolToolMessage as _
RESOURCE_DEMO_FIELDS_KEY = 'schooltool.resource.demographics_fields'
RESOURCE_DEMO_DATA_KEY = 'schooltool.resource.demographics_data'
class ResourceContainer(BTreeContainer):
"""Container of resources."""
implements(interfaces.IResourceContainer, IAttributeAnnotatable)
class BaseResource(Persistent, Contained, Asset):
"""Base Resource."""
implements(interfaces.IBaseResource, IAttributeAnnotatable)
type = _(u"Resource")
def __init__(self, title=None, description=None):
self.title = title
self.description = description
self.notes = u""
class Resource(BaseResource):
"""Resource."""
implements(interfaces.IResource)
# BBB so that evolution scripts would work
isLocation = None
class Location(BaseResource):
"""Location."""
implements(interfaces.ILocation)
capacity = None
class Equipment(BaseResource):
"""Equipment."""
implements(interfaces.IEquipment)
type = u""
manufacturer = u""
model = u""
serialNumber = u""
purchaseDate = None
class ResourceInit(InitBase):
def __call__(self):
self.app['resources'] = ResourceContainer()
self.app[RESOURCE_DEMO_FIELDS_KEY] = ResourceDemographicsFields()
self.app[RESOURCE_DEMO_DATA_KEY] = ResourceDemographicsDataContainer()
class ResourceStartUp(StartUpBase):
def __call__(self):
if RESOURCE_DEMO_FIELDS_KEY not in self.app:
self.app[RESOURCE_DEMO_FIELDS_KEY] = ResourceDemographicsFields()
if RESOURCE_DEMO_DATA_KEY not in self.app:
self.app[RESOURCE_DEMO_DATA_KEY] = \
ResourceDemographicsDataContainer()
class ResourceViewersCrowd(ConfigurableCrowd):
setting_key = 'everyone_can_view_resource_info'
class ResourceContainerViewersCrowd(ConfigurableCrowd):
setting_key = 'everyone_can_view_resource_list'
class ResourceCalendarViewersSettingCrowd(ConfigurableCrowd):
setting_key = "everyone_can_view_resource_calendar"
class ResourceCalendarViewersCrowd(AggregateCrowd):
adapts(interfaces.IBaseResource)
implements(ICalendarParentCrowd)
def crowdFactories(self):
return [ResourceCalendarViewersSettingCrowd,
LeaderCrowd, AuthenticatedCrowd, TeachersCrowd]
class ResourceCalendarEditorsCrowd(AggregateCrowd):
adapts(interfaces.IBaseResource)
implements(ICalendarParentCrowd)
def crowdFactories(self):
return [LeaderCrowd, TeachersCrowd]
################### Demographics #################
class ResourceDemographicsFields(DemographicsFields):
"""Storage for demographics fields for all resources."""
implements(interfaces.IResourceDemographicsFields)
@implementer(interfaces.IResourceDemographicsFields)
@adapter(ISchoolToolApplication)
def getResourceDemographicsFields(app):
return app[RESOURCE_DEMO_FIELDS_KEY]
class ResourceDemographicsDataContainer(BTreeContainer):
"""Storage for demographics information for all resources."""
class ResourceDemographicsData(PersonDemographicsData):
"""Storage for demographics information for a resource."""
implements(interfaces.IResourceDemographics)
def isValidKey(self, key):
app = ISchoolToolApplication(None)
demographics_fields = interfaces.IResourceDemographicsFields(app)
return key in demographics_fields
@adapter(interfaces.IBaseResource)
@implementer(interfaces.IResourceDemographics)
def getResourceDemographics(resource):
app = ISchoolToolApplication(None)
rdc = app[RESOURCE_DEMO_DATA_KEY]
demographics = rdc.get(resource.__name__, None)
if demographics is None:
rdc[resource.__name__] = demographics = ResourceDemographicsData()
return demographics
@adapter(interfaces.IResourceDemographicsFields)
@implementer(IFieldFilterVocabulary)
def getLimitKeyVocabularyForResourceFields(resource_field_description_container):
return vocabulary([
('resource', _('Resource')),
('location', _('Location')),
('equipment', _('Equipment')),
])
class DemographicsFormAdapter(object):
implements(IDemographicsForm)
adapts(interfaces.IBaseResource)
def __init__(self, context):
self.__dict__['context'] = context
self.__dict__['demographics'] = interfaces.IResourceDemographics(
self.context)
def __setattr__(self, name, value):
self.demographics[name] = value
def __getattr__(self, name):
return self.demographics.get(name, None)
@adapter(interfaces.IResourceDemographicsFields)
@implementer(IFieldFilterVocabulary)
def getLimitKeyVocabularyForResourceFields(resource_field_description_container):
return vocabulary([
('resource', _('Resource')),
('location', _('Location')),
('equipment', _('Equipment')),
])
|