Project

General

Profile

« Previous | Next » 

Revision ad9330e1

Added by Jérôme Schneider over 12 years ago

agenda: add display for service activity

View differences:

calebasse/agenda/views.py
4 4
from django.shortcuts import redirect
5 5

  
6 6
from calebasse.cbv import TemplateView, CreateView
7
from calebasse.agenda.models import Occurrence
7
from calebasse.agenda.models import Occurrence, Event, EventType
8 8
from calebasse.personnes.models import TimeTable
9
from calebasse.actes.models import EventAct, Event
9
from calebasse.actes.models import EventAct
10 10
from calebasse.agenda.appointments import get_daily_appointments
11 11
from calebasse.personnes.models import Worker
12 12
from calebasse.ressources.models import Service, WorkerType
......
65 65
                occurrences_workers, workers)
66 66
        return context
67 67

  
68
class AgendaServiceActivityView(TemplateView):
69

  
70
    template_name = 'agenda/service-activity.html'
71

  
72
    def get_context_data(self, **kwargs):
73
        context = super(AgendaServiceActivityView, self).get_context_data(**kwargs)
74

  
75
        appointments_times = dict()
76
        appoinment_type = EventType.objects.get(id=1)
77
        occurrences = Occurrence.objects.daily_occurrences(context['date'],
78
                services=[self.service],
79
                event_type=appoinment_type).order_by('start_time')
80
        for occurrence in occurrences:
81
            start_time = occurrence.start_time.strftime("%H:%M")
82
            if not appointments_times.has_key(start_time):
83
                appointments_times[start_time] = dict()
84
                appointments_times[start_time]['row'] = 0
85
                appointments_times[start_time]['appointments'] = []
86
            appointment = dict()
87
            length = occurrence.end_time - occurrence.start_time
88
            if length.seconds:
89
                length = length.seconds / 60
90
                appointment['length'] = "%sm" % length
91
            event_act = occurrence.event.eventact
92
            appointment['patient'] = event_act.patient
93
            appointment['therapists'] = ""
94
            for participant in occurrence.event.participants.all():
95
                appointment['therapists'] += str(participant) + "; "
96
            if appointment['therapists']:
97
                appointment['therapists'] = appointment['therapists'][:-2]
98
            appointment['act'] = event_act.act_type.name
99
            appointments_times[start_time]['row'] += 1
100
            appointments_times[start_time]['appointments'].append(appointment)
101
        context['appointments_times'] = appointments_times
102
        print context['appointments_times']
103
        return context
104

  
105

  
68 106
class NewAppointmentView(CreateView):
69 107
    model = EventAct
70 108
    form_class = NewAppointmentForm

Also available in: Unified diff