Project

General

Profile

« Previous | Next » 

Revision 3a38fa86

Added by Serghei Mihai almost 10 years ago

ressource disponibility view refactored

View differences:

calebasse/agenda/views.py
601 601
        }
602 602
        return context
603 603

  
604
class AjaxWorkerDisponibilityColumnView(TemplateView):
604
class AjaxDisponibilityColumnView(TemplateView):
605 605

  
606
    template_name = 'agenda/ajax-ressource-disponibility-column.html'
606
    template_name = 'agenda/ajax-disponibility-column.html'
607 607
    cookies_to_clear = []
608 608

  
609
    def get_context_data(self, worker_id, **kwargs):
610
        context = super(AjaxWorkerDisponibilityColumnView, self).get_context_data(**kwargs)
609
    def get_ressource_context_data(self, ressource_id, context):
610
        ressource = Room.objects.get(pk = ressource_id)
611
        context['initials'] = ressource.name[:3]
612
        disponibility = dict()
613
        start_datetime = datetime.datetime(self.date.year,
614
                                           self.date.month,
615
                                           self.date.day, 8, 0)
616
        end_datetime = datetime.datetime(self.date.year, self.date.month,
617
                                         self.date.day, 8, 15)
618
        events = Event.objects.filter(room__id=ressource_id).today_occurrences(self.date)
619

  
620
        while (start_datetime.hour <= 19):
621
            if start_datetime.hour not in disponibility:
622
                disponibility[start_datetime.hour] = [[], [], [], []]
623
                quarter = 0
624
            dispo = 'free'
625
            mins = quarter * 15
626

  
627
            if events:
628
                event = events[0]
629

  
630
                if event.start_datetime <= start_datetime and event.end_datetime >= end_datetime:
631
                    dispo = 'busy'
632
            disponibility[start_datetime.hour][quarter].append((mins, {'id': ressource_id, 'dispo': dispo}))
633
            quarter += 1
634
            start_datetime += datetime.timedelta(minutes=15)
635
            end_datetime += datetime.timedelta(minutes=15)
636
        context['disponibility'] = disponibility
637
        return context
638

  
639

  
640
    def get_worker_context_data(self, worker_id, context):
611 641
        worker = Worker.objects.get(pk=worker_id)
612 642

  
613 643
        time_tables_worker = TimeTable.objects.select_related('worker'). \
......
637 667
        holidays_workers = {worker.id: holidays_worker}
638 668

  
639 669
        context['initials'] = worker.initials
640
        context['type'] = 'worker'
641
        context['ressource_id'] = worker.id
642 670
        context['disponibility'] = Event.objects.daily_disponibilities(self.date,
643 671
                events_workers, [worker], time_tables_workers, holidays_workers)
644 672
        return context
645 673

  
646
class AjaxRessourceDisponibilityColumnView(AjaxWorkerDisponibilityColumnView):
647

  
648
    def get_context_data(self, ressource_id, **kwargs):
649
        context = {}
650
        ressource = Room.objects.get(pk = ressource_id)
651
        context = {'initials': ressource.name[:3], 'ressource_id': ressource.id, 'type': 'ressource'}
652
        disponibility = dict()
653
        start_datetime = datetime.datetime(self.date.year,
654
                                           self.date.month,
655
                                           self.date.day, 8, 0)
656
        end_datetime = datetime.datetime(self.date.year, self.date.month,
657
                                         self.date.day, 8, 15)
658
        events = Event.objects.filter(room__id=ressource_id).today_occurrences(self.date)
659

  
660
        while (start_datetime.hour <= 19):
661
            if start_datetime.hour not in disponibility:
662
                disponibility[start_datetime.hour] = [[], [], [], []]
663
                quarter = 0
664
            dispo = 'free'
665
            mins = quarter * 15
666

  
667
            if events:
668
                event = events[0]
669

  
670
                if event.start_datetime <= start_datetime and event.end_datetime >= end_datetime:
671
                    dispo = 'busy'
672

  
673
            disponibility[start_datetime.hour][quarter].append((mins, {'id': ressource_id, 'dispo': dispo}))
674
            quarter += 1
675
            start_datetime += datetime.timedelta(minutes=15)
676
            end_datetime += datetime.timedelta(minutes=15)
677
        context['disponibility'] = disponibility
674
    def get_context_data(self, ressource_type, ressource_id, **kwargs):
675
        context = super(AjaxDisponibilityColumnView, self).get_context_data(**kwargs)
676
        if ressource_type in ('worker', 'ressource',):
677
            context['ressource_type'] = ressource_type
678
            context['ressource_id'] = ressource_id
679
            getattr(self, 'get_%s_context_data' % ressource_type)(ressource_id, context)
678 680
        return context
679 681

  
680

  
681 682
class PeriodicEventsView(cbv.ListView):
682 683
    model = EventWithAct
683 684
    template_name = 'agenda/periodic-events.html'

Also available in: Unified diff