/usr/share/pyshared/schooltool/timetable/interfaces.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 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 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | #
# 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
#
"""
Schedule and timetabling interfaces
"""
import pytz
import zope.schema
from zope.annotation.interfaces import IAttributeAnnotatable
from zope.interface import Interface, Attribute
from zope.container.constraints import contains
from zope.container.interfaces import IContainer, IOrderedContainer
from zope.container.interfaces import IContained
from schooltool.app.interfaces import ISchoolToolCalendarEvent
from schooltool.app.interfaces import ISchoolToolCalendar
from schooltool.app.interfaces import IHaveCalendar
from schooltool.app.utils import vocabulary
from schooltool.calendar.interfaces import ICalendar
from schooltool.common import SchoolToolMessage as _
#
# Schedule
#
activity_types = vocabulary(
[("lesson", _("Lesson")),
("homeroom", _("Homeroom")),
("free", _("Free")),
("lunch", _("Lunch")),
])
class IPeriod(IContained):
"""A period of activity."""
title = zope.schema.TextLine(
title=u"Title of the period.",
required=False)
activity_type = zope.schema.Choice(
title=_("Activity type."),
required=True,
default="lesson",
vocabulary=activity_types)
class IMeeting(Interface):
"""A meeting represents a lesson or other scheduled activity."""
dtstart = zope.schema.Datetime(
title=u"Time of the start of the event",
required=True)
duration = zope.schema.Timedelta(
title=u"Timedelta of the duration of the event",
required=True)
period = zope.schema.Object(
title=u"The period to schedule.",
schema=IPeriod,
required=False)
meeting_id = zope.schema.TextLine(
title=u"Unique identifier of a meeting (lesson)",
description=u"""
The meeting_id is an arbitrary identifier of a meeting (lesson),
unique within the schedule that generated it.
""",
required=False)
def clone(dtstart=None, duration=None,
period=None, meeting_id=None):
"""Return a copy of the meeting with replaced given values."""
class ISchedule(Interface):
"""A schedule of meetings."""
title = zope.schema.TextLine(
title=u"Title of the timetable",
required=True)
first = zope.schema.Date(
title=_("First scheduled day"),
required=True)
last = zope.schema.Date(
title=_("Last scheduled day"),
required=True)
timezone = zope.schema.Choice(
title=u"Time Zone",
description=u"Meetings time zone",
values=pytz.common_timezones,
required=True)
def iterMeetings(date, until_date=None):
"""Yields meetings for the given date range."""
class IMeetingException(IMeeting):
"""A persistent exception meeting."""
class IScheduleExceptions(Interface):
# XXX: if exception values were objects instead of meeting lists
# we could log additional info, like reason for the exception
exceptions = zope.schema.Dict(
title=_("Exceptions"),
description=_("Exceptions by date."),
key_type=zope.schema.Date(
title=_("Exception date")),
value_type=zope.schema.List(
title=_("Meetings"),
value_type = zope.schema.Object(
title=_("Meeting"),
schema=IMeetingException),
),
)
def iterOriginalMeetings(date, until_date=None):
"""Yields meetings disregarding exception dates."""
class IScheduleWithExceptions(ISchedule, IScheduleExceptions):
"""Schedule with exception days."""
class IScheduleContainer(IContainer, IScheduleWithExceptions):
"""A container of schedules.
The container itself is as a big composite schedule.
"""
contains(ISchedule)
first = zope.schema.Date(
title=u"First scheduled day",
required=False)
last = zope.schema.Date(
title=u"Last scheduled day",
required=False)
#
# Day templates
#
class IDayTemplate(IOrderedContainer):
title = zope.schema.TextLine(
title=u"Title of the day",
required=False)
class IDayTemplateContainer(IOrderedContainer):
"""Ordered container of day templates."""
contains(IDayTemplate)
class ITimeSlot(IContained):
"""Time slot designated for an activity."""
tstart = zope.schema.Time(
title=u"Time of the start of the event",
required=True)
duration = zope.schema.Timedelta(
title=u"Timedelta of the duration of the event",
required=True)
activity_type = zope.schema.Choice(
title=_("Activity type"),
required=False,
default="lesson",
vocabulary=activity_types)
class IDayTemplateSchedule(IContained):
"""Day templates scheduled by date."""
templates = zope.schema.Object(
title=u"The template container.",
schema=IDayTemplateContainer,
required=True)
def iterDates(dates):
"""Yield day templates for given dates."""
class ICalendarDayTemplates(IDayTemplateSchedule):
"""Day templates."""
starting_index = zope.schema.Int(
title=u"Starting date should start as Nth day",
default=0,
required=True)
def getDay(schedule, date):
"""Get template for the given date."""
class IWeekDayTemplates(IDayTemplateSchedule):
"""Iterator of day templates."""
def getWeekDayKey(weekday):
"""Get weekday template container key."""
def getWeekDay(weekday):
"""Get weekday template."""
class ISchooldays(Interface):
"""XXX: should be moved to term, as schooldays are defined there."""
def iterDates(dates):
"""Iterate dates that are schooldays."""
def __iter__():
"""Yield all schoolday dates."""
def __contains__(date):
"""Return whether the date is a schoolday."""
class ISchoolDayTemplates(IDayTemplateSchedule):
"""Iterator that rotates on schooldays (as opposed to rotating on
calendar days)"""
starting_index = zope.schema.Int(
title=u"Starting date should start as Nth day",
default=0,
required=True)
#
# Timetabling
#
class ITimetable(IScheduleWithExceptions):
"""The schedule of meetings built from day templates."""
periods = zope.schema.Object(
title=u"Periods",
schema=IDayTemplateSchedule,
required=True)
time_slots = zope.schema.Object(
title=u"Time slots",
schema=IDayTemplateSchedule,
required=True)
class ITimetableContainerBase(Interface):
default = zope.schema.Object(
title=u"The default timetable",
schema=ITimetable,
required=False)
class ITimetableContainer(IContainer, ITimetableContainerBase):
"""A container of timetables."""
contains(ITimetable)
class ISelectedPeriodsScheduleRead(ISchedule):
timetable = zope.schema.Object(
title=u"Timetable to filter meetings from",
schema=ITimetable,
required=False)
periods = Attribute(
"""Iterate only over meetings for these periods.""")
consecutive_periods_as_one = zope.schema.Bool(
title=_("Treat consecutive periods as one meeting"),
default=False,
required=False)
def hasPeriod(period):
"""Is the period added to this schedule."""
class ISelectedPeriodsScheduleWrite(Interface):
def addPeriod(period):
"""Schedule meetings for this period."""
def removePeriod(period):
"""Unschedule meeting for this period."""
class ISelectedPeriodsSchedule(ISelectedPeriodsScheduleRead,
ISelectedPeriodsScheduleWrite):
"""Schedule composed of meetings from another schedule with
selected periods only."""
def addPeriod(period):
"""Schedule meetings for this period."""
def removePeriod(period):
"""Unschedule meeting for this period."""
#
# Calendar
#
class IScheduleCalendarEvent(IMeeting, ISchoolToolCalendarEvent):
"""Calendar event that forms a schedule."""
schedule = zope.schema.Object(
title=u"Schedule that generated this event.",
schema=ISchedule,
required=False)
class IImmutableScheduleCalendar(ICalendar):
"""Calendar representation of a schedule."""
class IScheduleCalendar(ISchoolToolCalendar):
"""Persistent calendar of a schedule."""
def updateSchedule(schedule):
"""Update calendar with events from this schedule."""
def removeSchedule(schedule):
"""Remove events generated by this schedule."""
#
# Integration
#
class IHaveSchedule(IAttributeAnnotatable, IHaveCalendar):
"""Marker interface for objects that schedule existing timetables."""
class IHaveTimetables(IAttributeAnnotatable):
"""Marker interface for objects that have timetables."""
#
# Security
#
class IScheduleParentCrowd(Interface):
"""A crowd object that is used on a schedule's parent.
This is just a marker interface.
"""
def contains(principal):
"""Return True if principal is in the crowd."""
|