paul@441 | 1 | #!/usr/bin/env python |
paul@441 | 2 | |
paul@441 | 3 | """ |
paul@441 | 4 | Common calendar client utilities. |
paul@441 | 5 | |
paul@441 | 6 | Copyright (C) 2014, 2015 Paul Boddie <paul@boddie.org.uk> |
paul@441 | 7 | |
paul@441 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@441 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@441 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@441 | 11 | version. |
paul@441 | 12 | |
paul@441 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@441 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@441 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@441 | 16 | details. |
paul@441 | 17 | |
paul@441 | 18 | You should have received a copy of the GNU General Public License along with |
paul@441 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@441 | 20 | """ |
paul@441 | 21 | |
paul@441 | 22 | from imiptools.data import uri_items |
paul@441 | 23 | |
paul@441 | 24 | def update_attendees(obj, added, removed): |
paul@441 | 25 | |
paul@441 | 26 | """ |
paul@441 | 27 | Update the attendees in 'obj' with the given 'added' and 'removed' |
paul@441 | 28 | attendee lists. A list is returned containing the attendees whose |
paul@441 | 29 | attendance should be cancelled. |
paul@441 | 30 | """ |
paul@441 | 31 | |
paul@441 | 32 | to_cancel = [] |
paul@441 | 33 | |
paul@441 | 34 | if added or removed: |
paul@441 | 35 | attendees = uri_items(obj.get_items("ATTENDEE") or []) |
paul@441 | 36 | |
paul@441 | 37 | if removed: |
paul@441 | 38 | remaining = [] |
paul@441 | 39 | |
paul@441 | 40 | for attendee, attendee_attr in attendees: |
paul@441 | 41 | if attendee in removed: |
paul@441 | 42 | if attendee_attr.get("PARTSTAT") in ("ACCEPTED", "TENTATIVE"): |
paul@441 | 43 | to_cancel.append((attendee, attendee_attr)) |
paul@441 | 44 | else: |
paul@441 | 45 | remaining.append((attendee, attendee_attr)) |
paul@441 | 46 | |
paul@441 | 47 | attendees = remaining |
paul@441 | 48 | |
paul@441 | 49 | if added: |
paul@441 | 50 | for attendee in added: |
paul@441 | 51 | attendees.append((attendee, {"PARTSTAT" : "NEEDS-ACTION", "RSVP" : "TRUE"})) |
paul@441 | 52 | |
paul@441 | 53 | obj["ATTENDEE"] = attendees |
paul@441 | 54 | |
paul@441 | 55 | return to_cancel |
paul@441 | 56 | |
paul@441 | 57 | # vim: tabstop=4 expandtab shiftwidth=4 |