def getComponentFilters(self,component,event=None,dateTime=None):
<EOL>if component.staffMember:<EOL><INDENT>filters = Q(pk=component.staffMember.pk)<EOL><DEDENT>else:<EOL><INDENT>filters = Q(eventstaffmember__category=component.staffCategory)<EOL><DEDENT>if component.admissionRule == '<STR_LIT>' and event:<EOL><INDENT>return Q(filters & Q(eventstaffmember__event=event))<EOL><DEDENT>elif component.admissionRule in ['<STR_LIT>','<STR_LIT>']:<EOL><INDENT>return Q(filters)<EOL><DEDENT>if event:<EOL><INDENT>intervals = [(x.startTime,x.endTime) for x in event.eventoccurrence_set.all()]<EOL><DEDENT>elif dateTime:<EOL><INDENT>intervals = [(dateTime,dateTime)]<EOL><DEDENT>else:<EOL><INDENT>raise ValueError(_('<STR_LIT>'))<EOL><DEDENT>if component.admissionRule == '<STR_LIT>':<EOL><INDENT>intervals = [<EOL>(self.getDayStart(x[<NUM_LIT:0>]),self.getDayStart(x[<NUM_LIT:1>]) + timedelta(days=<NUM_LIT:1>)) for x in intervals<EOL>]<EOL><DEDENT>elif component.admissionRule == '<STR_LIT>':<EOL><INDENT>intervals = [<EOL>(<EOL>self.getDayStart(x[<NUM_LIT:0>]) - timedelta(days=x[<NUM_LIT:0>].weekday()),<EOL>self.getDayStart(x[<NUM_LIT:1>]) - timedelta(days=x[<NUM_LIT:1>].weekday() - <NUM_LIT:7>)<EOL>) for x in intervals<EOL>]<EOL><DEDENT>elif component.admissionRule == '<STR_LIT>':<EOL><INDENT>intervals = [<EOL>(<EOL>self.getDayStart(x[<NUM_LIT:0>]).replace(day=<NUM_LIT:1>),<EOL>self.getDayStart(x[<NUM_LIT:1>]).replace(day=<NUM_LIT:1>) + relativedelta(months=<NUM_LIT:1>)<EOL>) for x in intervals<EOL>]<EOL><DEDENT>elif component.admissionRule == '<STR_LIT>':<EOL><INDENT>intervals = [<EOL>(<EOL>self.getDayStart(x[<NUM_LIT:0>]).replace(month=<NUM_LIT:1>,day=<NUM_LIT:1>),<EOL>self.getDayStart(x[<NUM_LIT:1>]).replace(year=x[<NUM_LIT:1>].year + <NUM_LIT:1>,month=<NUM_LIT:1>,day=<NUM_LIT:1>)<EOL>) for x in intervals<EOL>]<EOL><DEDENT>else:<EOL><INDENT>return Q(pk__isnull=True)<EOL><DEDENT>intervals = [sorted(x) for x in intervals]<EOL>tree = IntervalTree.from_tuples(intervals)<EOL>tree.merge_overlaps()<EOL>intervalFilters = Q(pk__isnull=True)<EOL>for item in tree.items():<EOL><INDENT>intervalFilters = intervalFilters | Q(<EOL>Q(eventstaffmember__event__eventoccurrence__endTime__gte=item[<NUM_LIT:0>]) &<EOL>Q(eventstaffmember__event__eventoccurrence__startTime__lte=item[<NUM_LIT:1>])<EOL>)<EOL><DEDENT>return Q(filters & intervalFilters)<EOL>
Get a parsimonious set of intervals and the associated Q() objects
based on the occurrences of a specified event, and the rule that
implicitly defines the start and end of each interval.