Commit 5f6968b489701393436404665c01954b8086b699
1 parent
955337a6
Exists in
master
and in
5 other branches
Changing log context field to postgres JSONField [Issue: #231]
Showing
5 changed files
with
14 additions
and
9 deletions
Show diff stats
core/decorators.py
... | ... | @@ -38,7 +38,8 @@ def log_decorator(log_component = '', log_action = '', log_resource = ''): |
38 | 38 | log = Log() |
39 | 39 | log.user = request.user |
40 | 40 | log.component = log_component |
41 | - log.context = json.dumps(request.log_context) | |
41 | + #log.context = json.dumps(request.log_context) | |
42 | + log.context = request.log_context | |
42 | 43 | log.action_resource = action_resource |
43 | 44 | |
44 | 45 | log.save() | ... | ... |
core/middleware.py
... | ... | @@ -26,13 +26,16 @@ class TimeSpentMiddleware(object): |
26 | 26 | secs = secs % 60 |
27 | 27 | |
28 | 28 | log_context = json.loads(log.context) |
29 | + print(log.context) | |
29 | 30 | |
30 | - log_context['time_spent'] = {} | |
31 | - log_context['time_spent']['hours'] = hours | |
32 | - log_context['time_spent']['minutes'] = minutes | |
33 | - log_context['time_spent']['seconds'] = secs | |
31 | + time = {} | |
32 | + time['hours'] = hours | |
33 | + time['minutes'] = minutes | |
34 | + time['seconds'] = secs | |
34 | 35 | |
35 | - log.context = json.dumps(log_context) | |
36 | + log_context['time_spent'] = time | |
37 | + | |
38 | + log.context = log_context | |
36 | 39 | |
37 | 40 | log.save() |
38 | 41 | ... | ... |
core/mixins.py
core/models.py
... | ... | @@ -2,6 +2,7 @@ from django.db import models |
2 | 2 | from django.utils.translation import ugettext_lazy as _ |
3 | 3 | from users.models import User |
4 | 4 | from autoslug.fields import AutoSlugField |
5 | +from django.contrib.postgres.fields import JSONField | |
5 | 6 | # Create your models here. |
6 | 7 | |
7 | 8 | class MimeType(models.Model): |
... | ... | @@ -102,7 +103,7 @@ class Notification(models.Model): |
102 | 103 | |
103 | 104 | class Log(models.Model): |
104 | 105 | component = models.TextField(_('Component (Module / App)')) |
105 | - context = models.TextField(_('Context'), blank = True) | |
106 | + context = JSONField(_('Context'), blank = True) | |
106 | 107 | action_resource = models.ForeignKey(Action_Resource, verbose_name = _('Action_Resource')) |
107 | 108 | user = models.ForeignKey(User, verbose_name = _('Actor')) |
108 | 109 | datetime = models.DateTimeField(_("Date and Time of action"), auto_now_add = True) | ... | ... |
core/views.py
... | ... | @@ -20,7 +20,6 @@ from rest_framework import status, serializers, permissions, viewsets |
20 | 20 | from rest_framework.response import Response |
21 | 21 | from rest_framework.decorators import api_view |
22 | 22 | |
23 | - | |
24 | 23 | from .forms import RegisterUserForm |
25 | 24 | from .decorators import log_decorator, notification_decorator |
26 | 25 | ... | ... |