Project

General

Profile

« Previous | Next » 

Revision b58c4ed6

Added by Serghei Mihai over 9 years ago

logging: handling cases when objects created, modified or deleted from shell

View differences:

calebasse/common/models.py
1 1
from django.db.models.signals import post_save, pre_delete
2 2
from ..middleware.request import get_request
3 3

  
4
import django_journal
5

  
4 6
from calebasse.agenda.models import Event, EventWithAct, EventType
5 7
from calebasse.actes.models import ActValidationState, Act
6 8
from calebasse.dossiers.models import FileState, PatientRecord, PatientAddress, PatientContact
......
10 12
    model_name = sender.__name__.lower()
11 13
    if kwargs.get('created'):
12 14
        tag = 'new-%s' % model_name
13
        log = '{obj_id} created by {user} from {ip}'
15
        log = '{obj} created'
14 16
    else:
15 17
        tag = '%s-save' % model_name
16
        log = '{obj_id} saved by {user} from {ip}'
18
        log = '{obj} saved'
17 19

  
18
    obj_id = kwargs['instance'].id
19
    get_request().record(tag, log, obj_id=obj_id)
20
    obj = kwargs['instance']
21
    try:
22
        get_request().record(tag, log, obj=obj)
23
    except AttributeError:
24
        django_journal.record(tag, '{obj} from shell', obj=obj)
20 25

  
21 26
def object_delete(sender, **kwargs):
22 27
    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)
28
    try:
29
        get_request().record('delete-%s' % model_name,
30
                             '{obj}',
31
                             obj=kwargs['instance'])
32
    except AttributeError:
33
        django_journal.record('delete-%s' % model_name,
34
                              '{obj} from shell', obj=kwargs['instance'])
26 35

  
27 36
for model in (Event, EventWithAct, EventType, ActValidationState, Act,
28 37
              FileState, PatientRecord, PatientAddress, PatientContact,

Also available in: Unified diff