Commit e64fc7dd88436690365ea2581221ec067e9d40b0
1 parent
d79b229b
Exists in
master
and in
2 other branches
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,10 +5,10 @@ from .models import Log | ||
5 | from users.models import User | 5 | from users.models import User |
6 | 6 | ||
7 | class LogMixin(object): | 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 | def createLog(self, actor = None, component = '', log_action = '', log_resource = '', context = {}): | 13 | def createLog(self, actor = None, component = '', log_action = '', log_resource = '', context = {}): |
14 | if actor.is_authenticated: | 14 | if actor.is_authenticated: |
@@ -16,10 +16,23 @@ class LogMixin(object): | @@ -16,10 +16,23 @@ class LogMixin(object): | ||
16 | log.user = str(actor) | 16 | log.user = str(actor) |
17 | log.user_id = actor.id | 17 | log.user_id = actor.id |
18 | log.user_email = actor.email | 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 | log.save() | 37 | log.save() |
25 | 38 |