paul@69 | 1 | #!/usr/bin/env python |
paul@69 | 2 | |
paul@146 | 3 | """ |
paul@146 | 4 | A Web interface to a user's calendar. |
paul@146 | 5 | |
paul@146 | 6 | Copyright (C) 2014, 2015 Paul Boddie <paul@boddie.org.uk> |
paul@146 | 7 | |
paul@146 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@146 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@146 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@146 | 11 | version. |
paul@146 | 12 | |
paul@146 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@146 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@146 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@146 | 16 | details. |
paul@146 | 17 | |
paul@146 | 18 | You should have received a copy of the GNU General Public License along with |
paul@146 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@146 | 20 | """ |
paul@146 | 21 | |
paul@146 | 22 | # Edit this path to refer to the location of the imiptools libraries, if |
paul@146 | 23 | # necessary. |
paul@146 | 24 | |
paul@146 | 25 | LIBRARY_PATH = "/var/lib/imip-agent" |
paul@146 | 26 | |
paul@202 | 27 | from datetime import datetime |
paul@149 | 28 | import babel.dates |
paul@149 | 29 | import cgi, os, sys |
paul@69 | 30 | |
paul@146 | 31 | sys.path.append(LIBRARY_PATH) |
paul@69 | 32 | |
paul@153 | 33 | from imiptools.content import Handler, get_address, \ |
paul@117 | 34 | get_item, get_uri, get_utc_datetime, get_value, \ |
paul@155 | 35 | get_value_map, get_values, parse_object, to_part |
paul@153 | 36 | from imiptools.dates import format_datetime, get_datetime, get_start_of_day, \ |
paul@202 | 37 | get_end_of_day, ends_on_same_day, to_timezone |
paul@83 | 38 | from imiptools.mail import Messenger |
paul@162 | 39 | from imiptools.period import add_day_start_points, add_slots, convert_periods, \ |
paul@185 | 40 | get_freebusy_details, \ |
paul@162 | 41 | get_scale, have_conflict, get_slots, get_spans, \ |
paul@162 | 42 | partition_by_day |
paul@147 | 43 | from imiptools.profile import Preferences |
paul@77 | 44 | from vCalendar import to_node |
paul@69 | 45 | import markup |
paul@69 | 46 | import imip_store |
paul@69 | 47 | |
paul@69 | 48 | getenv = os.environ.get |
paul@69 | 49 | setenv = os.environ.__setitem__ |
paul@69 | 50 | |
paul@69 | 51 | class CGIEnvironment: |
paul@69 | 52 | |
paul@69 | 53 | "A CGI-compatible environment." |
paul@69 | 54 | |
paul@69 | 55 | def __init__(self): |
paul@69 | 56 | self.args = None |
paul@69 | 57 | self.method = None |
paul@69 | 58 | self.path = None |
paul@69 | 59 | self.path_info = None |
paul@69 | 60 | self.user = None |
paul@69 | 61 | |
paul@69 | 62 | def get_args(self): |
paul@69 | 63 | if self.args is None: |
paul@69 | 64 | if self.get_method() != "POST": |
paul@69 | 65 | setenv("QUERY_STRING", "") |
paul@69 | 66 | self.args = cgi.parse(keep_blank_values=True) |
paul@69 | 67 | return self.args |
paul@69 | 68 | |
paul@69 | 69 | def get_method(self): |
paul@69 | 70 | if self.method is None: |
paul@69 | 71 | self.method = getenv("REQUEST_METHOD") or "GET" |
paul@69 | 72 | return self.method |
paul@69 | 73 | |
paul@69 | 74 | def get_path(self): |
paul@69 | 75 | if self.path is None: |
paul@69 | 76 | self.path = getenv("SCRIPT_NAME") or "" |
paul@69 | 77 | return self.path |
paul@69 | 78 | |
paul@69 | 79 | def get_path_info(self): |
paul@69 | 80 | if self.path_info is None: |
paul@69 | 81 | self.path_info = getenv("PATH_INFO") or "" |
paul@69 | 82 | return self.path_info |
paul@69 | 83 | |
paul@69 | 84 | def get_user(self): |
paul@69 | 85 | if self.user is None: |
paul@69 | 86 | self.user = getenv("REMOTE_USER") or "" |
paul@69 | 87 | return self.user |
paul@69 | 88 | |
paul@69 | 89 | def get_output(self): |
paul@69 | 90 | return sys.stdout |
paul@69 | 91 | |
paul@69 | 92 | def get_url(self): |
paul@69 | 93 | path = self.get_path() |
paul@69 | 94 | path_info = self.get_path_info() |
paul@69 | 95 | return "%s%s" % (path.rstrip("/"), path_info) |
paul@69 | 96 | |
paul@154 | 97 | def new_url(self, path_info): |
paul@154 | 98 | path = self.get_path() |
paul@154 | 99 | return "%s/%s" % (path.rstrip("/"), path_info.lstrip("/")) |
paul@154 | 100 | |
paul@79 | 101 | class ManagerHandler(Handler): |
paul@79 | 102 | |
paul@121 | 103 | """ |
paul@121 | 104 | A content handler for use by the manager, as opposed to operating within the |
paul@121 | 105 | mail processing pipeline. |
paul@121 | 106 | """ |
paul@79 | 107 | |
paul@121 | 108 | def __init__(self, obj, user, messenger): |
paul@121 | 109 | details, details_attr = obj.values()[0] |
paul@79 | 110 | Handler.__init__(self, details) |
paul@121 | 111 | self.obj = obj |
paul@79 | 112 | self.user = user |
paul@82 | 113 | self.messenger = messenger |
paul@82 | 114 | |
paul@79 | 115 | self.organisers = map(get_address, self.get_values("ORGANIZER")) |
paul@79 | 116 | |
paul@79 | 117 | # Communication methods. |
paul@79 | 118 | |
paul@79 | 119 | def send_message(self, sender): |
paul@79 | 120 | |
paul@79 | 121 | """ |
paul@128 | 122 | Create a full calendar object and send it to the organisers, sending a |
paul@128 | 123 | copy to the 'sender'. |
paul@79 | 124 | """ |
paul@79 | 125 | |
paul@121 | 126 | node = to_node(self.obj) |
paul@79 | 127 | part = to_part("REPLY", [node]) |
paul@178 | 128 | message = self.messenger.make_outgoing_message([part], self.organisers, outgoing_bcc=sender) |
paul@128 | 129 | self.messenger.sendmail(self.organisers, message.as_string(), outgoing_bcc=sender) |
paul@79 | 130 | |
paul@79 | 131 | # Action methods. |
paul@79 | 132 | |
paul@155 | 133 | def process_request(self, accept, update=False): |
paul@79 | 134 | |
paul@79 | 135 | """ |
paul@79 | 136 | Process the current request for the given 'user', accepting any request |
paul@79 | 137 | when 'accept' is true, declining requests otherwise. Return whether any |
paul@79 | 138 | action was taken. |
paul@155 | 139 | |
paul@155 | 140 | If 'update' is given, the sequence number will be incremented in order |
paul@155 | 141 | to override any previous response. |
paul@79 | 142 | """ |
paul@79 | 143 | |
paul@79 | 144 | # When accepting or declining, do so only on behalf of this user, |
paul@79 | 145 | # preserving any other attributes set as an attendee. |
paul@79 | 146 | |
paul@79 | 147 | for attendee, attendee_attr in self.get_items("ATTENDEE"): |
paul@79 | 148 | |
paul@79 | 149 | if attendee == self.user: |
paul@79 | 150 | freebusy = self.store.get_freebusy(attendee) |
paul@79 | 151 | |
paul@79 | 152 | attendee_attr["PARTSTAT"] = accept and "ACCEPTED" or "DECLINED" |
paul@128 | 153 | if self.messenger and self.messenger.sender != get_address(attendee): |
paul@128 | 154 | attendee_attr["SENT-BY"] = get_uri(self.messenger.sender) |
paul@79 | 155 | self.details["ATTENDEE"] = [(attendee, attendee_attr)] |
paul@155 | 156 | if update: |
paul@155 | 157 | sequence = self.get_value("SEQUENCE") or "0" |
paul@155 | 158 | self.details["SEQUENCE"] = [(str(int(sequence) + 1), {})] |
paul@158 | 159 | self.update_dtstamp() |
paul@155 | 160 | |
paul@79 | 161 | self.send_message(get_address(attendee)) |
paul@79 | 162 | |
paul@79 | 163 | return True |
paul@79 | 164 | |
paul@79 | 165 | return False |
paul@79 | 166 | |
paul@69 | 167 | class Manager: |
paul@69 | 168 | |
paul@69 | 169 | "A simple manager application." |
paul@69 | 170 | |
paul@82 | 171 | def __init__(self, messenger=None): |
paul@82 | 172 | self.messenger = messenger or Messenger() |
paul@82 | 173 | |
paul@69 | 174 | self.env = CGIEnvironment() |
paul@69 | 175 | user = self.env.get_user() |
paul@77 | 176 | self.user = user and get_uri(user) or None |
paul@147 | 177 | self.preferences = None |
paul@149 | 178 | self.locale = None |
paul@121 | 179 | self.requests = None |
paul@121 | 180 | |
paul@69 | 181 | self.out = self.env.get_output() |
paul@69 | 182 | self.page = markup.page() |
paul@69 | 183 | self.encoding = "utf-8" |
paul@69 | 184 | |
paul@77 | 185 | self.store = imip_store.FileStore() |
paul@162 | 186 | self.objects = {} |
paul@77 | 187 | |
paul@77 | 188 | try: |
paul@77 | 189 | self.publisher = imip_store.FilePublisher() |
paul@77 | 190 | except OSError: |
paul@77 | 191 | self.publisher = None |
paul@77 | 192 | |
paul@121 | 193 | def _get_uid(self, path_info): |
paul@121 | 194 | return path_info.lstrip("/").split("/", 1)[0] |
paul@121 | 195 | |
paul@117 | 196 | def _get_object(self, uid): |
paul@162 | 197 | if self.objects.has_key(uid): |
paul@162 | 198 | return self.objects[uid] |
paul@162 | 199 | |
paul@117 | 200 | f = uid and self.store.get_event(self.user, uid) or None |
paul@117 | 201 | |
paul@117 | 202 | if not f: |
paul@117 | 203 | return None |
paul@117 | 204 | |
paul@162 | 205 | self.objects[uid] = obj = parse_object(f, "utf-8") |
paul@117 | 206 | |
paul@117 | 207 | if not obj: |
paul@117 | 208 | return None |
paul@117 | 209 | |
paul@121 | 210 | return obj |
paul@121 | 211 | |
paul@121 | 212 | def _get_details(self, obj): |
paul@121 | 213 | details, details_attr = obj.values()[0] |
paul@121 | 214 | return details |
paul@121 | 215 | |
paul@121 | 216 | def _get_requests(self): |
paul@121 | 217 | if self.requests is None: |
paul@121 | 218 | self.requests = self.store.get_requests(self.user) |
paul@121 | 219 | return self.requests |
paul@117 | 220 | |
paul@162 | 221 | def _get_request_summary(self): |
paul@162 | 222 | summary = [] |
paul@162 | 223 | for uid in self._get_requests(): |
paul@162 | 224 | obj = self._get_object(uid) |
paul@162 | 225 | if obj: |
paul@162 | 226 | details = self._get_details(obj) |
paul@162 | 227 | summary.append(( |
paul@162 | 228 | get_value(details, "DTSTART"), |
paul@162 | 229 | get_value(details, "DTEND"), |
paul@162 | 230 | uid |
paul@162 | 231 | )) |
paul@162 | 232 | return summary |
paul@162 | 233 | |
paul@147 | 234 | # Preference methods. |
paul@147 | 235 | |
paul@149 | 236 | def get_user_locale(self): |
paul@149 | 237 | if not self.locale: |
paul@149 | 238 | self.locale = self.get_preferences().get("LANG", "C") |
paul@149 | 239 | return self.locale |
paul@147 | 240 | |
paul@147 | 241 | def get_preferences(self): |
paul@147 | 242 | if not self.preferences: |
paul@147 | 243 | self.preferences = Preferences(self.user) |
paul@147 | 244 | return self.preferences |
paul@147 | 245 | |
paul@162 | 246 | # Prettyprinting of dates and times. |
paul@162 | 247 | |
paul@149 | 248 | def format_date(self, dt, format): |
paul@149 | 249 | return self._format_datetime(babel.dates.format_date, dt, format) |
paul@149 | 250 | |
paul@149 | 251 | def format_time(self, dt, format): |
paul@149 | 252 | return self._format_datetime(babel.dates.format_time, dt, format) |
paul@149 | 253 | |
paul@149 | 254 | def format_datetime(self, dt, format): |
paul@149 | 255 | return self._format_datetime(babel.dates.format_datetime, dt, format) |
paul@149 | 256 | |
paul@149 | 257 | def _format_datetime(self, fn, dt, format): |
paul@149 | 258 | return fn(dt, format=format, locale=self.get_user_locale()) |
paul@149 | 259 | |
paul@78 | 260 | # Data management methods. |
paul@78 | 261 | |
paul@78 | 262 | def remove_request(self, uid): |
paul@105 | 263 | return self.store.dequeue_request(self.user, uid) |
paul@78 | 264 | |
paul@78 | 265 | # Presentation methods. |
paul@78 | 266 | |
paul@69 | 267 | def new_page(self, title): |
paul@192 | 268 | self.page.init(title=title, charset=self.encoding, css=self.env.new_url("styles.css")) |
paul@69 | 269 | |
paul@69 | 270 | def status(self, code, message): |
paul@123 | 271 | self.header("Status", "%s %s" % (code, message)) |
paul@123 | 272 | |
paul@123 | 273 | def header(self, header, value): |
paul@123 | 274 | print >>self.out, "%s: %s" % (header, value) |
paul@69 | 275 | |
paul@69 | 276 | def no_user(self): |
paul@69 | 277 | self.status(403, "Forbidden") |
paul@69 | 278 | self.new_page(title="Forbidden") |
paul@69 | 279 | self.page.p("You are not logged in and thus cannot access scheduling requests.") |
paul@69 | 280 | |
paul@70 | 281 | def no_page(self): |
paul@70 | 282 | self.status(404, "Not Found") |
paul@70 | 283 | self.new_page(title="Not Found") |
paul@70 | 284 | self.page.p("No page is provided at the given address.") |
paul@70 | 285 | |
paul@123 | 286 | def redirect(self, url): |
paul@123 | 287 | self.status(302, "Redirect") |
paul@123 | 288 | self.header("Location", url) |
paul@123 | 289 | self.new_page(title="Redirect") |
paul@123 | 290 | self.page.p("Redirecting to: %s" % url) |
paul@123 | 291 | |
paul@121 | 292 | # Request logic and page fragment methods. |
paul@121 | 293 | |
paul@202 | 294 | def handle_newevent(self): |
paul@202 | 295 | |
paul@202 | 296 | "Handle any new event operation." |
paul@202 | 297 | |
paul@202 | 298 | # Handle a submitted form. |
paul@202 | 299 | |
paul@202 | 300 | args = self.env.get_args() |
paul@202 | 301 | |
paul@202 | 302 | if not args.has_key("newevent"): |
paul@202 | 303 | return |
paul@202 | 304 | |
paul@202 | 305 | # Create a new event using the available information. |
paul@202 | 306 | |
paul@202 | 307 | slot = args.get("slot", [None])[0] |
paul@202 | 308 | participants = args.get("participants", []) |
paul@202 | 309 | |
paul@202 | 310 | if not slot: |
paul@202 | 311 | return |
paul@202 | 312 | |
paul@202 | 313 | start, end = slot.split("-") |
paul@202 | 314 | |
paul@202 | 315 | # Obtain the user's timezone. |
paul@202 | 316 | |
paul@202 | 317 | prefs = self.get_preferences() |
paul@202 | 318 | tzid = prefs.get("TZID", "UTC") |
paul@202 | 319 | |
paul@202 | 320 | # Invent a unique identifier. |
paul@202 | 321 | |
paul@202 | 322 | utcnow = format_datetime(to_timezone(datetime.utcnow(), "UTC")) |
paul@202 | 323 | uid = "imip-agent-%s-%s" % (utcnow, get_address(self.user)) |
paul@202 | 324 | |
paul@202 | 325 | # Create a calendar object and store it as a request. |
paul@202 | 326 | |
paul@202 | 327 | record = [] |
paul@202 | 328 | rwrite = record.append |
paul@202 | 329 | |
paul@202 | 330 | rwrite(("UID", {}, uid)) |
paul@202 | 331 | rwrite(("SUMMARY", {}, "New event at %s" % utcnow)) |
paul@202 | 332 | rwrite(("DTSTAMP", {}, utcnow)) |
paul@202 | 333 | rwrite(("DTSTART", {"VALUE" : "DATE-TIME"}, start)) |
paul@202 | 334 | rwrite(("DTEND", {"VALUE" : "DATE-TIME"}, end or |
paul@202 | 335 | format_datetime(get_end_of_day(get_datetime(start, {"TZID" : tzid}))) |
paul@202 | 336 | )) |
paul@202 | 337 | rwrite(("ORGANIZER", {}, self.user)) |
paul@202 | 338 | |
paul@202 | 339 | for participant in participants: |
paul@202 | 340 | if not participant: |
paul@202 | 341 | continue |
paul@202 | 342 | participant = get_uri(participant) |
paul@202 | 343 | if participant != self.user: |
paul@202 | 344 | rwrite(("ATTENDEE", {}, participant)) |
paul@202 | 345 | |
paul@202 | 346 | obj = ("VEVENT", {}, record) |
paul@202 | 347 | |
paul@202 | 348 | self.store.set_event(self.user, uid, obj) |
paul@202 | 349 | self.store.queue_request(self.user, uid) |
paul@202 | 350 | |
paul@202 | 351 | # Redirect to the object, where instead of attendee controls, |
paul@202 | 352 | # there will be organiser controls. |
paul@202 | 353 | |
paul@202 | 354 | self.redirect(self.env.new_url(uid)) |
paul@202 | 355 | |
paul@155 | 356 | def handle_request(self, uid, request, queued): |
paul@121 | 357 | |
paul@155 | 358 | """ |
paul@155 | 359 | Handle actions involving the given 'uid' and 'request' object, where |
paul@155 | 360 | 'queued' indicates that the object has not yet been handled. |
paul@155 | 361 | """ |
paul@121 | 362 | |
paul@121 | 363 | # Handle a submitted form. |
paul@121 | 364 | |
paul@121 | 365 | args = self.env.get_args() |
paul@123 | 366 | handled = True |
paul@121 | 367 | |
paul@121 | 368 | accept = args.has_key("accept") |
paul@121 | 369 | decline = args.has_key("decline") |
paul@155 | 370 | update = not queued and args.has_key("update") |
paul@121 | 371 | |
paul@121 | 372 | if accept or decline: |
paul@121 | 373 | |
paul@121 | 374 | handler = ManagerHandler(request, self.user, self.messenger) |
paul@121 | 375 | |
paul@155 | 376 | if handler.process_request(accept, update): |
paul@121 | 377 | |
paul@121 | 378 | # Remove the request from the list. |
paul@121 | 379 | |
paul@121 | 380 | self.remove_request(uid) |
paul@121 | 381 | |
paul@121 | 382 | elif args.has_key("ignore"): |
paul@121 | 383 | |
paul@121 | 384 | # Remove the request from the list. |
paul@121 | 385 | |
paul@121 | 386 | self.remove_request(uid) |
paul@121 | 387 | |
paul@121 | 388 | else: |
paul@123 | 389 | handled = False |
paul@121 | 390 | |
paul@123 | 391 | if handled: |
paul@123 | 392 | self.redirect(self.env.get_path()) |
paul@123 | 393 | |
paul@123 | 394 | return handled |
paul@121 | 395 | |
paul@155 | 396 | def show_request_form(self, obj, needs_action): |
paul@155 | 397 | |
paul@155 | 398 | """ |
paul@155 | 399 | Show a form for a request concerning 'obj', indicating whether action is |
paul@155 | 400 | needed if 'needs_action' is specified as a true value. |
paul@155 | 401 | """ |
paul@155 | 402 | |
paul@155 | 403 | details = self._get_details(obj) |
paul@155 | 404 | |
paul@155 | 405 | attendees = get_value_map(details, "ATTENDEE") |
paul@155 | 406 | attendee_attr = attendees.get(self.user) |
paul@121 | 407 | |
paul@155 | 408 | if attendee_attr: |
paul@155 | 409 | partstat = attendee_attr.get("PARTSTAT") |
paul@155 | 410 | if partstat == "ACCEPTED": |
paul@155 | 411 | self.page.p("This request has been accepted.") |
paul@155 | 412 | elif partstat == "DECLINED": |
paul@155 | 413 | self.page.p("This request has been declined.") |
paul@155 | 414 | else: |
paul@155 | 415 | self.page.p("This request has been ignored.") |
paul@121 | 416 | |
paul@155 | 417 | if needs_action: |
paul@155 | 418 | self.page.p("An action is required for this request:") |
paul@155 | 419 | else: |
paul@155 | 420 | self.page.p("This request can be updated as follows:") |
paul@155 | 421 | |
paul@121 | 422 | self.page.form(method="POST") |
paul@121 | 423 | self.page.p() |
paul@121 | 424 | self.page.input(name="accept", type="submit", value="Accept") |
paul@121 | 425 | self.page.add(" ") |
paul@121 | 426 | self.page.input(name="decline", type="submit", value="Decline") |
paul@121 | 427 | self.page.add(" ") |
paul@121 | 428 | self.page.input(name="ignore", type="submit", value="Ignore") |
paul@155 | 429 | if not needs_action: |
paul@155 | 430 | self.page.input(name="update", type="hidden", value="true") |
paul@121 | 431 | self.page.p.close() |
paul@121 | 432 | self.page.form.close() |
paul@121 | 433 | |
paul@121 | 434 | def show_object_on_page(self, uid, obj): |
paul@121 | 435 | |
paul@121 | 436 | """ |
paul@121 | 437 | Show the calendar object with the given 'uid' and representation 'obj' |
paul@121 | 438 | on the current page. |
paul@121 | 439 | """ |
paul@121 | 440 | |
paul@154 | 441 | # Obtain the user's timezone. |
paul@154 | 442 | |
paul@154 | 443 | prefs = self.get_preferences() |
paul@154 | 444 | tzid = prefs.get("TZID", "UTC") |
paul@121 | 445 | |
paul@121 | 446 | # Provide a summary of the object. |
paul@121 | 447 | |
paul@154 | 448 | details = self._get_details(obj) |
paul@154 | 449 | |
paul@121 | 450 | self.page.dl() |
paul@121 | 451 | |
paul@121 | 452 | for name in ["SUMMARY", "DTSTART", "DTEND", "ORGANIZER", "ATTENDEE"]: |
paul@147 | 453 | if name in ["DTSTART", "DTEND"]: |
paul@147 | 454 | value, attr = get_item(details, name) |
paul@154 | 455 | tzid = attr.get("TZID", tzid) |
paul@149 | 456 | value = self.format_datetime(to_timezone(get_datetime(value), tzid), "full") |
paul@121 | 457 | self.page.dt(name) |
paul@121 | 458 | self.page.dd(value) |
paul@147 | 459 | else: |
paul@147 | 460 | for value in get_values(details, name): |
paul@147 | 461 | self.page.dt(name) |
paul@147 | 462 | self.page.dd(value) |
paul@121 | 463 | |
paul@121 | 464 | self.page.dl.close() |
paul@121 | 465 | |
paul@121 | 466 | dtstart = format_datetime(get_utc_datetime(details, "DTSTART")) |
paul@121 | 467 | dtend = format_datetime(get_utc_datetime(details, "DTEND")) |
paul@121 | 468 | |
paul@121 | 469 | # Indicate whether there are conflicting events. |
paul@121 | 470 | |
paul@121 | 471 | freebusy = self.store.get_freebusy(self.user) |
paul@121 | 472 | |
paul@121 | 473 | if freebusy: |
paul@121 | 474 | |
paul@121 | 475 | # Obtain any time zone details from the suggested event. |
paul@121 | 476 | |
paul@121 | 477 | _dtstart, attr = get_item(details, "DTSTART") |
paul@154 | 478 | tzid = attr.get("TZID", tzid) |
paul@121 | 479 | |
paul@121 | 480 | # Show any conflicts. |
paul@121 | 481 | |
paul@121 | 482 | for t in have_conflict(freebusy, [(dtstart, dtend)], True): |
paul@121 | 483 | start, end, found_uid = t[:3] |
paul@154 | 484 | |
paul@154 | 485 | # Provide details of any conflicting event. |
paul@154 | 486 | |
paul@121 | 487 | if uid != found_uid: |
paul@149 | 488 | start = self.format_datetime(to_timezone(get_datetime(start), tzid), "full") |
paul@149 | 489 | end = self.format_datetime(to_timezone(get_datetime(end), tzid), "full") |
paul@154 | 490 | self.page.p("Event conflicts with another from %s to %s: " % (start, end)) |
paul@154 | 491 | |
paul@154 | 492 | # Show the event summary for the conflicting event. |
paul@154 | 493 | |
paul@154 | 494 | found_obj = self._get_object(found_uid) |
paul@154 | 495 | if found_obj: |
paul@154 | 496 | found_details = self._get_details(found_obj) |
paul@154 | 497 | self.page.a(get_value(found_details, "SUMMARY"), href=self.env.new_url(found_uid)) |
paul@121 | 498 | |
paul@121 | 499 | def show_requests_on_page(self): |
paul@69 | 500 | |
paul@69 | 501 | "Show requests for the current user." |
paul@69 | 502 | |
paul@69 | 503 | # NOTE: This list could be more informative, but it is envisaged that |
paul@69 | 504 | # NOTE: the requests would be visited directly anyway. |
paul@69 | 505 | |
paul@121 | 506 | requests = self._get_requests() |
paul@70 | 507 | |
paul@185 | 508 | self.page.div(id="pending-requests") |
paul@185 | 509 | |
paul@80 | 510 | if requests: |
paul@114 | 511 | self.page.p("Pending requests:") |
paul@114 | 512 | |
paul@80 | 513 | self.page.ul() |
paul@69 | 514 | |
paul@80 | 515 | for request in requests: |
paul@165 | 516 | obj = self._get_object(request) |
paul@165 | 517 | if obj: |
paul@165 | 518 | details = self._get_details(obj) |
paul@165 | 519 | self.page.li() |
paul@171 | 520 | self.page.a(get_value(details, "SUMMARY"), href="#request-%s" % request) |
paul@165 | 521 | self.page.li.close() |
paul@80 | 522 | |
paul@80 | 523 | self.page.ul.close() |
paul@80 | 524 | |
paul@80 | 525 | else: |
paul@80 | 526 | self.page.p("There are no pending requests.") |
paul@69 | 527 | |
paul@185 | 528 | self.page.div.close() |
paul@185 | 529 | |
paul@185 | 530 | def show_participants_on_page(self): |
paul@185 | 531 | |
paul@185 | 532 | "Show participants for scheduling purposes." |
paul@185 | 533 | |
paul@185 | 534 | args = self.env.get_args() |
paul@185 | 535 | participants = args.get("participants", []) |
paul@185 | 536 | |
paul@185 | 537 | try: |
paul@185 | 538 | for name, value in args.items(): |
paul@185 | 539 | if name.startswith("remove-participant-"): |
paul@185 | 540 | i = int(name[len("remove-participant-"):]) |
paul@185 | 541 | del participants[i] |
paul@185 | 542 | break |
paul@185 | 543 | except ValueError: |
paul@185 | 544 | pass |
paul@185 | 545 | |
paul@185 | 546 | # Trim empty participants. |
paul@185 | 547 | |
paul@185 | 548 | while participants and not participants[-1].strip(): |
paul@185 | 549 | participants.pop() |
paul@185 | 550 | |
paul@185 | 551 | # Show any specified participants together with controls to remove and |
paul@185 | 552 | # add participants. |
paul@185 | 553 | |
paul@185 | 554 | self.page.div(id="participants") |
paul@185 | 555 | |
paul@185 | 556 | self.page.p("Participants for scheduling:") |
paul@185 | 557 | |
paul@185 | 558 | for i, participant in enumerate(participants): |
paul@185 | 559 | self.page.p() |
paul@185 | 560 | self.page.input(name="participants", type="text", value=participant) |
paul@185 | 561 | self.page.input(name="remove-participant-%d" % i, type="submit", value="Remove") |
paul@185 | 562 | self.page.p.close() |
paul@185 | 563 | |
paul@185 | 564 | self.page.p() |
paul@185 | 565 | self.page.input(name="participants", type="text") |
paul@185 | 566 | self.page.input(name="add-participant", type="submit", value="Add") |
paul@185 | 567 | self.page.p.close() |
paul@185 | 568 | |
paul@185 | 569 | self.page.div.close() |
paul@185 | 570 | |
paul@185 | 571 | return participants |
paul@185 | 572 | |
paul@121 | 573 | # Full page output methods. |
paul@70 | 574 | |
paul@121 | 575 | def show_object(self, path_info): |
paul@70 | 576 | |
paul@121 | 577 | "Show an object request using the given 'path_info' for the current user." |
paul@70 | 578 | |
paul@121 | 579 | uid = self._get_uid(path_info) |
paul@121 | 580 | obj = self._get_object(uid) |
paul@121 | 581 | |
paul@121 | 582 | if not obj: |
paul@70 | 583 | return False |
paul@70 | 584 | |
paul@123 | 585 | is_request = uid in self._get_requests() |
paul@155 | 586 | handled = self.handle_request(uid, obj, is_request) |
paul@77 | 587 | |
paul@123 | 588 | if handled: |
paul@123 | 589 | return True |
paul@73 | 590 | |
paul@123 | 591 | self.new_page(title="Event") |
paul@79 | 592 | |
paul@121 | 593 | self.show_object_on_page(uid, obj) |
paul@73 | 594 | |
paul@155 | 595 | self.show_request_form(obj, is_request and not handled) |
paul@73 | 596 | |
paul@70 | 597 | return True |
paul@70 | 598 | |
paul@114 | 599 | def show_calendar(self): |
paul@114 | 600 | |
paul@114 | 601 | "Show the calendar for the current user." |
paul@114 | 602 | |
paul@202 | 603 | handled = self.handle_newevent() |
paul@202 | 604 | |
paul@114 | 605 | self.new_page(title="Calendar") |
paul@162 | 606 | page = self.page |
paul@162 | 607 | |
paul@196 | 608 | # Form controls are used in various places on the calendar page. |
paul@196 | 609 | |
paul@196 | 610 | page.form(method="POST") |
paul@196 | 611 | |
paul@121 | 612 | self.show_requests_on_page() |
paul@185 | 613 | participants = self.show_participants_on_page() |
paul@114 | 614 | |
paul@196 | 615 | # Show a button for scheduling a new event. |
paul@196 | 616 | |
paul@196 | 617 | page.p() |
paul@196 | 618 | page.input(name="newevent", type="submit", value="New event", id="newevent") |
paul@196 | 619 | page.p.close() |
paul@196 | 620 | |
paul@203 | 621 | # Show a control for hiding empty slots. |
paul@203 | 622 | # The positioning of the control, paragraph and table are important here. |
paul@203 | 623 | |
paul@203 | 624 | page.input(name="hideslots", type="checkbox", value="hide", id="hideslots") |
paul@203 | 625 | |
paul@203 | 626 | page.p() |
paul@203 | 627 | page.label("Hide unused time periods", for_="hideslots", class_="enable") |
paul@203 | 628 | page.label("Show unused time periods", for_="hideslots", class_="disable") |
paul@203 | 629 | page.p.close() |
paul@203 | 630 | |
paul@114 | 631 | freebusy = self.store.get_freebusy(self.user) |
paul@114 | 632 | |
paul@114 | 633 | if not freebusy: |
paul@114 | 634 | page.p("No events scheduled.") |
paul@114 | 635 | return |
paul@114 | 636 | |
paul@154 | 637 | # Obtain the user's timezone. |
paul@147 | 638 | |
paul@147 | 639 | prefs = self.get_preferences() |
paul@153 | 640 | tzid = prefs.get("TZID", "UTC") |
paul@147 | 641 | |
paul@114 | 642 | # Day view: start at the earliest known day and produce days until the |
paul@114 | 643 | # latest known day, perhaps with expandable sections of empty days. |
paul@114 | 644 | |
paul@114 | 645 | # Month view: start at the earliest known month and produce months until |
paul@114 | 646 | # the latest known month, perhaps with expandable sections of empty |
paul@114 | 647 | # months. |
paul@114 | 648 | |
paul@114 | 649 | # Details of users to invite to new events could be superimposed on the |
paul@114 | 650 | # calendar. |
paul@114 | 651 | |
paul@185 | 652 | # Requests are listed and linked to their tentative positions in the |
paul@185 | 653 | # calendar. Other participants are also shown. |
paul@185 | 654 | |
paul@185 | 655 | request_summary = self._get_request_summary() |
paul@185 | 656 | |
paul@185 | 657 | period_groups = [request_summary, freebusy] |
paul@185 | 658 | period_group_types = ["request", "freebusy"] |
paul@185 | 659 | period_group_sources = ["Pending requests", "Your schedule"] |
paul@185 | 660 | |
paul@187 | 661 | for i, participant in enumerate(participants): |
paul@185 | 662 | period_groups.append(self.store.get_freebusy_for_other(self.user, get_uri(participant))) |
paul@187 | 663 | period_group_types.append("freebusy-part%d" % i) |
paul@185 | 664 | period_group_sources.append(participant) |
paul@114 | 665 | |
paul@162 | 666 | groups = [] |
paul@162 | 667 | group_columns = [] |
paul@185 | 668 | group_types = period_group_types |
paul@185 | 669 | group_sources = period_group_sources |
paul@162 | 670 | all_points = set() |
paul@162 | 671 | |
paul@162 | 672 | # Obtain time point information for each group of periods. |
paul@162 | 673 | |
paul@185 | 674 | for periods in period_groups: |
paul@162 | 675 | periods = convert_periods(periods, tzid) |
paul@162 | 676 | |
paul@162 | 677 | # Get the time scale with start and end points. |
paul@162 | 678 | |
paul@162 | 679 | scale = get_scale(periods) |
paul@162 | 680 | |
paul@162 | 681 | # Get the time slots for the periods. |
paul@162 | 682 | |
paul@162 | 683 | slots = get_slots(scale) |
paul@162 | 684 | |
paul@162 | 685 | # Add start of day time points for multi-day periods. |
paul@162 | 686 | |
paul@162 | 687 | add_day_start_points(slots) |
paul@162 | 688 | |
paul@162 | 689 | # Record the slots and all time points employed. |
paul@162 | 690 | |
paul@162 | 691 | groups.append(slots) |
paul@201 | 692 | all_points.update([point for point, active in slots]) |
paul@162 | 693 | |
paul@162 | 694 | # Partition the groups into days. |
paul@162 | 695 | |
paul@162 | 696 | days = {} |
paul@162 | 697 | partitioned_groups = [] |
paul@171 | 698 | partitioned_group_types = [] |
paul@185 | 699 | partitioned_group_sources = [] |
paul@162 | 700 | |
paul@185 | 701 | for slots, group_type, group_source in zip(groups, group_types, group_sources): |
paul@162 | 702 | |
paul@162 | 703 | # Propagate time points to all groups of time slots. |
paul@162 | 704 | |
paul@162 | 705 | add_slots(slots, all_points) |
paul@162 | 706 | |
paul@162 | 707 | # Count the number of columns employed by the group. |
paul@162 | 708 | |
paul@162 | 709 | columns = 0 |
paul@162 | 710 | |
paul@162 | 711 | # Partition the time slots by day. |
paul@162 | 712 | |
paul@162 | 713 | partitioned = {} |
paul@162 | 714 | |
paul@162 | 715 | for day, day_slots in partition_by_day(slots).items(): |
paul@201 | 716 | intervals = [] |
paul@201 | 717 | last = None |
paul@201 | 718 | |
paul@201 | 719 | for point, active in day_slots: |
paul@201 | 720 | columns = max(columns, len(active)) |
paul@201 | 721 | if last: |
paul@201 | 722 | intervals.append((last, point)) |
paul@201 | 723 | last = point |
paul@201 | 724 | |
paul@201 | 725 | if last: |
paul@201 | 726 | intervals.append((last, None)) |
paul@162 | 727 | |
paul@162 | 728 | if not days.has_key(day): |
paul@162 | 729 | days[day] = set() |
paul@162 | 730 | |
paul@162 | 731 | # Convert each partition to a mapping from points to active |
paul@162 | 732 | # periods. |
paul@162 | 733 | |
paul@201 | 734 | partitioned[day] = dict(day_slots) |
paul@201 | 735 | |
paul@201 | 736 | # Record the divisions or intervals within each day. |
paul@201 | 737 | |
paul@201 | 738 | days[day].update(intervals) |
paul@162 | 739 | |
paul@194 | 740 | if group_type != "request" or columns: |
paul@194 | 741 | group_columns.append(columns) |
paul@194 | 742 | partitioned_groups.append(partitioned) |
paul@194 | 743 | partitioned_group_types.append(group_type) |
paul@194 | 744 | partitioned_group_sources.append(group_source) |
paul@114 | 745 | |
paul@188 | 746 | page.table(cellspacing=5, cellpadding=5, id="calendar") |
paul@188 | 747 | self.show_calendar_participant_headings(partitioned_group_types, partitioned_group_sources, group_columns) |
paul@171 | 748 | self.show_calendar_days(days, partitioned_groups, partitioned_group_types, group_columns) |
paul@162 | 749 | page.table.close() |
paul@114 | 750 | |
paul@196 | 751 | # End the form region. |
paul@196 | 752 | |
paul@196 | 753 | page.form.close() |
paul@196 | 754 | |
paul@188 | 755 | def show_calendar_participant_headings(self, group_types, group_sources, group_columns): |
paul@186 | 756 | |
paul@186 | 757 | """ |
paul@186 | 758 | Show headings for the participants and other scheduling contributors, |
paul@188 | 759 | defined by 'group_types', 'group_sources' and 'group_columns'. |
paul@186 | 760 | """ |
paul@186 | 761 | |
paul@185 | 762 | page = self.page |
paul@185 | 763 | |
paul@188 | 764 | page.colgroup(span=1, id="columns-timeslot") |
paul@186 | 765 | |
paul@188 | 766 | for group_type, columns in zip(group_types, group_columns): |
paul@191 | 767 | page.colgroup(span=max(columns, 1), id="columns-%s" % group_type) |
paul@186 | 768 | |
paul@185 | 769 | page.thead() |
paul@185 | 770 | page.tr() |
paul@185 | 771 | page.th("", class_="emptyheading") |
paul@185 | 772 | |
paul@193 | 773 | for group_type, source, columns in zip(group_types, group_sources, group_columns): |
paul@193 | 774 | page.th(source, |
paul@193 | 775 | class_=(group_type == "request" and "requestheading" or "participantheading"), |
paul@193 | 776 | colspan=max(columns, 1)) |
paul@185 | 777 | |
paul@185 | 778 | page.tr.close() |
paul@185 | 779 | page.thead.close() |
paul@185 | 780 | |
paul@171 | 781 | def show_calendar_days(self, days, partitioned_groups, partitioned_group_types, group_columns): |
paul@186 | 782 | |
paul@186 | 783 | """ |
paul@186 | 784 | Show calendar days, defined by a collection of 'days', the contributing |
paul@186 | 785 | period information as 'partitioned_groups' (partitioned by day), the |
paul@186 | 786 | 'partitioned_group_types' indicating the kind of contribution involved, |
paul@186 | 787 | and the 'group_columns' defining the number of columns in each group. |
paul@186 | 788 | """ |
paul@186 | 789 | |
paul@162 | 790 | page = self.page |
paul@162 | 791 | |
paul@191 | 792 | # Determine the number of columns required. Where participants provide |
paul@191 | 793 | # no columns for events, one still needs to be provided for the |
paul@191 | 794 | # participant itself. |
paul@147 | 795 | |
paul@191 | 796 | all_columns = sum([max(columns, 1) for columns in group_columns]) |
paul@191 | 797 | |
paul@191 | 798 | # Determine the days providing time slots. |
paul@191 | 799 | |
paul@162 | 800 | all_days = days.items() |
paul@162 | 801 | all_days.sort() |
paul@162 | 802 | |
paul@162 | 803 | # Produce a heading and time points for each day. |
paul@162 | 804 | |
paul@201 | 805 | for day, intervals in all_days: |
paul@186 | 806 | page.thead() |
paul@114 | 807 | page.tr() |
paul@171 | 808 | page.th(class_="dayheading", colspan=all_columns+1) |
paul@153 | 809 | page.add(self.format_date(day, "full")) |
paul@114 | 810 | page.th.close() |
paul@153 | 811 | page.tr.close() |
paul@186 | 812 | page.thead.close() |
paul@114 | 813 | |
paul@162 | 814 | groups_for_day = [partitioned.get(day) for partitioned in partitioned_groups] |
paul@162 | 815 | |
paul@186 | 816 | page.tbody() |
paul@201 | 817 | self.show_calendar_points(intervals, groups_for_day, partitioned_group_types, group_columns) |
paul@186 | 818 | page.tbody.close() |
paul@185 | 819 | |
paul@201 | 820 | def show_calendar_points(self, intervals, groups, group_types, group_columns): |
paul@186 | 821 | |
paul@186 | 822 | """ |
paul@201 | 823 | Show the time 'intervals' along with period information from the given |
paul@186 | 824 | 'groups', having the indicated 'group_types', each with the number of |
paul@186 | 825 | columns given by 'group_columns'. |
paul@186 | 826 | """ |
paul@186 | 827 | |
paul@162 | 828 | page = self.page |
paul@162 | 829 | |
paul@203 | 830 | # Produce a row for each interval. |
paul@162 | 831 | |
paul@201 | 832 | intervals = list(intervals) |
paul@201 | 833 | intervals.sort() |
paul@162 | 834 | |
paul@201 | 835 | for point, endpoint in intervals: |
paul@162 | 836 | continuation = point == get_start_of_day(point) |
paul@153 | 837 | |
paul@203 | 838 | # Some rows contain no period details and are marked as such. |
paul@203 | 839 | |
paul@203 | 840 | have_active = reduce(lambda x, y: x or y, [slots.get(point) for slots in groups], None) |
paul@203 | 841 | |
paul@203 | 842 | css = " ".join( |
paul@203 | 843 | ["slot"] + |
paul@203 | 844 | (not have_active and ["empty"] or []) + |
paul@203 | 845 | (continuation and ["daystart"] or []) |
paul@203 | 846 | ) |
paul@203 | 847 | |
paul@203 | 848 | page.tr(class_=css) |
paul@162 | 849 | page.th(class_="timeslot") |
paul@201 | 850 | self._time_point(point, endpoint) |
paul@162 | 851 | page.th.close() |
paul@162 | 852 | |
paul@162 | 853 | # Obtain slots for the time point from each group. |
paul@162 | 854 | |
paul@171 | 855 | for columns, slots, group_type in zip(group_columns, groups, group_types): |
paul@162 | 856 | active = slots and slots.get(point) |
paul@162 | 857 | |
paul@191 | 858 | # Where no periods exist for the given time interval, generate |
paul@191 | 859 | # an empty cell. Where a participant provides no periods at all, |
paul@191 | 860 | # the colspan is adjusted to be 1, not 0. |
paul@191 | 861 | |
paul@162 | 862 | if not active: |
paul@196 | 863 | page.td(class_="empty container", colspan=max(columns, 1)) |
paul@201 | 864 | self._empty_slot(point, endpoint) |
paul@196 | 865 | page.td.close() |
paul@162 | 866 | continue |
paul@162 | 867 | |
paul@162 | 868 | slots = slots.items() |
paul@162 | 869 | slots.sort() |
paul@162 | 870 | spans = get_spans(slots) |
paul@162 | 871 | |
paul@162 | 872 | # Show a column for each active period. |
paul@117 | 873 | |
paul@153 | 874 | for t in active: |
paul@185 | 875 | if t and len(t) >= 2: |
paul@185 | 876 | start, end, uid, key = get_freebusy_details(t) |
paul@185 | 877 | span = spans[key] |
paul@171 | 878 | |
paul@171 | 879 | # Produce a table cell only at the start of the period |
paul@171 | 880 | # or when continued at the start of a day. |
paul@171 | 881 | |
paul@153 | 882 | if point == start or continuation: |
paul@153 | 883 | |
paul@195 | 884 | has_continued = continuation and point != start |
paul@195 | 885 | will_continue = not ends_on_same_day(point, end) |
paul@195 | 886 | css = " ".join( |
paul@195 | 887 | ["event"] + |
paul@195 | 888 | (has_continued and ["continued"] or []) + |
paul@195 | 889 | (will_continue and ["continues"] or []) |
paul@195 | 890 | ) |
paul@195 | 891 | |
paul@189 | 892 | # Only anchor the first cell of events. |
paul@189 | 893 | |
paul@189 | 894 | if point == start: |
paul@195 | 895 | page.td(class_=css, rowspan=span, id="%s-%s" % (group_type, uid)) |
paul@189 | 896 | else: |
paul@195 | 897 | page.td(class_=css, rowspan=span) |
paul@171 | 898 | |
paul@153 | 899 | obj = self._get_object(uid) |
paul@185 | 900 | |
paul@185 | 901 | if not obj: |
paul@185 | 902 | page.span("") |
paul@185 | 903 | else: |
paul@153 | 904 | details = self._get_details(obj) |
paul@164 | 905 | summary = get_value(details, "SUMMARY") |
paul@171 | 906 | |
paul@171 | 907 | # Only link to events if they are not being |
paul@171 | 908 | # updated by requests. |
paul@171 | 909 | |
paul@171 | 910 | if uid in self._get_requests() and group_type != "request": |
paul@189 | 911 | page.span(summary) |
paul@164 | 912 | else: |
paul@171 | 913 | href = "%s/%s" % (self.env.get_url().rstrip("/"), uid) |
paul@189 | 914 | page.a(summary, href=href) |
paul@171 | 915 | |
paul@153 | 916 | page.td.close() |
paul@153 | 917 | else: |
paul@196 | 918 | page.td(class_="empty container") |
paul@201 | 919 | self._empty_slot(point, endpoint) |
paul@196 | 920 | page.td.close() |
paul@114 | 921 | |
paul@166 | 922 | # Pad with empty columns. |
paul@166 | 923 | |
paul@166 | 924 | i = columns - len(active) |
paul@166 | 925 | while i > 0: |
paul@166 | 926 | i -= 1 |
paul@196 | 927 | page.td(class_="empty container") |
paul@201 | 928 | self._empty_slot(point, endpoint) |
paul@196 | 929 | page.td.close() |
paul@166 | 930 | |
paul@162 | 931 | page.tr.close() |
paul@114 | 932 | |
paul@201 | 933 | def _time_point(self, point, endpoint): |
paul@201 | 934 | page = self.page |
paul@201 | 935 | value, identifier = self._slot_value_and_identifier(point, endpoint) |
paul@202 | 936 | slot = self.env.get_args().get("slot", [None])[0] |
paul@202 | 937 | if slot == value: |
paul@202 | 938 | page.input(name="slot", type="radio", value=value, id=identifier, class_="newevent", checked="checked") |
paul@202 | 939 | else: |
paul@202 | 940 | page.input(name="slot", type="radio", value=value, id=identifier, class_="newevent") |
paul@201 | 941 | page.label(self.format_time(point, "long"), class_="timepoint", for_=identifier) |
paul@201 | 942 | |
paul@201 | 943 | def _empty_slot(self, point, endpoint): |
paul@197 | 944 | page = self.page |
paul@201 | 945 | value, identifier = self._slot_value_and_identifier(point, endpoint) |
paul@201 | 946 | page.label("Make a new event in this period", class_="newevent popup", for_=identifier) |
paul@196 | 947 | |
paul@201 | 948 | def _slot_value_and_identifier(self, point, endpoint): |
paul@202 | 949 | value = "%s-%s" % (format_datetime(point), endpoint and format_datetime(endpoint) or "") |
paul@201 | 950 | identifier = "slot-%s" % value |
paul@201 | 951 | return value, identifier |
paul@196 | 952 | |
paul@69 | 953 | def select_action(self): |
paul@69 | 954 | |
paul@69 | 955 | "Select the desired action and show the result." |
paul@69 | 956 | |
paul@121 | 957 | path_info = self.env.get_path_info().strip("/") |
paul@121 | 958 | |
paul@69 | 959 | if not path_info: |
paul@114 | 960 | self.show_calendar() |
paul@121 | 961 | elif self.show_object(path_info): |
paul@70 | 962 | pass |
paul@70 | 963 | else: |
paul@70 | 964 | self.no_page() |
paul@69 | 965 | |
paul@82 | 966 | def __call__(self): |
paul@69 | 967 | |
paul@69 | 968 | "Interpret a request and show an appropriate response." |
paul@69 | 969 | |
paul@69 | 970 | if not self.user: |
paul@69 | 971 | self.no_user() |
paul@69 | 972 | else: |
paul@69 | 973 | self.select_action() |
paul@69 | 974 | |
paul@70 | 975 | # Write the headers and actual content. |
paul@70 | 976 | |
paul@69 | 977 | print >>self.out, "Content-Type: text/html; charset=%s" % self.encoding |
paul@69 | 978 | print >>self.out |
paul@69 | 979 | self.out.write(unicode(self.page).encode(self.encoding)) |
paul@69 | 980 | |
paul@69 | 981 | if __name__ == "__main__": |
paul@128 | 982 | Manager()() |
paul@69 | 983 | |
paul@69 | 984 | # vim: tabstop=4 expandtab shiftwidth=4 |