paul@108 | 1 | #!/usr/bin/env python |
paul@108 | 2 | |
paul@108 | 3 | """ |
paul@108 | 4 | Common handler functionality for different entities. |
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@108 | 20 | """ |
paul@108 | 21 | |
paul@222 | 22 | from imiptools.data import get_address, make_freebusy, to_part |
paul@108 | 23 | |
paul@222 | 24 | class CommonFreebusy: |
paul@108 | 25 | |
paul@222 | 26 | "Common free/busy mix-in." |
paul@181 | 27 | |
paul@222 | 28 | def request(self): |
paul@181 | 29 | |
paul@181 | 30 | """ |
paul@222 | 31 | Respond to a request by preparing a reply containing free/busy |
paul@222 | 32 | information for each indicated attendee. |
paul@181 | 33 | """ |
paul@181 | 34 | |
paul@108 | 35 | oa = self.require_organiser_and_attendees() |
paul@108 | 36 | if not oa: |
paul@108 | 37 | return None |
paul@108 | 38 | |
paul@181 | 39 | (organiser, organiser_attr), attendees = oa |
paul@108 | 40 | |
paul@181 | 41 | # Get the details for each attendee. |
paul@108 | 42 | |
paul@222 | 43 | responses = [] |
paul@222 | 44 | rwrite = responses.append |
paul@222 | 45 | |
paul@222 | 46 | # For replies, the organiser and attendee are preserved. |
paul@108 | 47 | |
paul@181 | 48 | for attendee, attendee_attr in attendees.items(): |
paul@222 | 49 | freebusy = self.store.get_freebusy(attendee) |
paul@222 | 50 | rwrite(make_freebusy(freebusy, self.uid, organiser, attendee)) |
paul@183 | 51 | |
paul@183 | 52 | # Return the reply. |
paul@183 | 53 | |
paul@222 | 54 | return [([get_address(organiser)], to_part("REPLY", responses))] |
paul@183 | 55 | |
paul@108 | 56 | # vim: tabstop=4 expandtab shiftwidth=4 |