Commit 16befc8848274a04e6a04aa5a7e631b7723df8e3

Authored by Zambom
1 parent ae0d1c79

Update log decorator [Issue: #231]

Showing 1 changed file with 5 additions and 2 deletions   Show diff stats
core/decorators.py
1 from django.conf import settings 1 from django.conf import settings
  2 +import json
2 from functools import wraps 3 from functools import wraps
3 from .models import Action, Resource, Action_Resource, Log, Notification 4 from .models import Action, Resource, Action_Resource, Log, Notification
4 5
5 -def log_decorator(log_action = '', log_resource = ''): 6 +def log_decorator(log_component = '', log_action = '', log_resource = ''):
6 7
7 def _log_decorator(view_function): 8 def _log_decorator(view_function):
8 9
@@ -10,7 +11,7 @@ def log_decorator(log_action = '', log_resource = ''): @@ -10,7 +11,7 @@ def log_decorator(log_action = '', log_resource = ''):
10 11
11 response = view_function(request, *args, **kwargs) 12 response = view_function(request, *args, **kwargs)
12 13
13 - if request.user.is_authenticated and request.POST: 14 + if request.user.is_authenticated:
14 action = Action.objects.filter(name = log_action) 15 action = Action.objects.filter(name = log_action)
15 resource = Resource.objects.filter(name = log_resource) 16 resource = Resource.objects.filter(name = log_resource)
16 17
@@ -36,6 +37,8 @@ def log_decorator(log_action = '', log_resource = ''): @@ -36,6 +37,8 @@ def log_decorator(log_action = '', log_resource = ''):
36 37
37 log = Log() 38 log = Log()
38 log.user = request.user 39 log.user = request.user
  40 + log.component = log_component
  41 + log.context = json.dumps(request.log_context)
39 log.action_resource = action_resource 42 log.action_resource = action_resource
40 43
41 log.save() 44 log.save()