Commit 4fcd45330521855b3caec85e05c7708115244c39
1 parent
d9c91f9e
Exists in
master
and in
3 other branches
Adding pendencies log
Showing
4 changed files
with
202 additions
and
5 deletions
Show diff stats
amadeus/static/js/pendencies.js
... | ... | @@ -65,6 +65,40 @@ $('.pendencies-content').on('hidden.bs.collapse', function(e) { |
65 | 65 | if (h_items > 10) { |
66 | 66 | h_holder.jPages("destroy"); |
67 | 67 | } |
68 | + | |
69 | + var url = pendencies.find('.view_log_url').val(); | |
70 | + var log_id = pendencies.find('.view_log_id').val(); | |
71 | + | |
72 | + if (typeof(url) != 'undefined') { | |
73 | + $.ajax({ | |
74 | + url: url, | |
75 | + data: {'action': 'close', 'log_id': log_id}, | |
76 | + dataType: 'json', | |
77 | + success: function (data) { | |
78 | + console.log(data.message); | |
79 | + }, | |
80 | + error: function (data) { | |
81 | + console.log(data); | |
82 | + } | |
83 | + }); | |
84 | + } | |
85 | + | |
86 | + var hist_url = history.find('.hist_log_url').val(); | |
87 | + var hist_log_id = history.find('.hist_log_id').val(); | |
88 | + | |
89 | + if (typeof(hist_url) != 'undefined' && hist_log_id != "") { | |
90 | + $.ajax({ | |
91 | + url: hist_url, | |
92 | + data: {'action': 'close', 'log_id': hist_log_id}, | |
93 | + dataType: 'json', | |
94 | + success: function (data) { | |
95 | + console.log(data.message); | |
96 | + }, | |
97 | + error: function (data) { | |
98 | + console.log(data); | |
99 | + } | |
100 | + }); | |
101 | + } | |
68 | 102 | } |
69 | 103 | }); |
70 | 104 | |
... | ... | @@ -111,6 +145,40 @@ function getPendencies(panel_id) { |
111 | 145 | metaFunctions(); |
112 | 146 | } |
113 | 147 | |
148 | + var url = list.parent().find('.view_log_url').val(); | |
149 | + var log_input = list.parent().find('.view_log_id'); | |
150 | + | |
151 | + if (typeof(url) != 'undefined') { | |
152 | + $.ajax({ | |
153 | + url: url, | |
154 | + data: {'action': 'open'}, | |
155 | + dataType: 'json', | |
156 | + success: function (data) { | |
157 | + log_input.val(data.log_id); | |
158 | + }, | |
159 | + error: function (data) { | |
160 | + console.log(data); | |
161 | + } | |
162 | + }); | |
163 | + } | |
164 | + | |
165 | + var hist_url = list.parent().parent().find('.hist_log_url').val(); | |
166 | + var hist_log_id = list.parent().parent().find('.hist_log_id').val(); | |
167 | + | |
168 | + if (typeof(hist_url) != 'undefined' && hist_log_id != "") { | |
169 | + $.ajax({ | |
170 | + url: hist_url, | |
171 | + data: {'action': 'close', 'log_id': hist_log_id}, | |
172 | + dataType: 'json', | |
173 | + success: function (data) { | |
174 | + console.log(data.message); | |
175 | + }, | |
176 | + error: function (data) { | |
177 | + console.log(data); | |
178 | + } | |
179 | + }); | |
180 | + } | |
181 | + | |
114 | 182 | list.parent().parent().find('.history').attr('style', 'display: none'); |
115 | 183 | list.parent().attr('style', 'display: block'); |
116 | 184 | |
... | ... | @@ -166,6 +234,40 @@ function getHistory(panel_id) { |
166 | 234 | } |
167 | 235 | } |
168 | 236 | |
237 | + var url = container.find('.view_log_url').val(); | |
238 | + var log_id = container.find('.view_log_id').val(); | |
239 | + | |
240 | + if (typeof(url) != 'undefined') { | |
241 | + $.ajax({ | |
242 | + url: url, | |
243 | + data: {'action': 'close', 'log_id': log_id}, | |
244 | + dataType: 'json', | |
245 | + success: function (data) { | |
246 | + console.log(data.message); | |
247 | + }, | |
248 | + error: function (data) { | |
249 | + console.log(data); | |
250 | + } | |
251 | + }); | |
252 | + } | |
253 | + | |
254 | + var hist_url = container.find('.hist_log_url').val(); | |
255 | + var hist_log_input = container.find('.hist_log_id'); | |
256 | + | |
257 | + if (typeof(hist_url) != 'undefined') { | |
258 | + $.ajax({ | |
259 | + url: hist_url, | |
260 | + data: {'action': 'open'}, | |
261 | + dataType: 'json', | |
262 | + success: function (data) { | |
263 | + hist_log_input.val(data.log_id); | |
264 | + }, | |
265 | + error: function (data) { | |
266 | + console.log(data); | |
267 | + } | |
268 | + }); | |
269 | + } | |
270 | + | |
169 | 271 | container.find('.pendencies_link').removeClass('active'); |
170 | 272 | container.find('.history_link').addClass('active'); |
171 | 273 | ... | ... |
notifications/templates/notifications/index.html
... | ... | @@ -41,11 +41,17 @@ |
41 | 41 | </div> |
42 | 42 | |
43 | 43 | <div class="pendencies" data-url="{% url 'notifications:ajax_view' notification.task__resource__topic__subject %}"> |
44 | + <input type="hidden" class="view_log_url" value="{% url 'notifications:view_log' notification.task__resource__topic__subject %}" /> | |
45 | + <input type="hidden" class="view_log_id" value="" /> | |
46 | + | |
44 | 47 | <div id="pendencies_list_{{ notification.task__resource__topic__subject }}" class="pendencies-cards"></div> |
45 | 48 | <div class="holder"></div> |
46 | 49 | </div> |
47 | 50 | |
48 | 51 | <div class="history" data-url="{% url 'notifications:ajax_history' notification.task__resource__topic__subject %}"> |
52 | + <input type="hidden" class="hist_log_url" value="{% url 'notifications:hist_log' notification.task__resource__topic__subject %}" /> | |
53 | + <input type="hidden" class="hist_log_id" value="" /> | |
54 | + | |
49 | 55 | <div class="history_data"></div> |
50 | 56 | <div class="text-center"> |
51 | 57 | <div class="holder"></div> | ... | ... |
notifications/urls.py
... | ... | @@ -7,6 +7,8 @@ urlpatterns = [ |
7 | 7 | url(r'^set_goal/$', views.set_goal, name='set_goal'), |
8 | 8 | url(r'^ajax/(?P<id>[\w_-]+)/$', views.AjaxNotifications.as_view(), name='ajax_view'), |
9 | 9 | url(r'^ajax_history/(?P<id>[\w_-]+)/$', views.AjaxHistory.as_view(), name='ajax_history'), |
10 | + url(r'^view_log/(?P<subject>[\w_-]+)/$', views.pendencies_view_log, name = 'view_log'), | |
11 | + url(r'^hist_log/(?P<subject>[\w_-]+)/$', views.pendencies_hist_log, name = 'hist_log'), | |
10 | 12 | url(r'^(?P<slug>[\w_-]+)/$', views.SubjectNotifications.as_view(), name='view'), |
11 | 13 | url(r'^(?P<slug>[\w_-]+)/history/$', views.SubjectHistory.as_view(), name='history'), |
12 | 14 | ] |
13 | 15 | \ No newline at end of file | ... | ... |
notifications/views.py
... | ... | @@ -17,10 +17,20 @@ from amadeus.permissions import has_subject_view_permissions, has_category_permi |
17 | 17 | from subjects.models import Subject |
18 | 18 | from categories.models import Category |
19 | 19 | |
20 | +from log.models import Log | |
21 | +from log.mixins import LogMixin | |
22 | +from log.decorators import log_decorator, log_decorator_ajax | |
23 | +import time | |
24 | + | |
20 | 25 | from .models import Notification |
21 | 26 | from .utils import get_order_by, is_date |
22 | 27 | |
23 | -class SubjectNotifications(LoginRequiredMixin, generic.ListView): | |
28 | +class SubjectNotifications(LoginRequiredMixin, LogMixin, generic.ListView): | |
29 | + log_component = 'pendencies' | |
30 | + log_action = 'view' | |
31 | + log_resource = 'pendencies' | |
32 | + log_context = {} | |
33 | + | |
24 | 34 | login_url = reverse_lazy("users:login") |
25 | 35 | redirect_field_name = 'next' |
26 | 36 | |
... | ... | @@ -60,9 +70,24 @@ class SubjectNotifications(LoginRequiredMixin, generic.ListView): |
60 | 70 | context['subject'] = subject |
61 | 71 | context['total'] = self.total |
62 | 72 | |
73 | + self.log_context['subject_id'] = subject.id | |
74 | + self.log_context['subject_name'] = subject.name | |
75 | + self.log_context['subject_slug'] = subject.slug | |
76 | + self.log_context['view_page'] = self.request.GET.get("page", 1) | |
77 | + self.log_context['timestamp_start'] = str(int(time.time())) | |
78 | + | |
79 | + super(SubjectNotifications, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
80 | + | |
81 | + self.request.session['log_id'] = Log.objects.latest('id').id | |
82 | + | |
63 | 83 | return context |
64 | 84 | |
65 | -class SubjectHistory(LoginRequiredMixin, generic.ListView): | |
85 | +class SubjectHistory(LoginRequiredMixin, LogMixin, generic.ListView): | |
86 | + log_component = 'pendencies' | |
87 | + log_action = 'view_history' | |
88 | + log_resource = 'pendencies' | |
89 | + log_context = {} | |
90 | + | |
66 | 91 | login_url = reverse_lazy("users:login") |
67 | 92 | redirect_field_name = 'next' |
68 | 93 | |
... | ... | @@ -127,6 +152,17 @@ class SubjectHistory(LoginRequiredMixin, generic.ListView): |
127 | 152 | context['rows'] = self.num_rows |
128 | 153 | context['searched'] = self.request.GET.get("search", "") |
129 | 154 | |
155 | + self.log_context['subject_id'] = subject.id | |
156 | + self.log_context['subject_name'] = subject.name | |
157 | + self.log_context['subject_slug'] = subject.slug | |
158 | + self.log_context['history_page'] = self.request.GET.get("page", 1) | |
159 | + self.log_context['searched'] = self.request.GET.get("search", "") | |
160 | + self.log_context['timestamp_start'] = str(int(time.time())) | |
161 | + | |
162 | + super(SubjectHistory, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
163 | + | |
164 | + self.request.session['log_id'] = Log.objects.latest('id').id | |
165 | + | |
130 | 166 | return context |
131 | 167 | |
132 | 168 | class IndexView(LoginRequiredMixin, generic.ListView): |
... | ... | @@ -237,6 +273,7 @@ class AjaxHistory(LoginRequiredMixin, generic.ListView): |
237 | 273 | return context |
238 | 274 | |
239 | 275 | @login_required |
276 | +@log_decorator('pendencies', 'set_goal', 'pendencies') | |
240 | 277 | def set_goal(request): |
241 | 278 | if request.method == "POST" and request.is_ajax(): |
242 | 279 | meta = request.POST.get('meta', None) |
... | ... | @@ -264,9 +301,59 @@ def set_goal(request): |
264 | 301 | notification.meta = meta |
265 | 302 | notification.save() |
266 | 303 | |
304 | + log_context = {} | |
305 | + log_context['notification_id'] = notification.id | |
306 | + log_context['notification'] = str(notification) | |
307 | + | |
308 | + request.log_context = log_context | |
309 | + | |
267 | 310 | if notification.level == 2: |
268 | - message = _('Your new goal to realize the task %s is %s')%(str(notification.task), formats.date_format(meta, "SHORT_DATETIME_FORMAT")) | |
311 | + message = _('Your new goal to realize the task %s is %s')%(str(notification), formats.date_format(meta, "SHORT_DATETIME_FORMAT")) | |
269 | 312 | else: |
270 | - message = _('Your goal to realize the task %s is %s')%(str(notification.task), formats.date_format(meta, "SHORT_DATETIME_FORMAT")) | |
313 | + message = _('Your goal to realize the task %s is %s')%(str(notification), formats.date_format(meta, "SHORT_DATETIME_FORMAT")) | |
314 | + | |
315 | + return JsonResponse({'error': False, 'message': message}) | |
316 | + | |
317 | +@log_decorator_ajax('pendencies', 'view', 'pendencies') | |
318 | +def pendencies_view_log(request, subject): | |
319 | + action = request.GET.get('action') | |
320 | + | |
321 | + if action == 'open': | |
322 | + subject = get_object_or_404(Subject, id = subject) | |
323 | + | |
324 | + log_context = {} | |
325 | + log_context['subject_id'] = subject.id | |
326 | + log_context['subject_name'] = subject.name | |
327 | + log_context['subject_slug'] = subject.slug | |
328 | + log_context['timestamp_start'] = str(int(time.time())) | |
329 | + log_context['timestamp_end'] = '-1' | |
330 | + | |
331 | + request.log_context = log_context | |
332 | + | |
333 | + log_id = Log.objects.latest('id').id | |
334 | + | |
335 | + return JsonResponse({'message': 'ok', 'log_id': log_id}) | |
336 | + | |
337 | + return JsonResponse({'message': 'ok'}) | |
338 | + | |
339 | +@log_decorator_ajax('pendencies', 'view_history', 'pendencies') | |
340 | +def pendencies_hist_log(request, subject): | |
341 | + action = request.GET.get('action') | |
342 | + | |
343 | + if action == 'open': | |
344 | + subject = get_object_or_404(Subject, id = subject) | |
345 | + | |
346 | + log_context = {} | |
347 | + log_context['subject_id'] = subject.id | |
348 | + log_context['subject_name'] = subject.name | |
349 | + log_context['subject_slug'] = subject.slug | |
350 | + log_context['timestamp_start'] = str(int(time.time())) | |
351 | + log_context['timestamp_end'] = '-1' | |
352 | + | |
353 | + request.log_context = log_context | |
354 | + | |
355 | + log_id = Log.objects.latest('id').id | |
356 | + | |
357 | + return JsonResponse({'message': 'ok', 'log_id': log_id}) | |
271 | 358 | |
272 | - return JsonResponse({'error': False, 'message': message}) | |
273 | 359 | \ No newline at end of file |
360 | + return JsonResponse({'message': 'ok'}) | |
274 | 361 | \ No newline at end of file | ... | ... |