Projet

Général

Profil

« Précédent | Suivant » 

Révision 7d4712a3

Ajouté par Serghei Mihai (congés, retour 15/05) il y a presque 10 ans

agenda: crossing schedules marked in availability bars

Closes #4143

Voir les différences:

calebasse/agenda/managers.py
49 49
        occurences = ( e.today_occurrence(today) for e in self )
50 50
        return sorted(occurences, key=lambda e: e.start_datetime)
51 51

  
52
    def daily_disponibilities(self, date, events, participants, time_tables,
52
    def daily_disponibilities(self, date, events, participant, time_tables,
53 53
            holidays):
54 54
        '''Slice the day into quarters between 8:00 and 19:00, and returns the
55 55
           list of particpants with their status amon free, busy and away for each
......
63 63
        '''
64 64
        result = dict()
65 65
        quarter = 0
66
        events_set = {}
67
        timetables_set = {}
68
        holidays_set = {}
69
        for participant in participants:
70
            events_set[participant.id] = IntervalSet((o.to_interval() for o in events[participant.id] if not o.is_event_absence()))
71
            timetables_set[participant.id] = IntervalSet((t.to_interval(date) for t in time_tables[participant.id]))
72
            holidays_set[participant.id] = IntervalSet((h.to_interval(date) for h in holidays[participant.id]))
66

  
67
        events_intervals = IntervalSet((o.to_interval() for o in events if not o.is_event_absence()))
68

  
69
        timetables_intervals = IntervalSet((t.to_interval(date) for t in time_tables))
70
        holidays_intervals = IntervalSet((h.to_interval(date) for h in holidays))
71

  
73 72
        start_datetime = datetime(date.year, date.month, date.day, 8, 0)
74 73
        end_datetime = datetime(date.year, date.month, date.day, 8, 15)
75 74
        while (start_datetime.hour <= 19):
76
            for participant in participants:
77
                if not result.has_key(start_datetime.hour):
78
                    result[start_datetime.hour] = [[], [], [], []]
79
                    quarter = 0
80
                interval = IntervalSet.between(start_datetime, end_datetime, False)
81
                mins = quarter * 15
82
                if interval.intersection(events_set[participant.id]):
83
                    result[start_datetime.hour][quarter].append((mins, {'id': participant.id, 'dispo': 'busy'}))
84
                elif interval.intersection(holidays_set[participant.id]):
85
                    result[start_datetime.hour][quarter].append((mins, {'id': participant.id, 'dispo': 'busy'}))
86
                elif not interval.intersection(timetables_set[participant.id]):
87
                    result[start_datetime.hour][quarter].append((mins, {'id': participant.id, 'dispo': 'away'}))
88
                else:
89
                    result[start_datetime.hour][quarter].append((mins, {'id': participant.id, 'dispo': 'free'}))
75

  
76
            if not result.has_key(start_datetime.hour):
77
                result[start_datetime.hour] = [[], [], [], []]
78
                quarter = 0
79
            interval = IntervalSet.between(start_datetime, end_datetime, False)
80
            mins = quarter * 15
81
            crossed_events = filter(lambda e: e.start_datetime <= start_datetime and e.end_datetime >= end_datetime, events)
82
            if len(crossed_events) > 1:
83
                result[start_datetime.hour][quarter].append((mins, {'id': participant.id, 'dispo': 'common'}))
84
            elif interval.intersection(events_intervals):
85
                result[start_datetime.hour][quarter].append((mins, {'id': participant.id, 'dispo': 'busy'}))
86
            elif interval.intersection(holidays_intervals):
87
                result[start_datetime.hour][quarter].append((mins, {'id': participant.id, 'dispo': 'busy'}))
88
            elif not interval.intersection(timetables_intervals):
89
                result[start_datetime.hour][quarter].append((mins, {'id': participant.id, 'dispo': 'away'}))
90
            else:
91
                result[start_datetime.hour][quarter].append((mins, {'id': participant.id, 'dispo': 'free'}))
90 92
            quarter += 1
91 93
            start_datetime += timedelta(minutes=15)
92 94
            end_datetime += timedelta(minutes=15)
calebasse/agenda/views.py
632 632
                for event in events:
633 633
                    if event.start_datetime <= start_datetime and event.end_datetime >= end_datetime:
634 634
                        dispo = 'busy'
635

  
635
                        crossed_events = filter(lambda e: e.start_datetime <= start_datetime and e.end_datetime >= end_datetime, events)
636
                        if len(crossed_events) > 1:
637
                            dispo = 'common'
636 638
                disponibility[start_datetime.hour][quarter].append((mins, {'id': ressource_id, 'dispo': dispo}))
637 639
            quarter += 1
638 640
            start_datetime += datetime.timedelta(minutes=15)
......
645 647
    def get_worker_context_data(self, worker_id, context):
646 648
        worker = Worker.objects.get(pk=worker_id)
647 649

  
648
        time_tables_worker = TimeTable.objects.select_related('worker'). \
650
        time_tables = TimeTable.objects.select_related('worker'). \
649 651
                filter(services=self.service, worker=worker). \
650 652
                for_today(self.date). \
651 653
                order_by('start_date')
652
        holidays_worker = Holiday.objects.for_worker(worker). \
654
        holidays = Holiday.objects.for_worker(worker). \
653 655
                for_period(self.date, self.date). \
654 656
                order_by('start_date')
655 657
        events = Event.objects.for_today(self.date) \
......
667 669

  
668 670
        events = list(events) + list(eventswithact)
669 671
        events = [ e.today_occurrence(self.date) for e in events ]
670
        time_tables_workers = {worker.id: time_tables_worker}
672
        time_tables_workers = {worker.id: time_tables}
671 673
        events_workers = {worker.id: events}
672
        holidays_workers = {worker.id: holidays_worker}
674
        holidays_workers = {worker.id: holidays}
673 675

  
674 676
        context['initials'] = worker.initials
675 677
        context['disponibility'] = Event.objects.daily_disponibilities(self.date,
676
                events_workers, [worker], time_tables_workers, holidays_workers)
678
                events, worker, time_tables, holidays)
677 679
        return context
678 680

  
679 681
    def get_context_data(self, ressource_type, ressource_id, **kwargs):
calebasse/static/css/agenda.css
178 178
    background: #ccc;
179 179
}
180 180

  
181
li.common {
182
    background: #d500a5;
183
}
184

  
181 185
li#time {
182 186
    margin-top: -0.15em;
183 187
}

Formats disponibles : Unified diff