Commit 2ef81f0af9e16a3029783986234cfead6d8e167f
1 parent
6e69b2da
Exists in
master
and in
3 other branches
Adding topic log
Showing
5 changed files
with
183 additions
and
61 deletions
Show diff stats
amadeus/static/js/topics.js
| 1 | 1 | $('.topic-panel').on('show.bs.collapse', function (e) { |
| 2 | - if($(this).is(e.target)){ | |
| 3 | - var btn = $(this).parent().find('.fa-angle-right'); | |
| 4 | - | |
| 5 | - btn = btn[0]; | |
| 6 | - | |
| 7 | - $(btn).switchClass("fa-angle-right", "fa-angle-down", 250, "easeInOutQuad"); | |
| 8 | - | |
| 9 | - $(this).parent().parent().find('.panel-collapse.in').collapse('hide'); | |
| 10 | - } | |
| 2 | + if($(this).is(e.target)){ | |
| 3 | + var btn = $(this).parent().find('.fa-angle-right'); | |
| 4 | + | |
| 5 | + btn = btn[0]; | |
| 6 | + | |
| 7 | + $(btn).switchClass("fa-angle-right", "fa-angle-down", 250, "easeInOutQuad"); | |
| 8 | + | |
| 9 | + var url = $(this).parent().find('.log_url').val(); | |
| 10 | + var log_input = $(this).parent().find('.log_id'); | |
| 11 | + | |
| 12 | + if (typeof(url) != 'undefined') { | |
| 13 | + $.ajax({ | |
| 14 | + url: url, | |
| 15 | + data: {'action': 'open'}, | |
| 16 | + dataType: 'json', | |
| 17 | + success: function (data) { | |
| 18 | + log_input.val(data.log_id); | |
| 19 | + }, | |
| 20 | + error: function (data) { | |
| 21 | + console.log(data); | |
| 22 | + } | |
| 23 | + }); | |
| 24 | + } | |
| 25 | + | |
| 26 | + $(this).parent().parent().find('.panel-collapse.in').collapse('hide'); | |
| 27 | + } | |
| 11 | 28 | }); |
| 12 | 29 | |
| 13 | 30 | // Update breadcrumb with topic's name |
| 14 | 31 | $('.topic-panel').on('shown.bs.collapse', function (e) { |
| 15 | - if($(this).is(e.target)){ | |
| 16 | - var li = $(".breadcrumb").find('li:last-child'); | |
| 17 | - var li_text = $(li).html(); | |
| 18 | - var url = $(".subs_url").val(); | |
| 19 | - var new_li = $(li).clone(); | |
| 20 | - | |
| 21 | - new_li.html($(this).parent().find('.panel-title').text()); | |
| 22 | - | |
| 23 | - $(li).html("<a href='" + url + "'>" + li_text + "</a>"); | |
| 24 | - $(li).append("<span class='divider'>/</span>"); | |
| 25 | - | |
| 26 | - new_li.appendTo('.breadcrumb'); | |
| 27 | - } | |
| 32 | + if($(this).is(e.target)){ | |
| 33 | + var li = $(".breadcrumb").find('li:last-child'); | |
| 34 | + var li_text = $(li).html(); | |
| 35 | + var url = $(".subs_url").val(); | |
| 36 | + var new_li = $(li).clone(); | |
| 37 | + | |
| 38 | + new_li.html($(this).parent().find('.panel-title').text()); | |
| 39 | + | |
| 40 | + $(li).html("<a href='" + url + "'>" + li_text + "</a>"); | |
| 41 | + $(li).append("<span class='divider'>/</span>"); | |
| 42 | + | |
| 43 | + new_li.appendTo('.breadcrumb'); | |
| 44 | + } | |
| 28 | 45 | }); |
| 29 | 46 | |
| 30 | 47 | // Reset breadcrumb to it's normal state |
| 31 | 48 | $('.topic-panel').on('hide.bs.collapse', function (e) { |
| 32 | - if($(this).is(e.target)){ | |
| 33 | - var btn = $(this).parent().find('.fa-angle-down'); | |
| 34 | - | |
| 35 | - btn = btn[0]; | |
| 36 | - | |
| 37 | - $(btn).switchClass("fa-angle-down", "fa-angle-right", 250, "easeInOutQuad"); | |
| 38 | - | |
| 39 | - $(".breadcrumb").find('li:last-child').remove(); | |
| 40 | - | |
| 41 | - var li = $(".breadcrumb").find('li:last-child'); | |
| 42 | - var text = $(li).find('a').text(); | |
| 43 | - | |
| 44 | - $(li).html(text); | |
| 49 | + if($(this).is(e.target)){ | |
| 50 | + var btn = $(this).parent().find('.fa-angle-down'); | |
| 51 | + | |
| 52 | + btn = btn[0]; | |
| 53 | + | |
| 54 | + $(btn).switchClass("fa-angle-down", "fa-angle-right", 250, "easeInOutQuad"); | |
| 55 | + | |
| 56 | + $(".breadcrumb").find('li:last-child').remove(); | |
| 57 | + | |
| 58 | + var li = $(".breadcrumb").find('li:last-child'); | |
| 59 | + var text = $(li).find('a').text(); | |
| 60 | + | |
| 61 | + $(li).html(text); | |
| 62 | + | |
| 63 | + var url = $(this).parent().find('.log_url').val(); | |
| 64 | + var log_id = $(this).parent().find('.log_id').val(); | |
| 65 | + | |
| 66 | + if (typeof(url) != 'undefined') { | |
| 67 | + $.ajax({ | |
| 68 | + url: url, | |
| 69 | + data: {'action': 'close', 'log_id': log_id}, | |
| 70 | + dataType: 'json', | |
| 71 | + success: function (data) { | |
| 72 | + console.log(data.message); | |
| 73 | + }, | |
| 74 | + error: function (data) { | |
| 75 | + console.log(data); | |
| 76 | + } | |
| 77 | + }); | |
| 78 | + } | |
| 45 | 79 | } |
| 46 | 80 | }); |
| 47 | 81 | |
| 48 | 82 | // utilizado para fazer a re-organização dos tópicos |
| 49 | 83 | $("#topics-accordion").sortable({ |
| 50 | - delay: 100, | |
| 51 | - distance: 5, | |
| 52 | - handle: 'i.move_topic', | |
| 53 | - update: function( event, ui ) { | |
| 54 | - var cont = 1; | |
| 55 | - var data = []; | |
| 56 | - | |
| 57 | - $("#topics-accordion").find('.order_inp').each(function () { | |
| 58 | - $(this).val(cont++); | |
| 59 | - | |
| 60 | - data.push({ | |
| 61 | - 'topic_id': $(this).parent().find('.id_inp').val(), | |
| 62 | - 'topic_order': $(this).val() | |
| 63 | - }); | |
| 64 | - }); | |
| 65 | - | |
| 66 | - data = JSON.stringify(data); | |
| 67 | - | |
| 68 | - sendUpdate(data); | |
| 69 | - }, | |
| 84 | + delay: 100, | |
| 85 | + distance: 5, | |
| 86 | + handle: 'i.move_topic', | |
| 87 | + update: function( event, ui ) { | |
| 88 | + var cont = 1; | |
| 89 | + var data = []; | |
| 90 | + | |
| 91 | + $("#topics-accordion").find('.order_inp').each(function () { | |
| 92 | + $(this).val(cont++); | |
| 93 | + | |
| 94 | + data.push({ | |
| 95 | + 'topic_id': $(this).parent().find('.id_inp').val(), | |
| 96 | + 'topic_order': $(this).val() | |
| 97 | + }); | |
| 98 | + }); | |
| 99 | + | |
| 100 | + data = JSON.stringify(data); | |
| 101 | + | |
| 102 | + sendUpdate(data); | |
| 103 | + }, | |
| 70 | 104 | }); |
| 71 | 105 | |
| 72 | 106 | function sendUpdate(data) { |
| ... | ... | @@ -94,9 +128,9 @@ function delete_topic(url) { |
| 94 | 128 | } |
| 95 | 129 | |
| 96 | 130 | $(".add_resource").on('show.bs.dropdown', function () { |
| 97 | - $(this).find('i.fa-angle-right').switchClass("fa-angle-right", "fa-angle-down", 250, "easeInOutQuad"); | |
| 131 | + $(this).find('i.fa-angle-right').switchClass("fa-angle-right", "fa-angle-down", 250, "easeInOutQuad"); | |
| 98 | 132 | }); |
| 99 | 133 | |
| 100 | 134 | $(".add_resource").on('hide.bs.dropdown', function () { |
| 101 | - $(this).find('i.fa-angle-down').switchClass("fa-angle-down", "fa-angle-right", 250, "easeInOutQuad"); | |
| 135 | + $(this).find('i.fa-angle-down').switchClass("fa-angle-down", "fa-angle-right", 250, "easeInOutQuad"); | |
| 102 | 136 | }); |
| 103 | 137 | \ No newline at end of file | ... | ... |
subjects/templates/subjects/subject_card.html
| ... | ... | @@ -42,7 +42,7 @@ |
| 42 | 42 | </div> |
| 43 | 43 | </div> |
| 44 | 44 | <div id="{{subject.slug}}" class="panel-collapse collapse category-panel-content"> |
| 45 | - <input type="hidden" class="log_url" value="{% url 'subjects:view_log' subject.id %}" /> | |
| 45 | + <input type="hidden" class="log_url" value="{% url 'subjects:view_log' subject.id %}" /> | |
| 46 | 46 | <input type="hidden" class="log_id" value="" /> |
| 47 | 47 | |
| 48 | 48 | <div class="row"> | ... | ... |
topics/templates/topics/list.html
| ... | ... | @@ -37,6 +37,9 @@ |
| 37 | 37 | <div id="{{topic.slug}}" class="panel-collapse collapse category-panel-content topic-panel"> |
| 38 | 38 | <input type="hidden" class="id_inp" name="id" value="{{ topic.id }}" /> |
| 39 | 39 | <input type="hidden" class="order_inp" name="order" value="{{ topic.order }}" /> |
| 40 | + | |
| 41 | + <input type="hidden" class="log_url" value="{% url 'topics:view_log' topic.id %}" /> | |
| 42 | + <input type="hidden" class="log_id" value="" /> | |
| 40 | 43 | |
| 41 | 44 | {% autoescape off %} |
| 42 | 45 | {{ topic.description }} | ... | ... |
topics/urls.py
| ... | ... | @@ -7,6 +7,7 @@ urlpatterns = [ |
| 7 | 7 | url(r'^create/(?P<slug>[\w_-]+)/$', views.CreateView.as_view(), name = 'create'), |
| 8 | 8 | url(r'^update/(?P<sub_slug>[\w_-]+)/(?P<slug>[\w_-]+)/$', views.UpdateView.as_view(), name = 'update'), |
| 9 | 9 | url(r'^delete/(?P<slug>[\w_-]+)/$', views.DeleteView.as_view(), name = 'delete'), |
| 10 | + url(r'^view_log/(?P<topic>[\w_-]+)/$', views.topic_view_log, name = 'view_log'), | |
| 10 | 11 | url(r'^update_order/$', views.update_order, name = 'update_order'), |
| 11 | 12 | url(r'^update_resource_order/$', views.update_resource_order, name = 'update_resource_order'), |
| 12 | 13 | ] | ... | ... |
topics/views.py
| ... | ... | @@ -7,6 +7,11 @@ from django.utils.translation import ugettext_lazy as _ |
| 7 | 7 | from django.contrib.auth.mixins import LoginRequiredMixin |
| 8 | 8 | |
| 9 | 9 | import json |
| 10 | +import time | |
| 11 | + | |
| 12 | +from log.models import Log | |
| 13 | +from log.mixins import LogMixin | |
| 14 | +from log.decorators import log_decorator_ajax | |
| 10 | 15 | |
| 11 | 16 | from amadeus.permissions import has_subject_permissions |
| 12 | 17 | |
| ... | ... | @@ -15,7 +20,12 @@ from subjects.models import Subject |
| 15 | 20 | from .models import Topic, Resource |
| 16 | 21 | from .forms import TopicForm |
| 17 | 22 | |
| 18 | -class CreateView(LoginRequiredMixin, generic.edit.CreateView): | |
| 23 | +class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | |
| 24 | + log_component = 'topic' | |
| 25 | + log_action = 'create' | |
| 26 | + log_resource = 'topic' | |
| 27 | + log_context = {} | |
| 28 | + | |
| 19 | 29 | login_url = reverse_lazy("users:login") |
| 20 | 30 | redirect_field_name = 'next' |
| 21 | 31 | |
| ... | ... | @@ -51,6 +61,18 @@ class CreateView(LoginRequiredMixin, generic.edit.CreateView): |
| 51 | 61 | |
| 52 | 62 | self.object.save() |
| 53 | 63 | |
| 64 | + self.log_context['category_id'] = self.object.subject.category.id | |
| 65 | + self.log_context['category_name'] = self.object.subject.category.name | |
| 66 | + self.log_context['category_slug'] = self.object.subject.category.slug | |
| 67 | + self.log_context['subject_id'] = self.object.subject.id | |
| 68 | + self.log_context['subject_name'] = self.object.subject.name | |
| 69 | + self.log_context['subject_slug'] = self.object.subject.slug | |
| 70 | + self.log_context['topic_id'] = self.object.id | |
| 71 | + self.log_context['topic_name'] = self.object.name | |
| 72 | + self.log_context['topic_slug'] = self.object.slug | |
| 73 | + | |
| 74 | + super(CreateView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
| 75 | + | |
| 54 | 76 | return super(CreateView, self).form_valid(form) |
| 55 | 77 | |
| 56 | 78 | def get_context_data(self, **kwargs): |
| ... | ... | @@ -70,7 +92,12 @@ class CreateView(LoginRequiredMixin, generic.edit.CreateView): |
| 70 | 92 | |
| 71 | 93 | return reverse_lazy('subjects:view', kwargs = {'slug': self.object.subject.slug}) |
| 72 | 94 | |
| 73 | -class UpdateView(LoginRequiredMixin, generic.UpdateView): | |
| 95 | +class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): | |
| 96 | + log_component = 'topic' | |
| 97 | + log_action = 'update' | |
| 98 | + log_resource = 'topic' | |
| 99 | + log_context = {} | |
| 100 | + | |
| 74 | 101 | login_url = reverse_lazy("users:login") |
| 75 | 102 | redirect_field_name = 'next' |
| 76 | 103 | |
| ... | ... | @@ -112,9 +139,26 @@ class UpdateView(LoginRequiredMixin, generic.UpdateView): |
| 112 | 139 | def get_success_url(self): |
| 113 | 140 | messages.success(self.request, _('Topic "%s" was updated on virtual enviroment "%s" successfully!')%(self.object.name, self.object.subject.name)) |
| 114 | 141 | |
| 142 | + self.log_context['category_id'] = self.object.subject.category.id | |
| 143 | + self.log_context['category_name'] = self.object.subject.category.name | |
| 144 | + self.log_context['category_slug'] = self.object.subject.category.slug | |
| 145 | + self.log_context['subject_id'] = self.object.subject.id | |
| 146 | + self.log_context['subject_name'] = self.object.subject.name | |
| 147 | + self.log_context['subject_slug'] = self.object.subject.slug | |
| 148 | + self.log_context['topic_id'] = self.object.id | |
| 149 | + self.log_context['topic_name'] = self.object.name | |
| 150 | + self.log_context['topic_slug'] = self.object.slug | |
| 151 | + | |
| 152 | + super(UpdateView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
| 153 | + | |
| 115 | 154 | return reverse_lazy('subjects:view', kwargs = {'slug': self.object.subject.slug}) |
| 116 | 155 | |
| 117 | -class DeleteView(LoginRequiredMixin, generic.DeleteView): | |
| 156 | +class DeleteView(LoginRequiredMixin, LogMixin, generic.DeleteView): | |
| 157 | + log_component = 'topic' | |
| 158 | + log_action = 'delete' | |
| 159 | + log_resource = 'topic' | |
| 160 | + log_context = {} | |
| 161 | + | |
| 118 | 162 | login_url = reverse_lazy("users:login") |
| 119 | 163 | redirect_field_name = 'next' |
| 120 | 164 | |
| ... | ... | @@ -146,8 +190,48 @@ class DeleteView(LoginRequiredMixin, generic.DeleteView): |
| 146 | 190 | def get_success_url(self): |
| 147 | 191 | messages.success(self.request, _('Topic "%s" was removed from virtual enviroment "%s" successfully!')%(self.object.name, self.object.subject.name)) |
| 148 | 192 | |
| 193 | + self.log_context['category_id'] = self.object.subject.category.id | |
| 194 | + self.log_context['category_name'] = self.object.subject.category.name | |
| 195 | + self.log_context['category_slug'] = self.object.subject.category.slug | |
| 196 | + self.log_context['subject_id'] = self.object.subject.id | |
| 197 | + self.log_context['subject_name'] = self.object.subject.name | |
| 198 | + self.log_context['subject_slug'] = self.object.subject.slug | |
| 199 | + self.log_context['topic_id'] = self.object.id | |
| 200 | + self.log_context['topic_name'] = self.object.name | |
| 201 | + self.log_context['topic_slug'] = self.object.slug | |
| 202 | + | |
| 203 | + super(DeleteView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
| 204 | + | |
| 149 | 205 | return reverse_lazy('subjects:view', kwargs = {'slug': self.object.subject.slug}) |
| 150 | 206 | |
| 207 | +@log_decorator_ajax('topic', 'view', 'topic') | |
| 208 | +def topic_view_log(request, topic): | |
| 209 | + action = request.GET.get('action') | |
| 210 | + | |
| 211 | + if action == 'open': | |
| 212 | + topic = get_object_or_404(Topic, id = topic) | |
| 213 | + | |
| 214 | + log_context = {} | |
| 215 | + log_context['category_id'] = topic.subject.category.id | |
| 216 | + log_context['category_name'] = topic.subject.category.name | |
| 217 | + log_context['category_slug'] = topic.subject.category.slug | |
| 218 | + log_context['subject_id'] = topic.subject.id | |
| 219 | + log_context['subject_name'] = topic.subject.name | |
| 220 | + log_context['subject_slug'] = topic.subject.slug | |
| 221 | + log_context['topic_id'] = topic.id | |
| 222 | + log_context['topic_name'] = topic.name | |
| 223 | + log_context['topic_slug'] = topic.slug | |
| 224 | + log_context['timestamp_start'] = str(int(time.time())) | |
| 225 | + log_context['timestamp_end'] = '-1' | |
| 226 | + | |
| 227 | + request.log_context = log_context | |
| 228 | + | |
| 229 | + log_id = Log.objects.latest('id').id | |
| 230 | + | |
| 231 | + return JsonResponse({'message': 'ok', 'log_id': log_id}) | |
| 232 | + | |
| 233 | + return JsonResponse({'message': 'ok'}) | |
| 234 | + | |
| 151 | 235 | def update_order(request): |
| 152 | 236 | data = request.GET.get('data', None) |
| 153 | 237 | ... | ... |