Commit 45be92ec3bf506f1e4070f912be01ac4437f78c4
1 parent
bfb98dad
Exists in
master
and in
3 other branches
Adding log to category view
Showing
6 changed files
with
70 additions
and
14 deletions
Show diff stats
amadeus/settings.py
... | ... | @@ -71,7 +71,7 @@ MIDDLEWARE_CLASSES = [ |
71 | 71 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', |
72 | 72 | 'django.middleware.locale.LocaleMiddleware', |
73 | 73 | |
74 | - #'core.middleware.TimeSpentMiddleware', | |
74 | + 'log.middleware.TimeSpentMiddleware', | |
75 | 75 | #libs-middleware |
76 | 76 | |
77 | 77 | ] | ... | ... |
amadeus/static/js/course.js
... | ... | @@ -111,6 +111,21 @@ $('.collapse').on('show.bs.collapse', function (e) { |
111 | 111 | var btn = $(this).parent().find('.fa-angle-right'); |
112 | 112 | |
113 | 113 | btn.switchClass("fa-angle-right", "fa-angle-down", 250, "easeInOutQuad"); |
114 | + | |
115 | + var url = $(this).parent().find('.log_url').val(); | |
116 | + var log_input = $(this).parent().find('.log_id'); | |
117 | + | |
118 | + $.ajax({ | |
119 | + url: url, | |
120 | + data: {'action': 'open'}, | |
121 | + dataType: 'json', | |
122 | + success: function (data) { | |
123 | + log_input.val(data.log_id); | |
124 | + }, | |
125 | + error: function (data) { | |
126 | + console.log(data); | |
127 | + } | |
128 | + }); | |
114 | 129 | } |
115 | 130 | }); |
116 | 131 | |
... | ... | @@ -119,5 +134,20 @@ $('.collapse').on('hide.bs.collapse', function (e) { |
119 | 134 | var btn = $(this).parent().find('.fa-angle-down'); |
120 | 135 | |
121 | 136 | btn.switchClass("fa-angle-down", "fa-angle-right", 250, "easeInOutQuad"); |
137 | + | |
138 | + var url = $(this).parent().find('.log_url').val(); | |
139 | + var log_id = $(this).parent().find('.log_id').val(); | |
140 | + | |
141 | + $.ajax({ | |
142 | + url: url, | |
143 | + data: {'action': 'close', 'log_id': log_id}, | |
144 | + dataType: 'json', | |
145 | + success: function (data) { | |
146 | + console.log(data.message); | |
147 | + }, | |
148 | + error: function (data) { | |
149 | + console.log(data); | |
150 | + } | |
151 | + }); | |
122 | 152 | } |
123 | 153 | }); |
124 | 154 | \ No newline at end of file | ... | ... |
categories/templates/categories/list.html
... | ... | @@ -32,8 +32,7 @@ |
32 | 32 | <li>{% trans "all subjects" %}</li> |
33 | 33 | </ul> |
34 | 34 | </div> |
35 | - {% endif %} | |
36 | - | |
35 | + {% endif %} | |
37 | 36 | |
38 | 37 | <!-- Code for listing categories --> |
39 | 38 | <div class="col-md-12 cards-content"> |
... | ... | @@ -79,6 +78,9 @@ |
79 | 78 | </div> |
80 | 79 | </div> |
81 | 80 | <div id="{{category.slug}}" class="panel-collapse collapse category-panel-content"> |
81 | + <input type="hidden" class="log_url" value="{% url 'categories:view_log' category.id %}" /> | |
82 | + <input type="hidden" class="log_id" value="" /> | |
83 | + | |
82 | 84 | <h4> {% trans "Coordinator(s): " %} |
83 | 85 | {% for coordinator in category.coordinators.all %} |
84 | 86 | {{coordinator.username}} | ... | ... |
categories/urls.py
... | ... | @@ -7,4 +7,5 @@ urlpatterns = [ |
7 | 7 | url(r'^delete/(?P<slug>[\w_-]+)/$', views.DeleteCategory.as_view(), name='delete'), |
8 | 8 | url(r'^replicate/(?P<slug>[\w_-]+)/$', views.CreateCategory.as_view(), name='replicate'), |
9 | 9 | url(r'^update/(?P<slug>[\w_-]+)/$', views.UpdateCategory.as_view(), name='update'), |
10 | + url(r'^view_log/(?P<category>[\w_-]+)/$', views.category_view_log, name = 'view_log') | |
10 | 11 | ] |
11 | 12 | \ No newline at end of file | ... | ... |
categories/views.py
... | ... | @@ -5,7 +5,7 @@ from django.core.urlresolvers import reverse_lazy |
5 | 5 | from rolepermissions.verifications import has_role |
6 | 6 | |
7 | 7 | from django.contrib import messages |
8 | -from django.http import HttpResponse | |
8 | +from django.http import HttpResponse, JsonResponse | |
9 | 9 | from django.utils.translation import ugettext_lazy as _ |
10 | 10 | |
11 | 11 | from django.contrib.auth.mixins import LoginRequiredMixin |
... | ... | @@ -17,6 +17,10 @@ from braces import views |
17 | 17 | from subjects.models import Subject |
18 | 18 | |
19 | 19 | from log.mixins import LogMixin |
20 | +from log.decorators import log_decorator_ajax | |
21 | +from log.models import Log | |
22 | + | |
23 | +import time | |
20 | 24 | |
21 | 25 | class IndexView(LoginRequiredMixin, ListView): |
22 | 26 | |
... | ... | @@ -113,7 +117,6 @@ class CreateCategory(views.SuperuserRequiredMixin, HasRoleMixin, LogMixin, Creat |
113 | 117 | |
114 | 118 | super(CreateCategory, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) |
115 | 119 | |
116 | - #TODO: Implement log calls | |
117 | 120 | return super(CreateCategory, self).form_valid(form) |
118 | 121 | |
119 | 122 | def get_success_url(self): |
... | ... | @@ -182,4 +185,24 @@ class UpdateCategory(LogMixin, UpdateView): |
182 | 185 | messages.success(self.request, _('Category "%s" updated successfully!')%(objeto)) |
183 | 186 | return reverse_lazy('categories:index') |
184 | 187 | |
188 | +@log_decorator_ajax('category', 'view', 'category') | |
189 | +def category_view_log(request, category): | |
190 | + action = request.GET.get('action') | |
191 | + | |
192 | + if action == 'open': | |
193 | + category = get_object_or_404(Category, id = category) | |
194 | + | |
195 | + log_context = {} | |
196 | + log_context['category_id'] = category.id | |
197 | + log_context['category_name'] = category.name | |
198 | + log_context['category_slug'] = category.slug | |
199 | + log_context['timestamp_start'] = str(int(time.time())) | |
200 | + log_context['timestamp_end'] = '-1' | |
201 | + | |
202 | + request.log_context = log_context | |
203 | + | |
204 | + log_id = Log.objects.latest('id').id | |
205 | + | |
206 | + return JsonResponse({'message': 'ok', 'log_id': log_id}) | |
185 | 207 | |
208 | + return JsonResponse({'message': 'ok'}) | ... | ... |
log/middleware.py
... | ... | @@ -32,16 +32,16 @@ class TimeSpentMiddleware(object): |
32 | 32 | |
33 | 33 | request.session['log_id'] = None |
34 | 34 | |
35 | - oppened_logs = Log.objects.filter(user = request.user, context__contains={'timestamp_end': '-1'}) | |
35 | + oppened_logs = Log.objects.filter(user = request.user, context__contains={'timestamp_end': '-1'}) | |
36 | 36 | |
37 | - for op_log in oppened_logs: | |
38 | - if type(op_log.context) == dict: | |
39 | - log_context = op_log.context | |
40 | - else: | |
41 | - log_context = json.loads(op_log.context) | |
37 | + for op_log in oppened_logs: | |
38 | + if type(op_log.context) == dict: | |
39 | + log_context = op_log.context | |
40 | + else: | |
41 | + log_context = json.loads(op_log.context) | |
42 | 42 | |
43 | - log_context['timestamp_end'] = str(int(time.time())) | |
43 | + log_context['timestamp_end'] = str(int(time.time())) | |
44 | 44 | |
45 | - op_log.context = log_context | |
45 | + op_log.context = log_context | |
46 | 46 | |
47 | - op_log.save() | |
48 | 47 | \ No newline at end of file |
48 | + op_log.save() | |
49 | 49 | \ No newline at end of file | ... | ... |