This file is indexed.

/usr/share/pyshared/schooltool/app/booking.txt 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
==============================
Resource booking in SchoolTool
==============================

Overview
--------

Every calendar event may indicate that one or more resources (e.g., projectors,
rooms) are needed for this event.  We call this "resource booking" in
SchoolTool.  When a resource is booked, the calendar event is automatically
added to the resource's calendar, and is kept in sync.


Set up
------

Set up the calendaring framework::

    >>> from zope.app.testing import setup
    >>> setup.placelessSetUp()
    >>> setup.setUpAnnotations()

    >>> from schooltool.testing import setup as sbsetup
    >>> sbsetup.setUpCalendaring()

We will need some test fixture for relationships.

    >>> from schooltool.relationship.tests import setUpRelationships
    >>> setUpRelationships()

You have a person and a resource

    >>> from schooltool.resource.resource import Resource
    >>> from schooltool.person.person import Person
    >>> person = Person('froggy')
    >>> resource = Resource('lily')
    >>> resource2 = Resource('mud')


Resource booking and unbooking
------------------------------

You want to create a calendar event and book a resource.  You can specify the
resource when you're creating an event.

    >>> from datetime import datetime, timedelta
    >>> from schooltool.app.interfaces import ISchoolToolCalendar
    >>> from schooltool.app.cal import CalendarEvent
    >>> e = CalendarEvent(title="Presentation",
    ...                   dtstart=datetime(2005, 3, 2, 12, 45),
    ...                   duration=timedelta(minutes=45),
    ...                   resources=[resource])
    >>> ISchoolToolCalendar(person).addEvent(e)

The event magically appears in the resource's calendar

    >>> ISchoolToolCalendar(resource).find(e.unique_id) is e
    True

You can change the event to remove the booking

    >>> e.unbookResource(resource)
    >>> ISchoolToolCalendar(resource).find(e.unique_id)
    Traceback (most recent call last):
      ...
    KeyError: ...

or you may book a different resource

    >>> e.bookResource(resource2)
    >>> ISchoolToolCalendar(resource2).find(e.unique_id) is e
    True


Delayed booking
---------------

If you create an event with resource bookings, but never add that event
anywhere, it doesn't appear in resource calendars.

    >>> e = CalendarEvent(title="Bluffing",
    ...                   dtstart=datetime(2005, 3, 2, 12, 15),
    ...                   duration=timedelta(minutes=5),
    ...                   resources=[resource])
    >>> e in ISchoolToolCalendar(resource)
    False
    >>> e.bookResource(resource2)
    >>> e in ISchoolToolCalendar(resource2)
    False

However just add the event somewhere, and it materializes in all three calendars

    >>> ISchoolToolCalendar(person).addEvent(e)
    >>> [e in ISchoolToolCalendar(x) for x in [person, resource, resource2]]
    [True, True, True]


Deleting events
---------------

So, you have an event in two calendars:

    >>> e = CalendarEvent(title="Presentation",
    ...                   dtstart=datetime(2005, 3, 3, 12, 00),
    ...                   duration=timedelta(minutes=45),
    ...                   resources=[resource2])
    >>> ISchoolToolCalendar(person).addEvent(e)
    >>> e in ISchoolToolCalendar(resource2)
    True
    >>> e in ISchoolToolCalendar(person)
    True

If you remove it from the person's calendar, it gets removed from the
resource's calendar too.

    >>> ISchoolToolCalendar(person).removeEvent(e)
    >>> e not in ISchoolToolCalendar(resource2)
    True

If you remove an event from a resource's calendar, it loses that booking::

    >>> e = CalendarEvent(title="Big presentation",
    ...                   dtstart=datetime(2005, 3, 4, 12, 45),
    ...                   duration=timedelta(minutes=45),
    ...                   resources=[resource, resource2])
    >>> ISchoolToolCalendar(person).addEvent(e)
    >>> [e in ISchoolToolCalendar(x) for x in [person, resource, resource2]]
    [True, True, True]

    >>> ISchoolToolCalendar(resource).removeEvent(e)
    >>> [e in ISchoolToolCalendar(x) for x in [person, resource, resource2]]
    [True, False, True]
    >>> list(e.resources) == [resource2]
    True

Clearing a calendar is equivalent to removing all its events::

    >>> ISchoolToolCalendar(resource2).clear()
    >>> [e in ISchoolToolCalendar(x) for x in [person, resource, resource2]]
    [True, False, False]
    >>> list(e.resources) == []
    True


Insane corner cases
-------------------

Booking loops are not allowed::

    >>> e = CalendarEvent(title="Strange presentation",
    ...                   dtstart=datetime(2005, 3, 4, 12, 45),
    ...                   duration=timedelta(minutes=5))
    >>> ISchoolToolCalendar(resource).addEvent(e)
    >>> e.bookResource(resource)
    Traceback (most recent call last):
      ...
    ValueError: cannot book itself

    >>> e.resources
    ()

It doesn't work if you do it differently either::

    >>> e = CalendarEvent(title="Strange presentation",
    ...                   dtstart=datetime(2005, 3, 4, 12, 50),
    ...                   duration=timedelta(minutes=5),
    ...                   resources=[resource2, resource])
    >>> ISchoolToolCalendar(resource).addEvent(e)
    Traceback (most recent call last):
      ...
    ValueError: cannot book itself

    >>> e in ISchoolToolCalendar(resource)
    False
    >>> e in ISchoolToolCalendar(resource2)
    False


.. Tear down::

    >>> setup.placelessTearDown()


Remaining issues
----------------

XXX what if I do::

     e = CalendarEvent(resources=[r])
     e.unbookResource(r)

without adding `a` to any calendars?