Project

General

Profile

« Previous | Next » 

Revision 3a38fa86

Added by Serghei Mihai almost 10 years ago

ressource disponibility view refactored

View differences:

calebasse/agenda/templates/agenda/ajax-disponibility-column.html
1
<li class='{{ ressource_type }}-{{ ressource_id }}'>
2
<ul>
3
  <li class="initials" data-id="{{ ressource_id }}">
4
    {{ initials }}
5
  </li>
6
  {% for start_time, quarters in disponibility.items %}
7
  <li class="hour-mark">
8
    <ul>
9
      {% for quarter in quarters %}
10
      {% for min, value in quarter %}
11
      <li class="ressource-{{ value.id }} agenda {{ value.dispo }}" data-id="{{ value.id }}" title="{{ start_time|stringformat:"02d" }}:{{ min|stringformat:"02d" }}"></li>
12
      {% endfor %}
13

  
14
      {% endfor %}
15
    </ul>
16
  </li>
17
  {% endfor %}
18
</ul>
19
</li>
calebasse/agenda/templates/agenda/ajax-ressource-disponibility-column.html
1
<li class='{{ type }}-{{ ressource_id }}'>
2
<ul>
3
  <li class="initials" data-id="{{ ressource_id }}">
4
    {{ initials }}
5
  </li>
6
  {% for start_time, quarters in disponibility.items %}
7
  <li class="hour-mark">
8
    <ul>
9
      {% for quarter in quarters %}
10
      {% for min, value in quarter %}
11
      <li class="ressource-{{ value.id }} agenda {{ value.dispo }}" data-id="{{ value.id }}" title="{{ start_time|stringformat:"02d" }}:{{ min|stringformat:"02d" }}"></li>
12
      {% endfor %}
13

  
14
      {% endfor %}
15
    </ul>
16
  </li>
17
  {% endfor %}
18
</ul>
19
</li>
calebasse/agenda/urls.py
9 9
        NewEventView, AgendaServiceActivityView, UpdateAppointmentView,
10 10
        UpdateEventView, AgendaServiceActValidationView, AutomatedValidationView,
11 11
        UnlockAllView, AgendasTherapeutesView, JoursNonVerrouillesView,
12
        AjaxWorkerTabView, AjaxRessourceTabView, AjaxWorkerDisponibilityColumnView,
12
        AjaxWorkerTabView, AjaxRessourceTabView, AjaxDisponibilityColumnView,
13 13
        DeleteOccurrenceView, DeleteEventView, UpdatePeriodicEventView,
14
        UpdatePeriodicAppointmentView, PeriodicEventsView,
15
        AjaxRessourceDisponibilityColumnView)
14
        UpdatePeriodicAppointmentView, PeriodicEventsView)
16 15

  
17 16
agenda_patterns = patterns('',
18 17
            url(r'^$',
......
71 70
            url(r'^ajax-ressource-tab/(?P<ressource_id>\d+)$',
72 71
                AjaxRessourceTabView.as_view(),
73 72
                name='ajax-ressource-tab'),
74
            url(r'^disponibility/worker-(?P<worker_id>\d+)$',
75
                AjaxWorkerDisponibilityColumnView.as_view(),
76
                name='ajax-worker-disponibility-column'),
77
            url(r'^disponibility/ressource-(?P<ressource_id>\d+)$',
78
                AjaxRessourceDisponibilityColumnView.as_view(),
79
                name='ajax-ressource-disponibility-column'),
73
            url(r'^disponibility/(?P<ressource_type>\w+)-(?P<ressource_id>\d+)$',
74
                AjaxDisponibilityColumnView.as_view(),
75
                name='ajax-disponibility-column'),
80 76
            url(r'^rendez-vous-periodiques/$',
81 77
                PeriodicEventsView.as_view(),
82 78
                name='periodic-events'),
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