Commit e64fc7dd88436690365ea2581221ec067e9d40b0

Authored by Felipe Bormann
1 parent d79b229b

modified logmixin to use attributes of class

Showing 1 changed file with 21 additions and 8 deletions   Show diff stats
log/mixins.py
... ... @@ -5,10 +5,10 @@ from .models import Log
5 5 from users.models import User
6 6  
7 7 class LogMixin(object):
8   - log_component = ""
9   - log_context = {}
10   - log_action = ""
11   - log_resource = ""
  8 + log_component = None
  9 + log_context = None
  10 + log_action = None
  11 + log_resource = None
12 12  
13 13 def createLog(self, actor = None, component = '', log_action = '', log_resource = '', context = {}):
14 14 if actor.is_authenticated:
... ... @@ -16,10 +16,23 @@ class LogMixin(object):
16 16 log.user = str(actor)
17 17 log.user_id = actor.id
18 18 log.user_email = actor.email
19   - log.context = context
20   - log.component = component
21   - log.action = log_action
22   - log.resource = log_resource
  19 + if self.log_context is not None:
  20 + log.context = self.log_context
  21 + else:
  22 + log.context = context
  23 + if self.log_component is not None:
  24 + log.component = self.log_component
  25 + else:
  26 + log.component = component
  27 +
  28 + if self.log_action is not None:
  29 + log.action = self.log_action
  30 + else:
  31 + log.action = log_action
  32 + if self.log_resource is not None:
  33 + log.resource = self.log_resource
  34 + else:
  35 + log.resource = log_resource
23 36  
24 37 log.save()
25 38  
... ...