Commit b7b7e74522ed3ac46147b1fd0535d72094cbe226
1 parent
46dd7640
Exists in
master
and in
2 other branches
criando a página de relatórios para links
Showing
4 changed files
with
563 additions
and
1 deletions
Show diff stats
... | ... | @@ -0,0 +1,408 @@ |
1 | +{% extends "webpages/view.html" %} | |
2 | + | |
3 | +{% load static i18n pagination permissions_tags subject_counter %} | |
4 | +{% load django_bootstrap_breadcrumbs %} | |
5 | + | |
6 | +{% block javascript%} | |
7 | + {{ block.super }} | |
8 | + <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> | |
9 | + <script type="text/javascript"> | |
10 | + var tabela_atual = true; | |
11 | + | |
12 | + var array_history = []; | |
13 | + {%for data_json in json_history.data %} | |
14 | + array_history.push(["{{data_json.0}}","{{data_json.1}}","{{data_json.2}}",{% if data_json.3 is not None %}new Date('{{data_json.3.isoformat}}'){% else%}null{% endif %}]); | |
15 | + {% endfor%} | |
16 | + var json_history = {"data":array_history}; | |
17 | + var column_history = [{"string":'{% trans "User" %}'},{"string":'{% trans "Group" %}'},{"string":'{% trans "Action" %}'},{"date":'{% trans "Date of Action" %}'}]; | |
18 | + | |
19 | + var search = []; | |
20 | + for (var i in json_history["data"]){ | |
21 | + search.push([json_history["data"][i][0],json_history["data"][i][1], | |
22 | + json_history["data"][i][2],json_history["data"][i][3]]); | |
23 | + } | |
24 | + | |
25 | + var array_n_did = []; | |
26 | + var checkbox = {}; | |
27 | + {%for data_json in json_n_did.data%} | |
28 | + var input = '<div class="checkbox">\ | |
29 | + <label for="{{data_json.0}}_google_table">\ | |
30 | + <input id="{{data_json.0}}_google_table" name="{{data_json.0}}_google_table" type="checkbox"><span class="checkbox-material"><span class="check"></span></span>\ | |
31 | + </label>\ | |
32 | + </div>' | |
33 | + checkbox["{{data_json.0}}_google_table"] = "{{data_json.4}}"; | |
34 | + array_n_did.push([input,"{{data_json.1}}","{{data_json.2}}","{{data_json.3}}"]); | |
35 | + {% endfor%} | |
36 | + var json_n_did = {"data":array_n_did}; | |
37 | + var column_n_did = [{"string":'<a href="javascript:void(0);" onclick="return openmodal();"> {% trans "Send message" %}</a>'},{"string":'{% trans "User" %}'},{"string":'{% trans "Group" %}'},{"string":"{% trans "Action don't realized" %}"}]; | |
38 | + </script> | |
39 | + | |
40 | + | |
41 | + <script type="text/javascript"> | |
42 | + google.charts.load('current', {'packages':['corechart',"table"]}); | |
43 | + google.charts.setOnLoadCallback(drawChart); | |
44 | + google.charts.setOnLoadCallback(drawTable); | |
45 | + | |
46 | + function drawChart() { | |
47 | + var data = google.visualization.arrayToDataTable({{db_data|safe}}); | |
48 | + var options = { | |
49 | + title: '{{title_chart}}', | |
50 | + // legend: {position: 'right', maxLines: 1}, | |
51 | + bar: { groupWidth: '30%' }, | |
52 | + chartArea:{width:"50%"}, | |
53 | + titlePosition: 'out', | |
54 | + vAxis: { | |
55 | + title: '{{title_vAxis}}', | |
56 | + ticks: [0, .20, .40, .60, .80, 1], | |
57 | + viewWindow: { | |
58 | + min: 0, | |
59 | + max: 1 | |
60 | + } | |
61 | + }, | |
62 | + isStacked: "percent", | |
63 | + }; | |
64 | + | |
65 | + function selectHandler() { | |
66 | + var selectedItem = chart.getSelection()[0]; | |
67 | + if (selectedItem) { | |
68 | + var col = data.getColumnLabel(selectedItem.column); | |
69 | + if (col == "{{n_did_table}}"){ | |
70 | + tabela_atual = false; | |
71 | + search = []; | |
72 | + for (var i in json_n_did["data"]){ | |
73 | + search.push([json_n_did["data"][i][0],json_n_did["data"][i][1], | |
74 | + json_n_did["data"][i][2],json_n_did["data"][i][3]]); | |
75 | + } | |
76 | + searcher(col, tabela_atual,true); | |
77 | + | |
78 | + } else if (col == "{{did_table}}"){ | |
79 | + tabela_atual = true; | |
80 | + search = []; | |
81 | + for (var i in json_history["data"]){ | |
82 | + search.push([json_history["data"][i][0],json_history["data"][i][1], | |
83 | + json_history["data"][i][2],json_history["data"][i][3]]); | |
84 | + } | |
85 | + searcher(col, tabela_atual,true); | |
86 | + } | |
87 | + } | |
88 | + chart.setSelection([]) | |
89 | + } | |
90 | + | |
91 | + var chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); | |
92 | + google.visualization.events.addListener(chart, 'select', selectHandler); | |
93 | + chart.draw(data, options); | |
94 | + | |
95 | + } | |
96 | + | |
97 | + var sortAscending = {0:false,1:false,2:false,3:false}; | |
98 | + function drawTable(columns = column_history,rows = pagination(json_history["data"],1),isdate = true,columndate = 3) { | |
99 | + var data_table = new google.visualization.DataTable(); | |
100 | + for (var i in columns){ | |
101 | + for (var item in columns[i]){ | |
102 | + data_table.addColumn(item,columns[i][item]); | |
103 | + } | |
104 | + } | |
105 | + | |
106 | + data_table.addRows(rows); | |
107 | + var formate_date = new google.visualization.DateFormat({pattern: 'dd/MM/yyyy HH:mm'}); | |
108 | + if (isdate) formate_date.format(data_table, columndate); | |
109 | + | |
110 | + // var methods = []; | |
111 | + // for (var m in data_table) { | |
112 | + // if (typeof data_table[m] == "function") { | |
113 | + // methods.push(m); | |
114 | + // } | |
115 | + // } | |
116 | + // console.log(methods.join(",")); | |
117 | + var options = { | |
118 | + sort: "event", | |
119 | + allowHtml: true, | |
120 | + cssClassNames : { | |
121 | + tableRow: 'text-center', | |
122 | + tableCell: 'text-center', | |
123 | + headerCell: 'text-center' | |
124 | + }, | |
125 | + showRowNumber: true, | |
126 | + width: '100%', | |
127 | + height: '100%', | |
128 | + } | |
129 | + function ordenar(properties){ | |
130 | + var columnIndex = properties['column']; | |
131 | + if (columnIndex > 0) { | |
132 | + options["sortColumn"] = columnIndex; | |
133 | + options["sortAscending"] = sortAscending[columnIndex]; | |
134 | + data_table.sort({column:columnIndex,desc:sortAscending[columnIndex]}); | |
135 | + sortAscending = {0:false,1:false,2:false,3:false}; | |
136 | + sortAscending[columnIndex] = !sortAscending[columnIndex]; | |
137 | + // console.log(sortAscending); | |
138 | + table.draw(data_table, options); | |
139 | + } | |
140 | + } | |
141 | + | |
142 | + var table = new google.visualization.Table(document.getElementById('table_div')); | |
143 | + google.visualization.events.addListener(table, 'sort', function(e) {ordenar(e)}); | |
144 | + table.draw(data_table, options); | |
145 | + } | |
146 | + </script> | |
147 | +{% endblock%} | |
148 | + | |
149 | +{% block breadcrumbs %} | |
150 | + {{ block.super }} | |
151 | + {% trans 'Reports' as bread %} | |
152 | + {% breadcrumb bread link%} | |
153 | +{% endblock %} | |
154 | + | |
155 | +{% block content %} | |
156 | + {% if messages %} | |
157 | + {% for message in messages %} | |
158 | + <div class="alert alert-{{ message.tags }} alert-dismissible" role="alert"> | |
159 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
160 | + <span aria-hidden="true">×</span> | |
161 | + </button> | |
162 | + <p>{{ message }}</p> | |
163 | + </div> | |
164 | + {% endfor %} | |
165 | + {% endif %} | |
166 | + <div class="panel panel-info topic-panel"> | |
167 | + <div class="panel-heading"> | |
168 | + <div class="row"> | |
169 | + <div class="col-md-12 category-header"> | |
170 | + <h4 class="panel-title" style="margin-top: 10px; margin-bottom: 8px"> | |
171 | + <span>{{link}} / {% trans "Reports" %}</span> | |
172 | + </h4> | |
173 | + </div> | |
174 | + </div> | |
175 | + </div> | |
176 | + <div class="row"> | |
177 | + <div class="col-md-12 text-center"> | |
178 | + <h4 style="margin-top: 15px; margin-bottom: 10px" ><strong>{% trans "Report of the resource " %}{{link}}</strong></h4> | |
179 | + </div> | |
180 | + </div> | |
181 | + <div class="row"> | |
182 | + <div class="col-md-12"> | |
183 | + | |
184 | + <ul class="list-inline nav-justified"> | |
185 | + <div id="general-parameters-div"> | |
186 | + <div class="general-parameters-field"> | |
187 | + <li class="text-right"><h4>{% trans "Select the period: " %}</h4></li> | |
188 | + </div> | |
189 | + <form id="period-form" action="" method="get"> | |
190 | + <div class="general-parameters-field"> | |
191 | + <li> <input class="form-control datetime-picker" name="init_date" type="text" required="" value="{% if LANGUAGE_CODE == 'pt-br' %}{{init_date|date:'d/m/Y H:i'}} {% else %} {{init_date|date:'m/d/Y H:i P'}} {% endif %}"></li> | |
192 | + </div> | |
193 | + <div class="general-parameters-field"> | |
194 | + <li><input id="inputdate" class="form-control datetime-picker" name="end_date" type="text" required="" value="{% if LANGUAGE_CODE == 'pt-br' %}{{end_date|date:'d/m/Y H:i'}} {% else %} {{end_date|date:'m/d/Y H:i P'}} {% endif %}"></li> | |
195 | + </div> | |
196 | + <li><input type="submit" value="{% trans 'Search' %}" style="margin-left: 15px;" class="btn btn-success btn-raised"></li> | |
197 | + </form> | |
198 | + </div> | |
199 | + <ul> | |
200 | + </div> | |
201 | + </div> | |
202 | + | |
203 | + <div class="row"> | |
204 | + <div class="col-md-10 col-md-offset-1"> | |
205 | + <div id="chart_div" style="height: 500px; margin-top: -50px;"></div> | |
206 | + </div> | |
207 | + </div> | |
208 | + | |
209 | + <div class="row"> | |
210 | + <div class="col-md-10 col-md-offset-1"> | |
211 | + <div class="text-center"> | |
212 | + <ul class="list-inline nav-justified"> | |
213 | + <li> | |
214 | + <ul id="view-table" class="list-inline text-right"> | |
215 | + <li><h3 id="title-table"></h3></li> | |
216 | + </ul> | |
217 | + </li> | |
218 | + <li> | |
219 | + <ul class="list-inline text-right"> | |
220 | + <li><p>{% trans "Filter: " %}</p></li> | |
221 | + <li><input id="search-input" class="form-control" type="text" name="search" value=""></li> | |
222 | + </ul> | |
223 | + </li> | |
224 | + </ul> | |
225 | + </div> | |
226 | + <form id="google-chart-checkbox" action="" method="get"> | |
227 | + <div id="table_div"></div> | |
228 | + </form> | |
229 | + <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12 text-center"> | |
230 | + <ul class="pagination"> | |
231 | + | |
232 | + </ul> | |
233 | + </div> | |
234 | + </div> | |
235 | + </div> | |
236 | + <div id="modal-message"></div> | |
237 | + <div class="row"> | |
238 | + <br><br> | |
239 | + </div> | |
240 | + </div> | |
241 | + | |
242 | + <script type="text/javascript"> | |
243 | + | |
244 | + $("#title-table").text(search.length + " {% trans 'record(s)' %}"); | |
245 | + function putpagination(data = json_history["data"], load_histoty = true){ | |
246 | + var len = Math.ceil(data.length / 20); | |
247 | + $(".pagination").empty(); | |
248 | + $(".pagination").append('<li class="disabled"><span>«</span></li>'); | |
249 | + $(".pagination").append('<li id="1" class="active">\ | |
250 | + <a href="javascript:void(0);" onclick="return clickPagination(1, '+ load_histoty +');">1</a>\ | |
251 | + </li>'); | |
252 | + for (var i = 2; i <= len;i++){ | |
253 | + $(".pagination").append('<li id="' + i + '">\ | |
254 | + <a href="javascript:void(0);" onclick="return clickPagination(' + i +', ' + load_histoty + ');">' + i + '</a>\ | |
255 | + </li>'); | |
256 | + } | |
257 | + if (len > 1) $(".pagination").append('<li><a href="javascript:void(0);" onclick="return clickPagination(2, '+ load_histoty +');"><span>»</span></a></li>'); | |
258 | + else $(".pagination").append('<li class="disabled"><span>»</span></li>'); | |
259 | + }; | |
260 | + putpagination(); | |
261 | + | |
262 | + $('#period-form').submit(function(event) { | |
263 | + $('<input />').attr('type', 'hidden') | |
264 | + .attr('name', "language") | |
265 | + .attr('value', '{{ LANGUAGE_CODE }}') | |
266 | + .appendTo('#period-form'); | |
267 | + }); | |
268 | + function add(element,local, first = false){ | |
269 | + if (first) $(local).prepend(element); | |
270 | + else $(local).append(element); | |
271 | + } | |
272 | + function text(element){ | |
273 | + return $(element).text(); | |
274 | + } | |
275 | + function length(element) { | |
276 | + return $(element).length; | |
277 | + } | |
278 | + | |
279 | + $("#search-input").on("keyup",function(){ | |
280 | + search = []; | |
281 | + var text = $("#search-input").val(); | |
282 | + searcher(text,tabela_atual); | |
283 | + }); | |
284 | + | |
285 | + function searcher(text, load_histoty = false,apaga=false){ | |
286 | + if(apaga){ | |
287 | + $("#search-input").val(""); | |
288 | + } | |
289 | + var data = []; | |
290 | + if (!load_histoty){ | |
291 | + data = $.map(json_n_did["data"], function (obj) { | |
292 | + return $.extend(true, {}, obj); | |
293 | + }); | |
294 | + } else { | |
295 | + data = $.map(json_history["data"], function (obj) { | |
296 | + return $.extend(true, {}, obj); | |
297 | + }); | |
298 | + } | |
299 | + if (load_histoty){ | |
300 | + for (var i in data){ | |
301 | + data[i][3] = moment(data[i][3]).format("DD/MM/YYYY HH:mm"); | |
302 | + } | |
303 | + } | |
304 | + if (load_histoty){ | |
305 | + for (var i in data){ | |
306 | + if (data[i][0].toLowerCase().includes(text.toLowerCase()) | |
307 | + || data[i][1].toLowerCase().includes(text.toLowerCase()) | |
308 | + || data[i][2].toLowerCase().includes(text.toLowerCase()) | |
309 | + || data[i][3].toLowerCase().includes(text.toLowerCase())){ | |
310 | + search.push(json_history["data"][i]); | |
311 | + } | |
312 | + } | |
313 | + } | |
314 | + else { | |
315 | + for (var i in data){ | |
316 | + if (data[i][1].toLowerCase().includes(text.toLowerCase()) | |
317 | + || data[i][2].toLowerCase().includes(text.toLowerCase()) | |
318 | + || data[i][3].toLowerCase().includes(text.toLowerCase())){ | |
319 | + search.push(json_n_did["data"][i]); | |
320 | + } | |
321 | + } | |
322 | + } | |
323 | + console.log(search); | |
324 | + if (!load_histoty){ | |
325 | + drawTable(column_n_did,pagination(search,1),false); | |
326 | + } else { | |
327 | + drawTable(column_history,pagination(search,1),true,3); | |
328 | + } | |
329 | + $("#title-table").text(search.length + " {% trans 'record(s)' %}"); | |
330 | + putpagination(search,load_histoty); | |
331 | + } | |
332 | + | |
333 | + function pagination(data,pag){ | |
334 | + var len = data.length; | |
335 | + var first = (pag * 20 - 20 < len) ? pag * 20 - 20:len; | |
336 | + var end = (pag * 20 < len) ? pag * 20:len; | |
337 | + var search = data.slice(first,end); | |
338 | + return search; | |
339 | + } | |
340 | + | |
341 | + function clickPagination(pag, load_histoty = false){ | |
342 | + $(".pagination > li").last().remove(); | |
343 | + $(".pagination > li").first().remove(); | |
344 | + | |
345 | + if (!load_histoty){ | |
346 | + drawTable(column_n_did,pagination(search,pag),false); | |
347 | + } else { | |
348 | + drawTable(column_history,pagination(search,pag),true,3); | |
349 | + } | |
350 | + | |
351 | + if (pag < Math.ceil(search.length / 20)) | |
352 | + $(".pagination").append('<li><a href="javascript:void(0);" onclick="return clickPagination(' + (pag + 1) + ', '+ load_histoty +');"><span>»</span></a></li>'); | |
353 | + else $(".pagination").append('<li class="disabled"><span>»</span></li>'); | |
354 | + if (pag > 1) | |
355 | + $(".pagination").prepend('<li><a href="javascript:void(0);" onclick="return clickPagination(' + (pag - 1) + ', '+ load_histoty +');"><span>«</span></a></li>'); | |
356 | + else $(".pagination").prepend('<li class="disabled"><span>«</span></li>'); | |
357 | + $(".active").removeClass("active"); | |
358 | + $("#" + pag).addClass("active"); | |
359 | + } | |
360 | + | |
361 | + function openmodal(){ | |
362 | + $( "#modal-message" ).empty(); | |
363 | + $.get( "{% url 'links:send_message' link.slug %}", function( data ) { | |
364 | + $( "#modal-message" ).append( data ); | |
365 | + $("#send-message-modal").modal("show"); | |
366 | + }); | |
367 | + } | |
368 | + | |
369 | + function sendMessage(){ | |
370 | + $("#send-message-modal").modal("hide"); | |
371 | + var checked = $("#google-chart-checkbox").serializeArray(); | |
372 | + var email = []; | |
373 | + for (var i in checked){ | |
374 | + email.push(checkbox[checked[i]["name"]]); | |
375 | + } | |
376 | + $('<input />').attr('type', 'hidden') | |
377 | + .attr('name', "users[]") | |
378 | + .attr('value', email) | |
379 | + .appendTo('#text_chat_form'); | |
380 | + | |
381 | + var formData = new FormData($('#text_chat_form').get(0)); | |
382 | + $.ajax({ | |
383 | + url: "{% url 'links:send_message' link.slug %}", | |
384 | + type: "POST", | |
385 | + data: formData, | |
386 | + cache: false, | |
387 | + processData: false, | |
388 | + contentType: false, | |
389 | + success: function(data) { | |
390 | + if (data["message"]){ | |
391 | + console.log("success"); | |
392 | + $("body").removeClass("modal-open"); | |
393 | + $( "#modal-message" ).empty(); | |
394 | + $(".modal-backdrop.fade.in").remove(); | |
395 | + } else { | |
396 | + $( "#modal-message" ).empty(); | |
397 | + $(".modal-backdrop.fade.in").remove(); | |
398 | + $( "#modal-message" ).append( data ); | |
399 | + $("#send-message-modal").modal("show"); | |
400 | + } | |
401 | + }, | |
402 | + error: function(data){ | |
403 | + console.log("erro"); | |
404 | + } | |
405 | + }); | |
406 | + } | |
407 | + </script> | |
408 | +{% endblock %} | ... | ... |
links/urls.py
... | ... | @@ -7,4 +7,7 @@ urlpatterns = [ |
7 | 7 | url(r'^create/(?P<slug>[\w_-]+)/$', views.CreateLinkView.as_view(), name='create'), |
8 | 8 | url(r'^delete/(?P<slug>[\w_-]+)/$', views.DeleteLinkView.as_view(), name='delete'), |
9 | 9 | url(r'^update/(?P<topic_slug>[\w_-]+)/(?P<slug>[\w_-]+)/$', views.UpdateLinkView.as_view(), name='update'), |
10 | - url(r'^view/(?P<slug>[\w_-]+)/$', views.RedirectUrl.as_view(), name='view')] | |
11 | 10 | \ No newline at end of file |
11 | + url(r'^view/(?P<slug>[\w_-]+)/$', views.RedirectUrl.as_view(), name='view'), | |
12 | + url(r'^chart/(?P<slug>[\w_-]+)/$', views.StatisticsView.as_view(), name = 'get_chart'), | |
13 | + url(r'^send-message/(?P<slug>[\w_-]+)/$', views.SendMessage.as_view(), name = 'send_message'), | |
14 | +] | ... | ... |
links/views.py
... | ... | @@ -17,6 +17,14 @@ from pendencies.forms import PendenciesForm |
17 | 17 | from amadeus.permissions import has_subject_permissions, has_resource_permissions |
18 | 18 | |
19 | 19 | from topics.models import Topic |
20 | + | |
21 | +import datetime | |
22 | +from chat.models import Conversation, TalkMessages | |
23 | +from users.models import User | |
24 | +from subjects.models import Subject | |
25 | + | |
26 | +from webpage.forms import FormModalMessage | |
27 | + | |
20 | 28 | # Create your views here. |
21 | 29 | class CreateLinkView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
22 | 30 | log_component = 'resources' |
... | ... | @@ -325,3 +333,143 @@ class UpdateLinkView(LoginRequiredMixin, LogMixin, generic.edit.UpdateView): |
325 | 333 | messages.success(self.request, _('The Website Link "%s" was updated successfully!')%(self.object.name)) |
326 | 334 | |
327 | 335 | return reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) |
336 | + | |
337 | + | |
338 | +class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | |
339 | + log_component = 'resources' | |
340 | + log_action = 'view_statistics' | |
341 | + log_resource = 'link' | |
342 | + log_context = {} | |
343 | + | |
344 | + login_url = reverse_lazy("users:login") | |
345 | + redirect_field_name = 'next' | |
346 | + model = Link | |
347 | + template_name = 'links/relatorios.html' | |
348 | + | |
349 | + def dispatch(self, request, *args, **kwargs): | |
350 | + slug = self.kwargs.get('slug', '') | |
351 | + link = get_object_or_404(Link, slug = slug) | |
352 | + | |
353 | + if not has_subject_permissions(request.user, link.topic.subject): | |
354 | + return redirect(reverse_lazy('subjects:home')) | |
355 | + | |
356 | + return super(StatisticsView, self).dispatch(request, *args, **kwargs) | |
357 | + | |
358 | + def get_context_data(self, **kwargs): | |
359 | + context = super(StatisticsView, self).get_context_data(**kwargs) | |
360 | + | |
361 | + self.log_context['category_id'] = self.object.topic.subject.category.id | |
362 | + self.log_context['category_name'] = self.object.topic.subject.category.name | |
363 | + self.log_context['category_slug'] = self.object.topic.subject.category.slug | |
364 | + self.log_context['subject_id'] = self.object.topic.subject.id | |
365 | + self.log_context['subject_name'] = self.object.topic.subject.name | |
366 | + self.log_context['subject_slug'] = self.object.topic.subject.slug | |
367 | + self.log_context['topic_id'] = self.object.topic.id | |
368 | + self.log_context['topic_name'] = self.object.topic.name | |
369 | + self.log_context['topic_slug'] = self.object.topic.slug | |
370 | + self.log_context['link_id'] = self.object.id | |
371 | + self.log_context['link_name'] = self.object.name | |
372 | + self.log_context['link_slug'] = self.object.slug | |
373 | + | |
374 | + super(StatisticsView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
375 | + | |
376 | + | |
377 | + context['title'] = _('Links Reports') | |
378 | + | |
379 | + slug = self.kwargs.get('slug') | |
380 | + link = get_object_or_404(Link, slug = slug) | |
381 | + print (self.request.GET.get('init_date','')) | |
382 | + date_format = "%d/%m/%Y %H:%M" if self.request.GET.get('language','') == 'pt-br' else "%m/%d/%Y %I:%M %p" | |
383 | + if self.request.GET.get('language','') == "": | |
384 | + start_date = datetime.datetime.now() - datetime.timedelta(30) | |
385 | + end_date = datetime.datetime.now() | |
386 | + else : | |
387 | + start_date = datetime.datetime.strptime(self.request.GET.get('init_date',''),date_format) | |
388 | + end_date = datetime.datetime.strptime(self.request.GET.get('end_date',''),date_format) | |
389 | + context["init_date"] = start_date | |
390 | + context["end_date"] = end_date | |
391 | + alunos = link.students.all() | |
392 | + if link.all_students : | |
393 | + alunos = link.topic.subject.students.all() | |
394 | + | |
395 | + vis_ou = Log.objects.filter(context__contains={'link_id':link.id},resource="link",action="view",user_email__in=(aluno.email for aluno in alunos), datetime__range=(start_date,end_date + datetime.timedelta(minutes = 1))) | |
396 | + did,n_did,history = str(_("Realized")),str(_("Unrealized")),str(_("Historic")) | |
397 | + re = [] | |
398 | + data_n_did,data_history = [],[] | |
399 | + json_n_did, json_history = {},{} | |
400 | + | |
401 | + from django.db.models import Count, Max | |
402 | + views_user = vis_ou.values("user_email").annotate(views=Count("user_email")) | |
403 | + date_last = vis_ou.values("user_email").annotate(last=Max("datetime")) | |
404 | + | |
405 | + for log_al in vis_ou.order_by("datetime"): | |
406 | + data_history.append([str(alunos.get(email=log_al.user_email)), | |
407 | + ", ".join([str(x) for x in link.topic.subject.group_subject.filter(participants__email=log_al.user_email)]), | |
408 | + log_al.action,log_al.datetime]) | |
409 | + json_history["data"] = data_history | |
410 | + | |
411 | + not_view = alunos.exclude(email__in=[log.user_email for log in vis_ou.distinct("user_email")]) | |
412 | + index = 0 | |
413 | + for alun in not_view: | |
414 | + data_n_did.append([index,str(alun),", ".join([str(x) for x in link.topic.subject.group_subject.filter(participants__email=alun.email)]),str(_('View')), str(alun.email)]) | |
415 | + index += 1 | |
416 | + json_n_did["data"] = data_n_did | |
417 | + | |
418 | + | |
419 | + context["json_n_did"] = json_n_did | |
420 | + context["json_history"] = json_history | |
421 | + c_visualizou = vis_ou.distinct("user_email").count() | |
422 | + re.append([str(_('Links')),did,n_did]) | |
423 | + re.append([str(_('View')),c_visualizou, alunos.count() - c_visualizou]) | |
424 | + context['topic'] = link.topic | |
425 | + context['subject'] = link.topic.subject | |
426 | + context['db_data'] = re | |
427 | + context['title_chart'] = _('Actions about resource') | |
428 | + context['title_vAxis'] = _('Quantity') | |
429 | + | |
430 | + context["n_did_table"] = n_did | |
431 | + context["did_table"] = did | |
432 | + context["history_table"] = history | |
433 | + return context | |
434 | + | |
435 | + | |
436 | + | |
437 | +class SendMessage(LoginRequiredMixin, LogMixin, generic.edit.FormView): | |
438 | + log_component = 'resources' | |
439 | + log_action = 'send' | |
440 | + log_resource = 'link' | |
441 | + log_context = {} | |
442 | + | |
443 | + login_url = reverse_lazy("users:login") | |
444 | + redirect_field_name = 'next' | |
445 | + | |
446 | + template_name = 'links/send_message.html' | |
447 | + form_class = FormModalMessage | |
448 | + | |
449 | + def dispatch(self, request, *args, **kwargs): | |
450 | + slug = self.kwargs.get('slug', '') | |
451 | + link = get_object_or_404(Link, slug = slug) | |
452 | + self.link = link | |
453 | + | |
454 | + if not has_subject_permissions(request.user, link.topic.subject): | |
455 | + return redirect(reverse_lazy('subjects:home')) | |
456 | + | |
457 | + return super(SendMessage, self).dispatch(request, *args, **kwargs) | |
458 | + | |
459 | + def form_valid(self, form): | |
460 | + message = form.cleaned_data.get('comment') | |
461 | + image = form.cleaned_data.get("image") | |
462 | + users = (self.request.POST.get('users[]','')).split(",") | |
463 | + user = self.request.user | |
464 | + subject = self.link.topic.subject | |
465 | + for u in users: | |
466 | + to_user = User.objects.get(email=u) | |
467 | + talk, create = Conversation.objects.get_or_create(user_one=user,user_two=to_user) | |
468 | + created = TalkMessages.objects.create(text=message,talk=talk,user=user,subject=subject,image=image) | |
469 | + return JsonResponse({"message":"ok"}) | |
470 | + | |
471 | + def get_context_data(self, **kwargs): | |
472 | + context = super(SendMessage,self).get_context_data() | |
473 | + context["link"] = get_object_or_404(Link, slug=self.kwargs.get('slug', '')) | |
474 | + return context | |
475 | + | ... | ... |
topics/templates/resources/list.html
... | ... | @@ -29,6 +29,9 @@ |
29 | 29 | </button> |
30 | 30 | <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="moreResources"> |
31 | 31 | <li><a href="{% url resource.update_link topic.slug resource.slug %}" class="edit"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> |
32 | + {% if resource|class_name == 'link' %} | |
33 | + <li><a href="{% url 'links:get_chart' resource.slug %}" class="edit"><i class="fa fa-line-chart fa-fw" aria-hidden="true"></i>{% trans 'Reports' %}</a></li> | |
34 | + {% endif %} | |
32 | 35 | {% if resource|class_name == 'filelink' %} |
33 | 36 | <li><a href="{% url 'file_links:get_chart' resource.slug %}" class="edit"><i class="fa fa-line-chart fa-fw" aria-hidden="true"></i>{% trans 'Reports' %}</a></li> |
34 | 37 | {% endif %} | ... | ... |