paul@418 | 1 | #!/usr/bin/env python |
paul@418 | 2 | |
paul@418 | 3 | """ |
paul@418 | 4 | General handler support for incoming calendar objects. |
paul@418 | 5 | |
paul@418 | 6 | Copyright (C) 2014, 2015 Paul Boddie <paul@boddie.org.uk> |
paul@418 | 7 | |
paul@418 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@418 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@418 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@418 | 11 | version. |
paul@418 | 12 | |
paul@418 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@418 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@418 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@418 | 16 | details. |
paul@418 | 17 | |
paul@418 | 18 | You should have received a copy of the GNU General Public License along with |
paul@418 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@418 | 20 | """ |
paul@418 | 21 | |
paul@418 | 22 | from datetime import datetime |
paul@418 | 23 | from email.mime.text import MIMEText |
paul@468 | 24 | from imiptools.client import Client |
paul@418 | 25 | from imiptools.config import MANAGER_PATH, MANAGER_URL |
paul@418 | 26 | from imiptools.data import Object, \ |
paul@468 | 27 | get_address, get_uri, get_value, \ |
paul@418 | 28 | is_new_object, uri_dict, uri_item, uri_values |
paul@563 | 29 | from imiptools.dates import format_datetime, get_recurrence_start_point, \ |
paul@561 | 30 | to_timezone |
paul@418 | 31 | from imiptools.period import can_schedule, remove_period, \ |
paul@418 | 32 | remove_additional_periods, remove_affected_period, \ |
paul@418 | 33 | update_freebusy |
paul@418 | 34 | from imiptools.profile import Preferences |
paul@418 | 35 | from socket import gethostname |
paul@418 | 36 | import imip_store |
paul@418 | 37 | |
paul@418 | 38 | # References to the Web interface. |
paul@418 | 39 | |
paul@418 | 40 | def get_manager_url(): |
paul@418 | 41 | url_base = MANAGER_URL or "http://%s/" % gethostname() |
paul@418 | 42 | return "%s/%s" % (url_base.rstrip("/"), MANAGER_PATH.lstrip("/")) |
paul@418 | 43 | |
paul@418 | 44 | def get_object_url(uid, recurrenceid=None): |
paul@418 | 45 | return "%s/%s%s" % ( |
paul@418 | 46 | get_manager_url().rstrip("/"), uid, |
paul@418 | 47 | recurrenceid and "/%s" % recurrenceid or "" |
paul@418 | 48 | ) |
paul@418 | 49 | |
paul@468 | 50 | class Handler(Client): |
paul@418 | 51 | |
paul@418 | 52 | "General handler support." |
paul@418 | 53 | |
paul@563 | 54 | def __init__(self, senders=None, recipient=None, messenger=None, store=None, |
paul@563 | 55 | publisher=None): |
paul@418 | 56 | |
paul@418 | 57 | """ |
paul@418 | 58 | Initialise the handler with the calendar 'obj' and the 'senders' and |
paul@418 | 59 | 'recipient' of the object (if specifically indicated). |
paul@563 | 60 | |
paul@563 | 61 | The optional 'store' and 'publisher' can be specified to override the |
paul@563 | 62 | default store and publisher objects. |
paul@418 | 63 | """ |
paul@418 | 64 | |
paul@468 | 65 | Client.__init__(self, recipient and get_uri(recipient)) |
paul@468 | 66 | |
paul@418 | 67 | self.senders = senders and set(map(get_address, senders)) |
paul@418 | 68 | self.recipient = recipient and get_address(recipient) |
paul@418 | 69 | self.messenger = messenger |
paul@418 | 70 | |
paul@418 | 71 | self.results = [] |
paul@418 | 72 | self.outgoing_methods = set() |
paul@418 | 73 | |
paul@418 | 74 | self.obj = None |
paul@418 | 75 | self.uid = None |
paul@418 | 76 | self.recurrenceid = None |
paul@418 | 77 | self.sequence = None |
paul@418 | 78 | self.dtstamp = None |
paul@418 | 79 | |
paul@563 | 80 | self.store = store or imip_store.FileStore() |
paul@418 | 81 | |
paul@418 | 82 | try: |
paul@563 | 83 | self.publisher = publisher or imip_store.FilePublisher() |
paul@418 | 84 | except OSError: |
paul@418 | 85 | self.publisher = None |
paul@418 | 86 | |
paul@418 | 87 | def set_object(self, obj): |
paul@418 | 88 | self.obj = obj |
paul@535 | 89 | self.uid = self.obj.get_uid() |
paul@535 | 90 | self.recurrenceid = self.obj.get_recurrenceid() |
paul@418 | 91 | self.sequence = self.obj.get_value("SEQUENCE") |
paul@418 | 92 | self.dtstamp = self.obj.get_value("DTSTAMP") |
paul@418 | 93 | |
paul@418 | 94 | def wrap(self, text, link=True): |
paul@418 | 95 | |
paul@418 | 96 | "Wrap any valid message for passing to the recipient." |
paul@418 | 97 | |
paul@418 | 98 | texts = [] |
paul@418 | 99 | texts.append(text) |
paul@418 | 100 | if link: |
paul@418 | 101 | texts.append("If your mail program cannot handle this " |
paul@418 | 102 | "message, you may view the details here:\n\n%s" % |
paul@418 | 103 | get_object_url(self.uid, self.recurrenceid)) |
paul@418 | 104 | |
paul@418 | 105 | return self.add_result(None, None, MIMEText("\n".join(texts))) |
paul@418 | 106 | |
paul@418 | 107 | # Result registration. |
paul@418 | 108 | |
paul@418 | 109 | def add_result(self, method, outgoing_recipients, part): |
paul@418 | 110 | |
paul@418 | 111 | """ |
paul@418 | 112 | Record a result having the given 'method', 'outgoing_recipients' and |
paul@418 | 113 | message part. |
paul@418 | 114 | """ |
paul@418 | 115 | |
paul@418 | 116 | if outgoing_recipients: |
paul@418 | 117 | self.outgoing_methods.add(method) |
paul@418 | 118 | self.results.append((outgoing_recipients, part)) |
paul@418 | 119 | |
paul@418 | 120 | def get_results(self): |
paul@418 | 121 | return self.results |
paul@418 | 122 | |
paul@418 | 123 | def get_outgoing_methods(self): |
paul@418 | 124 | return self.outgoing_methods |
paul@418 | 125 | |
paul@418 | 126 | # Convenience methods for modifying free/busy collections. |
paul@418 | 127 | |
paul@563 | 128 | def get_recurrence_start_point(self, recurrenceid): |
paul@511 | 129 | |
paul@511 | 130 | "Get 'recurrenceid' in a form suitable for matching free/busy entries." |
paul@511 | 131 | |
paul@561 | 132 | tzid = self.obj.get_tzid() or self.get_tzid() |
paul@563 | 133 | return get_recurrence_start_point(recurrenceid, tzid) |
paul@511 | 134 | |
paul@418 | 135 | def remove_from_freebusy(self, freebusy): |
paul@418 | 136 | |
paul@418 | 137 | "Remove this event from the given 'freebusy' collection." |
paul@418 | 138 | |
paul@523 | 139 | if not remove_period(freebusy, self.uid, self.recurrenceid) and self.recurrenceid: |
paul@563 | 140 | remove_affected_period(freebusy, self.uid, self.get_recurrence_start_point(self.recurrenceid)) |
paul@418 | 141 | |
paul@418 | 142 | def remove_freebusy_for_recurrences(self, freebusy, recurrenceids=None): |
paul@418 | 143 | |
paul@418 | 144 | """ |
paul@418 | 145 | Remove from 'freebusy' any original recurrence from parent free/busy |
paul@418 | 146 | details for the current object, if the current object is a specific |
paul@418 | 147 | additional recurrence. Otherwise, remove all additional recurrence |
paul@418 | 148 | information corresponding to 'recurrenceids', or if omitted, all |
paul@418 | 149 | recurrences. |
paul@418 | 150 | """ |
paul@418 | 151 | |
paul@418 | 152 | if self.recurrenceid: |
paul@563 | 153 | recurrenceid = self.get_recurrence_start_point(self.recurrenceid) |
paul@511 | 154 | remove_affected_period(freebusy, self.uid, recurrenceid) |
paul@418 | 155 | else: |
paul@418 | 156 | # Remove obsolete recurrence periods. |
paul@418 | 157 | |
paul@418 | 158 | remove_additional_periods(freebusy, self.uid, recurrenceids) |
paul@418 | 159 | |
paul@418 | 160 | # Remove original periods affected by additional recurrences. |
paul@418 | 161 | |
paul@418 | 162 | if recurrenceids: |
paul@418 | 163 | for recurrenceid in recurrenceids: |
paul@563 | 164 | recurrenceid = self.get_recurrence_start_point(recurrenceid) |
paul@418 | 165 | remove_affected_period(freebusy, self.uid, recurrenceid) |
paul@418 | 166 | |
paul@418 | 167 | def _update_freebusy(self, freebusy, periods, recurrenceid, transp=None): |
paul@418 | 168 | |
paul@418 | 169 | """ |
paul@418 | 170 | Update the 'freebusy' collection with the given 'periods', indicating an |
paul@418 | 171 | explicit 'recurrenceid' to affect either a recurrence or the parent |
paul@418 | 172 | event. |
paul@418 | 173 | """ |
paul@418 | 174 | |
paul@418 | 175 | update_freebusy(freebusy, periods, |
paul@418 | 176 | transp or self.obj.get_value("TRANSP"), |
paul@418 | 177 | self.uid, recurrenceid, |
paul@418 | 178 | self.obj.get_value("SUMMARY"), |
paul@418 | 179 | self.obj.get_value("ORGANIZER")) |
paul@418 | 180 | |
paul@418 | 181 | def update_freebusy(self, freebusy, periods, transp=None): |
paul@418 | 182 | |
paul@418 | 183 | """ |
paul@418 | 184 | Update the 'freebusy' collection for this event with the given |
paul@418 | 185 | 'periods'. |
paul@418 | 186 | """ |
paul@418 | 187 | |
paul@418 | 188 | self._update_freebusy(freebusy, periods, self.recurrenceid, transp) |
paul@418 | 189 | |
paul@418 | 190 | def update_freebusy_for_participant(self, freebusy, periods, attr, for_organiser=False): |
paul@418 | 191 | |
paul@418 | 192 | """ |
paul@418 | 193 | Update the 'freebusy' collection using the given 'periods', subject to |
paul@418 | 194 | the 'attr' provided for the participant, indicating whether this is |
paul@418 | 195 | being generated 'for_organiser' or not. |
paul@418 | 196 | """ |
paul@418 | 197 | |
paul@491 | 198 | # Organisers employ a special transparency if not attending. |
paul@418 | 199 | |
paul@505 | 200 | if for_organiser or not attr or attr.get("PARTSTAT") != "DECLINED": |
paul@491 | 201 | self.update_freebusy(freebusy, periods, transp=( |
paul@520 | 202 | for_organiser and not (attr and attr.get("PARTSTAT")) and "ORG" or None)) |
paul@418 | 203 | else: |
paul@418 | 204 | self.remove_from_freebusy(freebusy) |
paul@418 | 205 | |
paul@418 | 206 | # Convenience methods for updating stored free/busy information. |
paul@418 | 207 | |
paul@468 | 208 | def update_freebusy_from_participant(self, participant_item, for_organiser): |
paul@418 | 209 | |
paul@418 | 210 | """ |
paul@468 | 211 | For the calendar user, record the free/busy information for the |
paul@418 | 212 | 'participant_item' (a value plus attributes) representing a different |
paul@418 | 213 | identity, thus maintaining a separate record of their free/busy details. |
paul@418 | 214 | """ |
paul@418 | 215 | |
paul@418 | 216 | participant, participant_attr = participant_item |
paul@418 | 217 | |
paul@468 | 218 | if participant == self.user: |
paul@418 | 219 | return |
paul@418 | 220 | |
paul@468 | 221 | freebusy = self.store.get_freebusy_for_other(self.user, participant) |
paul@419 | 222 | |
paul@419 | 223 | # Obtain the stored object if the current object is not issued by the |
paul@419 | 224 | # organiser. |
paul@419 | 225 | |
paul@468 | 226 | obj = for_organiser and self.obj or self.get_object() |
paul@419 | 227 | if not obj: |
paul@419 | 228 | return |
paul@419 | 229 | |
paul@419 | 230 | # Obtain the affected periods. |
paul@419 | 231 | |
paul@557 | 232 | periods = obj.get_periods(self.get_tzid(), self.get_window_end()) |
paul@418 | 233 | |
paul@418 | 234 | # Record in the free/busy details unless a non-participating attendee. |
paul@505 | 235 | # Use any attendee information for an organiser, not the organiser's own |
paul@505 | 236 | # attributes. |
paul@505 | 237 | |
paul@505 | 238 | if for_organiser: |
paul@505 | 239 | participant_attr = obj.get_value_map("ATTENDEE").get(participant) |
paul@418 | 240 | |
paul@418 | 241 | self.update_freebusy_for_participant(freebusy, periods, participant_attr, |
paul@468 | 242 | for_organiser and not self.is_attendee(participant)) |
paul@418 | 243 | |
paul@505 | 244 | # Tidy up any obsolete recurrences. |
paul@505 | 245 | |
paul@468 | 246 | self.remove_freebusy_for_recurrences(freebusy, self.store.get_recurrences(self.user, self.uid)) |
paul@468 | 247 | self.store.set_freebusy_for_other(self.user, freebusy, participant) |
paul@418 | 248 | |
paul@468 | 249 | def update_freebusy_from_organiser(self, organiser_item): |
paul@418 | 250 | |
paul@418 | 251 | """ |
paul@468 | 252 | For the current user, record free/busy information from the |
paul@418 | 253 | 'organiser_item' (a value plus attributes). |
paul@418 | 254 | """ |
paul@418 | 255 | |
paul@468 | 256 | self.update_freebusy_from_participant(organiser_item, True) |
paul@418 | 257 | |
paul@468 | 258 | def update_freebusy_from_attendees(self, attendees): |
paul@418 | 259 | |
paul@468 | 260 | "For the current user, record free/busy information from 'attendees'." |
paul@418 | 261 | |
paul@418 | 262 | for attendee_item in attendees.items(): |
paul@468 | 263 | self.update_freebusy_from_participant(attendee_item, False) |
paul@418 | 264 | |
paul@418 | 265 | # Logic, filtering and access to calendar structures and other data. |
paul@418 | 266 | |
paul@468 | 267 | def is_attendee(self, identity, obj=None): |
paul@418 | 268 | |
paul@468 | 269 | """ |
paul@468 | 270 | Return whether 'identity' is an attendee in the current object, or in |
paul@468 | 271 | 'obj' if specified. |
paul@468 | 272 | """ |
paul@418 | 273 | |
paul@468 | 274 | return identity in uri_values((obj or self.obj).get_values("ATTENDEE")) |
paul@418 | 275 | |
paul@418 | 276 | def can_schedule(self, freebusy, periods): |
paul@418 | 277 | return can_schedule(freebusy, periods, self.uid, self.recurrenceid) |
paul@418 | 278 | |
paul@418 | 279 | def filter_by_senders(self, mapping): |
paul@418 | 280 | |
paul@418 | 281 | """ |
paul@418 | 282 | Return a list of items from 'mapping' filtered using sender information. |
paul@418 | 283 | """ |
paul@418 | 284 | |
paul@418 | 285 | if self.senders: |
paul@418 | 286 | |
paul@418 | 287 | # Get a mapping from senders to identities. |
paul@418 | 288 | |
paul@418 | 289 | identities = self.get_sender_identities(mapping) |
paul@418 | 290 | |
paul@418 | 291 | # Find the senders that are valid. |
paul@418 | 292 | |
paul@418 | 293 | senders = map(get_address, identities) |
paul@418 | 294 | valid = self.senders.intersection(senders) |
paul@418 | 295 | |
paul@418 | 296 | # Return the true identities. |
paul@418 | 297 | |
paul@418 | 298 | return [identities[get_uri(address)] for address in valid] |
paul@418 | 299 | else: |
paul@418 | 300 | return mapping |
paul@418 | 301 | |
paul@418 | 302 | def filter_by_recipient(self, mapping): |
paul@418 | 303 | |
paul@418 | 304 | """ |
paul@418 | 305 | Return a list of items from 'mapping' filtered using recipient |
paul@418 | 306 | information. |
paul@418 | 307 | """ |
paul@418 | 308 | |
paul@418 | 309 | if self.recipient: |
paul@418 | 310 | addresses = set(map(get_address, mapping)) |
paul@418 | 311 | return map(get_uri, addresses.intersection([self.recipient])) |
paul@418 | 312 | else: |
paul@418 | 313 | return mapping |
paul@418 | 314 | |
paul@418 | 315 | def require_organiser(self, from_organiser=True): |
paul@418 | 316 | |
paul@418 | 317 | """ |
paul@418 | 318 | Return the organiser for the current object, filtered for the sender or |
paul@418 | 319 | recipient of interest. Return None if no identities are eligible. |
paul@418 | 320 | |
paul@418 | 321 | The organiser identity is normalized. |
paul@418 | 322 | """ |
paul@418 | 323 | |
paul@418 | 324 | organiser_item = uri_item(self.obj.get_item("ORGANIZER")) |
paul@418 | 325 | |
paul@418 | 326 | # Only provide details for an organiser who sent/receives the message. |
paul@418 | 327 | |
paul@418 | 328 | organiser_filter_fn = from_organiser and self.filter_by_senders or self.filter_by_recipient |
paul@418 | 329 | |
paul@418 | 330 | if not organiser_filter_fn(dict([organiser_item])): |
paul@418 | 331 | return None |
paul@418 | 332 | |
paul@418 | 333 | return organiser_item |
paul@418 | 334 | |
paul@418 | 335 | def require_attendees(self, from_organiser=True): |
paul@418 | 336 | |
paul@418 | 337 | """ |
paul@418 | 338 | Return the attendees for the current object, filtered for the sender or |
paul@418 | 339 | recipient of interest. Return None if no identities are eligible. |
paul@418 | 340 | |
paul@418 | 341 | The attendee identities are normalized. |
paul@418 | 342 | """ |
paul@418 | 343 | |
paul@418 | 344 | attendee_map = uri_dict(self.obj.get_value_map("ATTENDEE")) |
paul@418 | 345 | |
paul@418 | 346 | # Only provide details for attendees who sent/receive the message. |
paul@418 | 347 | |
paul@418 | 348 | attendee_filter_fn = from_organiser and self.filter_by_recipient or self.filter_by_senders |
paul@418 | 349 | |
paul@418 | 350 | attendees = {} |
paul@418 | 351 | for attendee in attendee_filter_fn(attendee_map): |
paul@418 | 352 | attendees[attendee] = attendee_map[attendee] |
paul@418 | 353 | |
paul@418 | 354 | return attendees |
paul@418 | 355 | |
paul@418 | 356 | def require_organiser_and_attendees(self, from_organiser=True): |
paul@418 | 357 | |
paul@418 | 358 | """ |
paul@418 | 359 | Return the organiser and attendees for the current object, filtered for |
paul@418 | 360 | the recipient of interest. Return None if no identities are eligible. |
paul@418 | 361 | |
paul@418 | 362 | Organiser and attendee identities are normalized. |
paul@418 | 363 | """ |
paul@418 | 364 | |
paul@418 | 365 | organiser_item = self.require_organiser(from_organiser) |
paul@418 | 366 | attendees = self.require_attendees(from_organiser) |
paul@418 | 367 | |
paul@418 | 368 | if not attendees or not organiser_item: |
paul@418 | 369 | return None |
paul@418 | 370 | |
paul@418 | 371 | return organiser_item, attendees |
paul@418 | 372 | |
paul@418 | 373 | def get_sender_identities(self, mapping): |
paul@418 | 374 | |
paul@418 | 375 | """ |
paul@418 | 376 | Return a mapping from actual senders to the identities for which they |
paul@418 | 377 | have provided data, extracting this information from the given |
paul@418 | 378 | 'mapping'. |
paul@418 | 379 | """ |
paul@418 | 380 | |
paul@418 | 381 | senders = {} |
paul@418 | 382 | |
paul@418 | 383 | for value, attr in mapping.items(): |
paul@418 | 384 | sent_by = attr.get("SENT-BY") |
paul@418 | 385 | if sent_by: |
paul@418 | 386 | senders[get_uri(sent_by)] = value |
paul@418 | 387 | else: |
paul@418 | 388 | senders[value] = value |
paul@418 | 389 | |
paul@418 | 390 | return senders |
paul@418 | 391 | |
paul@468 | 392 | def _get_object(self, uid, recurrenceid): |
paul@418 | 393 | |
paul@418 | 394 | """ |
paul@468 | 395 | Return the stored object for the current user, with the given 'uid' and |
paul@468 | 396 | 'recurrenceid'. |
paul@418 | 397 | """ |
paul@418 | 398 | |
paul@468 | 399 | fragment = self.store.get_event(self.user, uid, recurrenceid) |
paul@418 | 400 | return fragment and Object(fragment) |
paul@418 | 401 | |
paul@468 | 402 | def get_object(self): |
paul@418 | 403 | |
paul@418 | 404 | """ |
paul@418 | 405 | Return the stored object to which the current object refers for the |
paul@468 | 406 | current user. |
paul@418 | 407 | """ |
paul@418 | 408 | |
paul@468 | 409 | return self._get_object(self.uid, self.recurrenceid) |
paul@418 | 410 | |
paul@468 | 411 | def get_parent_object(self): |
paul@418 | 412 | |
paul@418 | 413 | """ |
paul@418 | 414 | Return the parent object to which the current object refers for the |
paul@468 | 415 | current user. |
paul@418 | 416 | """ |
paul@418 | 417 | |
paul@468 | 418 | return self.recurrenceid and self._get_object(self.uid, None) or None |
paul@418 | 419 | |
paul@468 | 420 | def have_new_object(self, obj=None): |
paul@418 | 421 | |
paul@418 | 422 | """ |
paul@468 | 423 | Return whether the current object is new to the current user (or if the |
paul@418 | 424 | given 'obj' is new). |
paul@418 | 425 | """ |
paul@418 | 426 | |
paul@468 | 427 | obj = obj or self.get_object() |
paul@418 | 428 | |
paul@418 | 429 | # If found, compare SEQUENCE and potentially DTSTAMP. |
paul@418 | 430 | |
paul@418 | 431 | if obj: |
paul@418 | 432 | sequence = obj.get_value("SEQUENCE") |
paul@418 | 433 | dtstamp = obj.get_value("DTSTAMP") |
paul@418 | 434 | |
paul@418 | 435 | # If the request refers to an older version of the object, ignore |
paul@418 | 436 | # it. |
paul@418 | 437 | |
paul@418 | 438 | return is_new_object(sequence, self.sequence, dtstamp, self.dtstamp, |
paul@418 | 439 | self.is_partstat_updated(obj)) |
paul@418 | 440 | |
paul@418 | 441 | return True |
paul@418 | 442 | |
paul@418 | 443 | def is_partstat_updated(self, obj): |
paul@418 | 444 | |
paul@418 | 445 | """ |
paul@418 | 446 | Return whether the participant status has been updated in the current |
paul@418 | 447 | object in comparison to the given 'obj'. |
paul@418 | 448 | |
paul@418 | 449 | NOTE: Some clients like Claws Mail erase time information from DTSTAMP |
paul@418 | 450 | NOTE: and make it invalid. Thus, such attendance information may also be |
paul@418 | 451 | NOTE: incorporated into any new object assessment. |
paul@418 | 452 | """ |
paul@418 | 453 | |
paul@418 | 454 | old_attendees = uri_dict(obj.get_value_map("ATTENDEE")) |
paul@418 | 455 | new_attendees = uri_dict(self.obj.get_value_map("ATTENDEE")) |
paul@418 | 456 | |
paul@418 | 457 | for attendee, attr in old_attendees.items(): |
paul@418 | 458 | old_partstat = attr.get("PARTSTAT") |
paul@418 | 459 | new_attr = new_attendees.get(attendee) |
paul@418 | 460 | new_partstat = new_attr and new_attr.get("PARTSTAT") |
paul@418 | 461 | |
paul@418 | 462 | if old_partstat == "NEEDS-ACTION" and new_partstat and \ |
paul@418 | 463 | new_partstat != old_partstat: |
paul@418 | 464 | |
paul@418 | 465 | return True |
paul@418 | 466 | |
paul@418 | 467 | return False |
paul@418 | 468 | |
paul@468 | 469 | def merge_attendance(self, attendees): |
paul@418 | 470 | |
paul@418 | 471 | """ |
paul@418 | 472 | Merge attendance from the current object's 'attendees' into the version |
paul@468 | 473 | stored for the current user. |
paul@418 | 474 | """ |
paul@418 | 475 | |
paul@468 | 476 | obj = self.get_object() |
paul@418 | 477 | |
paul@468 | 478 | if not obj or not self.have_new_object(obj): |
paul@418 | 479 | return False |
paul@418 | 480 | |
paul@418 | 481 | # Get attendee details in a usable form. |
paul@418 | 482 | |
paul@418 | 483 | attendee_map = uri_dict(obj.get_value_map("ATTENDEE")) |
paul@418 | 484 | |
paul@418 | 485 | for attendee, attendee_attr in attendees.items(): |
paul@418 | 486 | |
paul@418 | 487 | # Update attendance in the loaded object. |
paul@418 | 488 | |
paul@418 | 489 | attendee_map[attendee] = attendee_attr |
paul@418 | 490 | |
paul@418 | 491 | # Set the new details and store the object. |
paul@418 | 492 | |
paul@418 | 493 | obj["ATTENDEE"] = attendee_map.items() |
paul@418 | 494 | |
paul@418 | 495 | # Set the complete event if not an additional occurrence. |
paul@418 | 496 | |
paul@418 | 497 | event = obj.to_node() |
paul@468 | 498 | self.store.set_event(self.user, self.uid, self.recurrenceid, event) |
paul@418 | 499 | |
paul@418 | 500 | return True |
paul@418 | 501 | |
paul@418 | 502 | def update_dtstamp(self): |
paul@418 | 503 | |
paul@418 | 504 | "Update the DTSTAMP in the current object." |
paul@418 | 505 | |
paul@418 | 506 | dtstamp = self.obj.get_utc_datetime("DTSTAMP") |
paul@418 | 507 | utcnow = to_timezone(datetime.utcnow(), "UTC") |
paul@418 | 508 | self.obj["DTSTAMP"] = [(format_datetime(dtstamp > utcnow and dtstamp or utcnow), {})] |
paul@418 | 509 | |
paul@418 | 510 | def set_sequence(self, increment=False): |
paul@418 | 511 | |
paul@418 | 512 | "Update the SEQUENCE in the current object." |
paul@418 | 513 | |
paul@418 | 514 | sequence = self.obj.get_value("SEQUENCE") or "0" |
paul@418 | 515 | self.obj["SEQUENCE"] = [(str(int(sequence) + (increment and 1 or 0)), {})] |
paul@418 | 516 | |
paul@418 | 517 | # vim: tabstop=4 expandtab shiftwidth=4 |