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