Project

General

Profile

« Previous | Next » 

Revision 0a82dcb8

Added by Benjamin Dauvergne over 12 years ago

add a new appointment form

View differences:

calebasse/agenda/forms.py
1
# -*- coding: utf-8 -*-
2

  
3
from datetime import datetime, timedelta
4

  
5
from django import forms
6

  
7
from calebasse.dossiers.models import PatientRecord
8
from calebasse.personnes.models import Worker
9
from calebasse.actes.models import EventAct
10

  
11
class NewAppointmentForm(forms.ModelForm):
12
    time = forms.TimeField(label=u'Heure de début')
13
    DURATION_CHOICES = (
14
            (45, '45 minutes'),
15
    )
16
    duration = forms.TypedChoiceField(choices=DURATION_CHOICES,
17
            coerce=int, label=u'Durée')
18

  
19
    class Meta:
20
        model = EventAct
21
        fields = (
22
                'date',
23
                'time',
24
                'duration',
25
                'patient',
26
                'participants',
27
                'room',
28
                'act_type',
29
        )
30

  
31

  
32
    def __init__(self, service=None):
33
        self.service = None
34
        super(NewAppointmentForm, self).__init__()
35
        if service:
36
            self.service = service
37
            self.fields['participants'].queryset = \
38
                    Worker.objects.for_service(service)
39
            self.fields['patient'].queryset = \
40
                    PatientRecord.objects.for_service(service)
41

  
42
    def save(self, commit=False):
43
        start_datetime = datetime.combine(self.cleaned_data['date'],
44
                    self.cleaned_data['time'])
45
        end_datetime = start_datetime + timedelta(
46
                minutes=self.cleaned_data['duration'])
47
        self.instance = EventAct.objects.create_patient_appointment(
48
                title='title #FIXME#',
49
                patient=self.cleaned_data['patient'],
50
                participants=self.cleaned_data['participants'],
51
                act_type=self.cleaned_data['act_type'],
52
                service=self.service,
53
                start_datetime=start_datetime,
54
                end_datetime=end_datetime,
55
                description='description #FIXME#',
56
                room=self.cleaned_data['room'],
57
                note=None,)
58
        return self.instance
59

  
calebasse/agenda/templates/agenda/index.html
1 1
{% extends "calebasse/base.html" %}
2
{% load url from future %}
2 3
{% block extrascripts %}
3 4
    <script>
4 5
  $(function() {
......
48 49
				  buttons: [ { text: "Fermer",
49 50
					       click: function() { $(this).dialog("close"); } },
50 51
					     { text: "Ajouter",
51
					       click: function() { $(this).dialog("close"); } }]}
52
					       click: function() { $("#rdv form").submit(); } }]}
52 53
			);
53 54
			});
54 55
	});
......
240 241

  
241 242
{% block dialogs %}
242 243
  <div id="rdv" style="display: none;">
243
   <form>
244
    <form method="post" action="{% url "nouveau-rdv" service=service date=date %}">
245
     {% with new_appointment_form as form %}
244 246
   <table><tr><td>
245 247
   <p>
246
   <label for="id_date">Date:</label>
247
   <input id="id_date" class="date" name="date" value="5/7/2012"/>
248

  
249
   {{ form.date.label_tag }}
250
   {{ form.date }}
248 251
   </p>
249 252
   </td><td>
250 253
   <p>
251
    <label for="id_debut">Heure de début :</label>
252
    <input id="id_debut" type="text" name="debut" maxlength="10"/>
254
   {{ form.time.label_tag }}
255
   {{ form.time }}
253 256
   </p>
254 257
   </td><td>
255 258
   <p>
256
    <label for="id_duree">Durée :</label>
257
    <input id="id_duree" type="text" name="duree" maxlength="10"/>
259
   {{ form.duration.label_tag }}
260
   {{ form.duration }}
258 261
   </p>
259 262
   </td></tr>
260 263

  
261 264
   <tr>
262 265
   <td>
263
   <h4>Intervenants</h4>
266
     <h4>{{ form.participants.label_tag }}</h4>
264 267
   <div id="intervenants">
265
    <ul>
266
     <li><input type="checkbox" value="Bob Léponge" checked="checked">Bob Léponge</input></li>
267
     <li><input type="checkbox" value="Sandy Kilo" checked="checked">Sandy Kilo</input></li>
268
    </ul>
269
    <input/><button id="add-intervenant-btn">➕</button>
270
   <p><small>(champ avec autocomplétion)</small></p>
271
    <!-- <a href="#">Tout le monde</a> -->
268
     {{ form.participants }}
272 269
   </div>
273 270
   </td>
274 271
   <td>
275
   <h4>Patient</h4>
276
   <input name="patient"/>
277
   <br/>
278
   <p><small>(champ avec autocomplétion)</small></p>
272
     <h4>{{ form.patient.label_tag }}</h4>
273
     {{ form.patient }}
279 274
   </td>
280 275
   <td>
281 276

  
282
   <h4>Type d'acte</h4>
283
   <select>
284
    <option>Analyse</option>
285
    <option>Bla bla bla bla bla bla</option>
286
   </select>
277
     <h4>{{ form.act_type.label_tag }}</h4>
278
     {{ form.act_type }}
287 279
   </td>
288 280
   </tr>
289 281
   </table>
290 282

  
291 283
   <hr/>
292 284
   <button>Configurer la périodicité</button>
293

  
285
   {% endwith %}
294 286
   </form>
295 287
 </div>
296 288
{% endblock %}
calebasse/agenda/urls.py
3 3
from django.conf.urls import url, patterns, include
4 4

  
5 5
from calebasse.cbv import TemplateView
6
from views import redirect_today, AgendaHomepageView
6
from views import redirect_today, AgendaHomepageView, new_appointment
7 7

  
8 8

  
9 9
agenda_patterns = patterns('',
......
11 11
                AgendaHomepageView.as_view(
12 12
                    template_name='agenda/index.html'),
13 13
                name='agenda'),
14
            url(r'^nouveau-rdv/$',
15
                new_appointment,
16
                name='nouveau-rdv'),
14 17
            url(r'^activite-du-service/$',
15 18
                TemplateView.as_view(
16 19
                    template_name='agenda/activite-du-service.html'),
calebasse/agenda/views.py
7 7
from calebasse.personnes.models import Worker
8 8
from calebasse.ressources.models import WorkerType
9 9

  
10
from forms import NewAppointmentForm
11

  
10 12
def redirect_today(request, service):
11 13
    '''If not date is given we redirect on the agenda for today'''
12 14
    return redirect('agenda', date=datetime.date.today().strftime('%Y-%m-%d'),
......
21 23
        context['workers_types'] = []
22 24
        context['workers_agenda'] = []
23 25
        context['disponnibility'] = {}
26
        context['new_appointment_form'] = NewAppointmentForm()
24 27
        workers = []
25 28
        for worker_type in WorkerType.objects.all():
26 29
            data = {'type': worker_type.name, 'workers': Worker.objects.for_service(self.service, worker_type) }
......
33 36

  
34 37
        context['disponnibility'] = Occurrence.objects.daily_disponiblity(context['date'], workers)
35 38
        return context
39

  
40
def new_appointment(request):
41
    pass

Also available in: Unified diff