Commit 401f271935adec317629c2204e8f9c70f601904c
1 parent
a55bb8e3
Exists in
master
and in
5 other branches
Changing log mixin [Issue: #231]
Showing
1 changed file
with
16 additions
and
6 deletions
Show diff stats
core/mixins.py
1 | 1 | from django.conf import settings |
2 | +import json | |
3 | + | |
2 | 4 | from .models import Action, Resource, Action_Resource, Log, Notification |
3 | 5 | from users.models import User |
4 | 6 | |
5 | 7 | class LogMixin(object): |
8 | + log_component = "" | |
9 | + log_context = {} | |
6 | 10 | log_action = "" |
7 | 11 | log_resource = "" |
8 | 12 | |
9 | - def dispatch(self, request, *args, **kwargs): | |
10 | - action = Action.objects.filter(name = self.log_action) | |
11 | - resource = Resource.objects.filter(name = self.log_resource) | |
13 | + def createLog(self, actor = None, component = '', log_action = '', log_resource = '', context = {}): | |
14 | + action = Action.objects.filter(name = log_action) | |
15 | + resource = Resource.objects.filter(name = log_resource) | |
12 | 16 | |
13 | 17 | if not action: |
14 | - action = Action(name = self.log_action) | |
18 | + action = Action(name = log_action) | |
15 | 19 | action.save() |
16 | 20 | else: |
17 | 21 | action = action[0] |
18 | 22 | |
19 | 23 | if not resource: |
20 | - resource = Resource(name = self.log_resource) | |
24 | + resource = Resource(name = log_resource) | |
21 | 25 | resource.save() |
22 | 26 | else: |
23 | 27 | resource = resource[0] |
... | ... | @@ -30,12 +34,18 @@ class LogMixin(object): |
30 | 34 | else: |
31 | 35 | action_resource = action_resource[0] |
32 | 36 | |
37 | + print(context) | |
38 | + print(json.dumps(context)) | |
39 | + | |
33 | 40 | log = Log() |
34 | - log.user = request.user | |
41 | + log.user = actor | |
42 | + log.context = json.dumps(context) | |
43 | + log.component = component | |
35 | 44 | log.action_resource = action_resource |
36 | 45 | |
37 | 46 | log.save() |
38 | 47 | |
48 | + def dispatch(self, request, *args, **kwargs): | |
39 | 49 | return super(LogMixin, self).dispatch(request, *args, **kwargs) |
40 | 50 | |
41 | 51 | class NotificationMixin(object): | ... | ... |