1.1 --- a/imiptools/handlers/scheduling/common.py Fri May 13 15:41:38 2016 +0200
1.2 +++ b/imiptools/handlers/scheduling/common.py Fri May 13 16:20:29 2016 +0200
1.3 @@ -37,4 +37,35 @@
1.4 else:
1.5 return response, _("The recipient is unavailable in the requested period.")
1.6
1.7 +def get_scheduling_conflicts(handler, freebusy, users, attendee=False):
1.8 +
1.9 + """
1.10 + Use the 'handler' to obtain scheduling conflicts within the given 'freebusy'
1.11 + collection involving the given 'users', with the organiser of each period
1.12 + being tested against the users unless 'attendee' is set to a true value
1.13 + (thus testing the attendee of each period against the users instead).
1.14 +
1.15 + Return a dictionary mapping users to the number of conflicts (or concurrent
1.16 + scheduling instances) each user experiences for the current object of the
1.17 + 'handler'.
1.18 + """
1.19 +
1.20 + conflicts = {}
1.21 +
1.22 + for user in users:
1.23 + conflicts[user] = 0
1.24 +
1.25 + for period in handler.get_periods(handler.obj):
1.26 + overlapping = freebusy.get_overlapping(period)
1.27 +
1.28 + # Where scheduling cannot occur, find the busy potential users.
1.29 +
1.30 + if overlapping:
1.31 + for p in overlapping:
1.32 + involved = attendee and p.attendee or p.organiser
1.33 + if conflicts.has_key(involved):
1.34 + conflicts[involved] += 1
1.35 +
1.36 + return conflicts
1.37 +
1.38 # vim: tabstop=4 expandtab shiftwidth=4