1
|
import datetime
|
2
|
|
3
|
from tastypie.authorization import Authorization
|
4
|
from tastypie.resources import ModelResource
|
5
|
from calebasse.actes.models import Act
|
6
|
from calebasse.agenda.models import Event, EventWithAct
|
7
|
from calebasse.dossiers.models import PatientRecord, PatientAddress
|
8
|
|
9
|
|
10
|
class EventResource(ModelResource):
|
11
|
class Meta:
|
12
|
queryset = Event.objects.all()
|
13
|
resource_name = 'event'
|
14
|
authorization = Authorization()
|
15
|
|
16
|
def obj_get(self, bundle, **kwargs):
|
17
|
'''If a date parameter is passed, use it to specialize the Event
|
18
|
instance for this date.'''
|
19
|
request = bundle.request
|
20
|
date = None
|
21
|
if 'date' in request.GET:
|
22
|
date = request.GET['date']
|
23
|
date = datetime.datetime.strptime(date, '%Y-%m-%d').date()
|
24
|
obj = super(EventResource, self).obj_get(bundle, **kwargs)
|
25
|
if date:
|
26
|
obj = obj.today_occurrence(date)
|
27
|
return obj
|
28
|
|
29
|
class EventWithActRessource(ModelResource):
|
30
|
class Meta:
|
31
|
queryset = EventWithAct.objects.all()
|
32
|
resource_name = 'eventwithact'
|
33
|
authorization = Authorization()
|
34
|
|
35
|
class PatientRecordRessource(ModelResource):
|
36
|
class Meta:
|
37
|
queryset = PatientRecord.objects.all()
|
38
|
resource_name = 'patientrecord'
|
39
|
authorization = Authorization()
|
40
|
|
41
|
class PatientAddressRessource(ModelResource):
|
42
|
class Meta:
|
43
|
queryset = PatientAddress.objects.all()
|
44
|
resource_name = 'patientaddress'
|
45
|
authorization = Authorization()
|
46
|
|
47
|
class ActRessource(ModelResource):
|
48
|
class Meta:
|
49
|
queryset = Act.objects.all()
|
50
|
resource_name = 'act'
|
51
|
authorization = Authorization()
|
52
|
|
53
|
patientaddress_ressource = PatientAddressRessource()
|
54
|
event_resource = EventResource()
|
55
|
eventwithact_resource = EventWithActRessource()
|
56
|
patientrecord_resource = PatientRecordRessource()
|
57
|
act_ressource = ActRessource()
|
58
|
|