From 401f271935adec317629c2204e8f9c70f601904c Mon Sep 17 00:00:00 2001 From: Zambom Date: Wed, 2 Nov 2016 18:25:48 -0300 Subject: [PATCH] Changing log mixin [Issue: #231] --- core/mixins.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/core/mixins.py b/core/mixins.py index 6c9b489..6c82977 100644 --- a/core/mixins.py +++ b/core/mixins.py @@ -1,23 +1,27 @@ from django.conf import settings +import json + from .models import Action, Resource, Action_Resource, Log, Notification from users.models import User class LogMixin(object): + log_component = "" + log_context = {} log_action = "" log_resource = "" - def dispatch(self, request, *args, **kwargs): - action = Action.objects.filter(name = self.log_action) - resource = Resource.objects.filter(name = self.log_resource) + def createLog(self, actor = None, component = '', log_action = '', log_resource = '', context = {}): + action = Action.objects.filter(name = log_action) + resource = Resource.objects.filter(name = log_resource) if not action: - action = Action(name = self.log_action) + action = Action(name = log_action) action.save() else: action = action[0] if not resource: - resource = Resource(name = self.log_resource) + resource = Resource(name = log_resource) resource.save() else: resource = resource[0] @@ -30,12 +34,18 @@ class LogMixin(object): else: action_resource = action_resource[0] + print(context) + print(json.dumps(context)) + log = Log() - log.user = request.user + log.user = actor + log.context = json.dumps(context) + log.component = component log.action_resource = action_resource log.save() + def dispatch(self, request, *args, **kwargs): return super(LogMixin, self).dispatch(request, *args, **kwargs) class NotificationMixin(object): -- libgit2 0.21.2