paul@1182 | 1 | #!/usr/bin/env python |
paul@1182 | 2 | |
paul@1182 | 3 | """ |
paul@1182 | 4 | Common scheduling functionality. |
paul@1182 | 5 | |
paul@1182 | 6 | Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> |
paul@1182 | 7 | |
paul@1182 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@1182 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@1182 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@1182 | 11 | version. |
paul@1182 | 12 | |
paul@1182 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@1182 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@1182 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@1182 | 16 | details. |
paul@1182 | 17 | |
paul@1182 | 18 | You should have received a copy of the GNU General Public License along with |
paul@1182 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@1182 | 20 | """ |
paul@1182 | 21 | |
paul@1182 | 22 | def standard_responses(handler, response): |
paul@1182 | 23 | |
paul@1182 | 24 | """ |
paul@1182 | 25 | Using 'handler' to translate descriptions, return a tuple containing the |
paul@1182 | 26 | 'response' and a suitable description. |
paul@1182 | 27 | """ |
paul@1182 | 28 | |
paul@1182 | 29 | _ = handler.get_translator() |
paul@1182 | 30 | |
paul@1182 | 31 | if response == "ACCEPTED": |
paul@1182 | 32 | return response, _("The recipient has scheduled the requested period.") |
paul@1182 | 33 | elif response == "COUNTER": |
paul@1182 | 34 | return response, _("The recipient has suggested a different period.") |
paul@1182 | 35 | elif response == "DELEGATED": |
paul@1182 | 36 | return response, _("The recipient has delegated the requested period.") |
paul@1182 | 37 | else: |
paul@1182 | 38 | return response, _("The recipient is unavailable in the requested period.") |
paul@1182 | 39 | |
paul@1183 | 40 | def get_scheduling_conflicts(handler, freebusy, users, attendee=False): |
paul@1183 | 41 | |
paul@1183 | 42 | """ |
paul@1183 | 43 | Use the 'handler' to obtain scheduling conflicts within the given 'freebusy' |
paul@1183 | 44 | collection involving the given 'users', with the organiser of each period |
paul@1183 | 45 | being tested against the users unless 'attendee' is set to a true value |
paul@1183 | 46 | (thus testing the attendee of each period against the users instead). |
paul@1183 | 47 | |
paul@1183 | 48 | Return a dictionary mapping users to the number of conflicts (or concurrent |
paul@1183 | 49 | scheduling instances) each user experiences for the current object of the |
paul@1183 | 50 | 'handler'. |
paul@1183 | 51 | """ |
paul@1183 | 52 | |
paul@1183 | 53 | conflicts = {} |
paul@1183 | 54 | |
paul@1183 | 55 | for user in users: |
paul@1183 | 56 | conflicts[user] = 0 |
paul@1183 | 57 | |
paul@1189 | 58 | overlapping = freebusy.get_overlapping(handler.get_periods(handler.obj)) |
paul@1183 | 59 | |
paul@1189 | 60 | # Where scheduling cannot occur, find the busy potential users. |
paul@1183 | 61 | |
paul@1189 | 62 | if overlapping: |
paul@1189 | 63 | for p in overlapping: |
paul@1189 | 64 | involved = attendee and p.attendee or p.organiser |
paul@1189 | 65 | if conflicts.has_key(involved): |
paul@1189 | 66 | conflicts[involved] += 1 |
paul@1183 | 67 | |
paul@1183 | 68 | return conflicts |
paul@1183 | 69 | |
paul@1182 | 70 | # vim: tabstop=4 expandtab shiftwidth=4 |