Commit b10e54375b74b3c8342694f3cab358e4cbd81324
1 parent
862dbc12
Exists in
master
and in
5 other branches
Fixing errors [Issue #24]
Showing
2 changed files
with
38 additions
and
2 deletions
Show diff stats
core/decorators.py
... | ... | @@ -14,7 +14,25 @@ def log_decorator(log_action = '', log_resource = ''): |
14 | 14 | action = Action.objects.filter(name = log_action) |
15 | 15 | resource = Resource.objects.filter(name = log_resource) |
16 | 16 | |
17 | - action_resource = Action_Resource.objects.filter(action = action, resource = resource)[0] | |
17 | + if not action: | |
18 | + action = Action(name = log_action) | |
19 | + action.save() | |
20 | + else: | |
21 | + action = action[0] | |
22 | + | |
23 | + if not resource: | |
24 | + resource = Resource(name = log_resource) | |
25 | + resource.save() | |
26 | + else: | |
27 | + resource = resource[0] | |
28 | + | |
29 | + action_resource = Action_Resource.objects.filter(action = action, resource = resource) | |
30 | + | |
31 | + if not action_resource: | |
32 | + action_resource = Action_Resource(action = action, resource = resource) | |
33 | + action_resource.save() | |
34 | + else: | |
35 | + action_resource = action_resource[0] | |
18 | 36 | |
19 | 37 | log = Log() |
20 | 38 | log.user = request.user | ... | ... |
core/mixins.py
... | ... | @@ -9,7 +9,25 @@ class LogMixin(object): |
9 | 9 | action = Action.objects.filter(name = self.log_action) |
10 | 10 | resource = Resource.objects.filter(name = self.log_resource) |
11 | 11 | |
12 | - action_resource = Action_Resource.objects.filter(action = action, resource = resource)[0] | |
12 | + if not action: | |
13 | + action = Action(name = self.log_action) | |
14 | + action.save() | |
15 | + else: | |
16 | + action = action[0] | |
17 | + | |
18 | + if not resource: | |
19 | + resource = Resource(name = self.log_resource) | |
20 | + resource.save() | |
21 | + else: | |
22 | + resource = resource[0] | |
23 | + | |
24 | + action_resource = Action_Resource.objects.filter(action = action, resource = resource) | |
25 | + | |
26 | + if not action_resource: | |
27 | + action_resource = Action_Resource(action = action, resource = resource) | |
28 | + action_resource.save() | |
29 | + else: | |
30 | + action_resource = action_resource[0] | |
13 | 31 | |
14 | 32 | log = Log() |
15 | 33 | log.user = request.user | ... | ... |