Project

General

Profile

Download (1.34 KB) Statistics
| Branch: | Tag: | Revision:

calebasse / calebasse / common / models.py @ 8e6a3c86

1 8e6a3c86 Serghei MIHAI
from django.db.models.signals import post_save, pre_delete
2
from ..middleware.request import get_request
3
4
from calebasse.agenda.models import Event, EventWithAct, EventType
5
from calebasse.actes.models import ActValidationState, Act
6
from calebasse.dossiers.models import FileState, PatientRecord, PatientAddress, PatientContact
7
from calebasse.personnes.models import People, Worker, ExternalWorker, ExternalTherapist, Holiday
8
9
def object_save(sender, **kwargs):
10
    model_name = sender.__name__.lower()
11
    if kwargs.get('created'):
12
        tag = 'new-%s' % model_name
13
        log = '{obj_id} created by {user} from {ip}'
14
    else:
15
        tag = '%s-save' % model_name
16
        log = '{obj_id} saved by {user} from {ip}'
17
18
    obj_id = kwargs['instance'].id
19
    get_request().record(tag, log, obj_id=obj_id)
20
21
def object_delete(sender, **kwargs):
22
    model_name = sender.__name__.lower()
23
    get_request().record('delete-%s' % model_name,
24
                         '{obj_id} deleted by {user} from {ip}',
25
                         obj_id=kwargs['instance'].id)
26
27
for model in (Event, EventWithAct, EventType, ActValidationState, Act,
28
              FileState, PatientRecord, PatientAddress, PatientContact,
29
              People, Worker, ExternalWorker, ExternalTherapist, Holiday):
30
    post_save.connect(object_save, sender=model)
31
    pre_delete.connect(object_delete, sender=model)