Commit 0f135ea72625338c18f7aa52da8e8802926b5150
1 parent
aaba2230
Exists in
master
and in
2 other branches
colocando opção para enviar mensagens no pdf file
Showing
3 changed files
with
154 additions
and
63 deletions
Show diff stats
pdf_file/templates/pdf_file/relatorios.html
@@ -7,6 +7,7 @@ | @@ -7,6 +7,7 @@ | ||
7 | {{ block.super }} | 7 | {{ block.super }} |
8 | <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> | 8 | <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> |
9 | <script type="text/javascript"> | 9 | <script type="text/javascript"> |
10 | + var tabela_atual = true; | ||
10 | 11 | ||
11 | var array_history = []; | 12 | var array_history = []; |
12 | {%for data_json in json_history.data%} | 13 | {%for data_json in json_history.data%} |
@@ -22,11 +23,18 @@ | @@ -22,11 +23,18 @@ | ||
22 | } | 23 | } |
23 | 24 | ||
24 | var array_n_did = []; | 25 | var array_n_did = []; |
26 | + var checkbox = {}; | ||
25 | {%for data_json in json_n_did.data%} | 27 | {%for data_json in json_n_did.data%} |
26 | - array_n_did.push(['<input type="checkbox" value="">',"{{data_json.0}}","{{data_json.1}}", "{{data_json.2}}"]); | 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}}"]); | ||
27 | {% endfor%} | 35 | {% endfor%} |
28 | var json_n_did = {"data":array_n_did}; | 36 | var json_n_did = {"data":array_n_did}; |
29 | - var column_n_did = [{"string":'{% trans "Enviar mensagem" %}'},{"string":'{% trans "User" %}'},{"string":'{% trans "Group" %}'},{"string":"Action don't realized"}]; | 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":"Action don't realized"}]; |
30 | </script> | 38 | </script> |
31 | 39 | ||
32 | 40 | ||
@@ -58,38 +66,35 @@ | @@ -58,38 +66,35 @@ | ||
58 | var selectedItem = chart.getSelection()[0]; | 66 | var selectedItem = chart.getSelection()[0]; |
59 | if (selectedItem) { | 67 | if (selectedItem) { |
60 | var col = data.getColumnLabel(selectedItem.column); | 68 | var col = data.getColumnLabel(selectedItem.column); |
61 | - var element = '<li id="link-history">\ | ||
62 | - <a id="call-history" href="javascript:void(0);" onclick="return backhistory();"> <i class="fa fa-arrow-left ta-fw"> </i> {{history_table}}</a>\ | ||
63 | - </li>'; | ||
64 | - if (col == "{{n_did_table}}" && text("#title-table") != "{{n_did_table}}"){ | ||
65 | - if (length("#link-history") <= 0){ | ||
66 | - add(element,"#view-table",true); | ||
67 | - } | ||
68 | - altertitle("{{n_did_table}}"); | 69 | + if (col == "{{n_did_table}}"){ |
70 | + tabela_atual = false; | ||
69 | search = []; | 71 | search = []; |
70 | for (var i in json_n_did["data"]){ | 72 | for (var i in json_n_did["data"]){ |
71 | - search.push([json_n_did["data"][i][0],json_n_did["data"][i][1]]); | 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]]); | ||
72 | } | 75 | } |
73 | - drawTable(column_n_did,pagination(json_n_did["data"],1),false); | ||
74 | - putpagination(json_n_did["data"]); | 76 | + searcher(col, tabela_atual,true); |
75 | 77 | ||
76 | - } else if (col == "{{did_table}}" && text("#title-table") != "{{did_table}}"){ | 78 | + } else if (col == "{{did_table}}"){ |
79 | + tabela_atual = true; | ||
77 | search = []; | 80 | search = []; |
78 | for (var i in json_history["data"]){ | 81 | for (var i in json_history["data"]){ |
79 | search.push([json_history["data"][i][0],json_history["data"][i][1], | 82 | search.push([json_history["data"][i][0],json_history["data"][i][1], |
80 | json_history["data"][i][2],json_history["data"][i][3]]); | 83 | json_history["data"][i][2],json_history["data"][i][3]]); |
81 | } | 84 | } |
82 | - searcher(col, true); | 85 | + searcher(col, tabela_atual,true); |
83 | } | 86 | } |
84 | } | 87 | } |
85 | chart.setSelection([]) | 88 | chart.setSelection([]) |
86 | - } | 89 | + } |
87 | 90 | ||
88 | var chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); | 91 | var chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); |
89 | google.visualization.events.addListener(chart, 'select', selectHandler); | 92 | google.visualization.events.addListener(chart, 'select', selectHandler); |
90 | chart.draw(data, options); | 93 | chart.draw(data, options); |
91 | 94 | ||
92 | } | 95 | } |
96 | + | ||
97 | + var sortAscending = {0:false,1:false,2:false,3:false}; | ||
93 | function drawTable(columns = column_history,rows = pagination(json_history["data"],1),isdate = true,columndate = 3) { | 98 | function drawTable(columns = column_history,rows = pagination(json_history["data"],1),isdate = true,columndate = 3) { |
94 | var data_table = new google.visualization.DataTable(); | 99 | var data_table = new google.visualization.DataTable(); |
95 | for (var i in columns){ | 100 | for (var i in columns){ |
@@ -109,10 +114,33 @@ | @@ -109,10 +114,33 @@ | ||
109 | // } | 114 | // } |
110 | // } | 115 | // } |
111 | // console.log(methods.join(",")); | 116 | // console.log(methods.join(",")); |
112 | - | 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 | + } | ||
113 | var table = new google.visualization.Table(document.getElementById('table_div')); | 141 | var table = new google.visualization.Table(document.getElementById('table_div')); |
114 | - | ||
115 | - table.draw(data_table, {allowHtml: true, cssClassNames : {tableRow: 'text-center',tableCell: 'text-center', headerCell: 'text-center'},showRowNumber: true, width: '100%', height: '100%'}); | 142 | + google.visualization.events.addListener(table, 'sort', function(e) {ordenar(e)}); |
143 | + table.draw(data_table, options); | ||
116 | } | 144 | } |
117 | </script> | 145 | </script> |
118 | {% endblock%} | 146 | {% endblock%} |
@@ -148,25 +176,29 @@ | @@ -148,25 +176,29 @@ | ||
148 | <div class="col-md-12 text-center"> | 176 | <div class="col-md-12 text-center"> |
149 | <h4 style="margin-top: 15px; margin-bottom: 10px" ><strong>{% trans "Report of the resource " %}{{pdf_file}}</strong></h4> | 177 | <h4 style="margin-top: 15px; margin-bottom: 10px" ><strong>{% trans "Report of the resource " %}{{pdf_file}}</strong></h4> |
150 | </div> | 178 | </div> |
151 | - <div class="col-md-2 text-right"> | ||
152 | - <h4>{% trans "Select the period: " %}</h4> | ||
153 | - </div> | ||
154 | - <div class="col-md-8"> | 179 | + </div> |
180 | + <div class="row"> | ||
181 | + <div class="col-md-12"> | ||
182 | + | ||
183 | + <ul class="list-inline nav-justified"> | ||
155 | <div id="general-parameters-div"> | 184 | <div id="general-parameters-div"> |
185 | + <div class="general-parameters-field"> | ||
186 | + <li class="text-right"><h4>{% trans "Select the period: " %}</h4></li> | ||
187 | + </div> | ||
156 | <form id="period-form" action="" method="get"> | 188 | <form id="period-form" action="" method="get"> |
157 | <div class="general-parameters-field"> | 189 | <div class="general-parameters-field"> |
158 | - <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 %}"> | ||
159 | - </div> | ||
160 | - | ||
161 | - <div class="general-parameters-field"> | ||
162 | - {# <label class="form-field-report"> {% trans "Final Date" %} </label> #} | ||
163 | - <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 %}"> | ||
164 | - </div> | ||
165 | - <input type="submit" value="{% trans 'Search' %}" style="margin-left: 15px;" class="btn btn-success btn-raised"> | ||
166 | - </form> | 190 | + <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> |
191 | + </div> | ||
192 | + <div class="general-parameters-field"> | ||
193 | + <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> | ||
194 | + </div> | ||
195 | + <li><input type="submit" value="{% trans 'Search' %}" style="margin-left: 15px;" class="btn btn-success btn-raised"></li> | ||
196 | + </form> | ||
167 | </div> | 197 | </div> |
198 | + <ul> | ||
168 | </div> | 199 | </div> |
169 | </div> | 200 | </div> |
201 | + | ||
170 | <div class="row"> | 202 | <div class="row"> |
171 | <div class="col-md-10 col-md-offset-1"> | 203 | <div class="col-md-10 col-md-offset-1"> |
172 | <div id="chart_div" style="height: 500px; margin-top: -50px;"></div> | 204 | <div id="chart_div" style="height: 500px; margin-top: -50px;"></div> |
@@ -199,12 +231,44 @@ | @@ -199,12 +231,44 @@ | ||
199 | </div> | 231 | </div> |
200 | </div> | 232 | </div> |
201 | </div> | 233 | </div> |
234 | + <!-- Modal (remember to change the ids!!!) --> | ||
235 | + <div class="modal fade" id="send-message-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> | ||
236 | + <div class="modal-dialog" role="document"> | ||
237 | + <div class="modal-content"> | ||
238 | + <!-- Modal Body --> | ||
239 | + <div class="modal-body"> | ||
240 | + <!-- Put ONLY your content here!!! --> | ||
241 | + <h3>{% trans "Message: " %}</h3> | ||
242 | + <form id="text_chat_form" action="" method="GET"> | ||
243 | + <textarea id="message" name="message" rows="5" cols="80"></textarea> | ||
244 | + </form> | ||
245 | + </div> | ||
246 | + <!-- Modal Footer --> | ||
247 | + <div id="delete-category-footer"class="modal-footer"> | ||
248 | + <!-- Don't remove that!!! --> | ||
249 | + <button type="button" class="btn btn-default btn-raised" data-dismiss="modal">{% trans "Close" %}</button> | ||
250 | + <a href="javascript:void(0)" onclick="return sendMessage()" form="text_chat_form" class="btn btn-success btn-raised erase-button">{% trans "Send" %}</a> | ||
251 | + </div> | ||
252 | + </div> | ||
253 | + </div> | ||
254 | + </div> | ||
255 | + | ||
202 | <div class="row"> | 256 | <div class="row"> |
203 | <br><br> | 257 | <br><br> |
204 | </div> | 258 | </div> |
205 | </div> | 259 | </div> |
206 | 260 | ||
207 | <script type="text/javascript"> | 261 | <script type="text/javascript"> |
262 | + $('#message').summernote({ | ||
263 | + dialogsInBody: true, | ||
264 | + disableDragAndDrop: true, | ||
265 | + height: 150, | ||
266 | + toolbar: [ | ||
267 | + // [groupName, [list of button]] | ||
268 | + ['style', ['bold', 'italic']], | ||
269 | + ['insert', ['link']] | ||
270 | + ] | ||
271 | + }); | ||
208 | $("#title-table").text(search.length + " {% trans 'record(s)' %}"); | 272 | $("#title-table").text(search.length + " {% trans 'record(s)' %}"); |
209 | function putpagination(data = json_history["data"]){ | 273 | function putpagination(data = json_history["data"]){ |
210 | var len = Math.ceil(data.length / 20); | 274 | var len = Math.ceil(data.length / 20); |
@@ -229,9 +293,6 @@ | @@ -229,9 +293,6 @@ | ||
229 | .attr('value', '{{ LANGUAGE_CODE }}') | 293 | .attr('value', '{{ LANGUAGE_CODE }}') |
230 | .appendTo('#period-form'); | 294 | .appendTo('#period-form'); |
231 | }); | 295 | }); |
232 | - function altertitle(value) { | ||
233 | - $("#title-table").text(value); | ||
234 | - } | ||
235 | function add(element,local, first = false){ | 296 | function add(element,local, first = false){ |
236 | if (first) $(local).prepend(element); | 297 | if (first) $(local).prepend(element); |
237 | else $(local).append(element); | 298 | else $(local).append(element); |
@@ -242,30 +303,19 @@ | @@ -242,30 +303,19 @@ | ||
242 | function length(element) { | 303 | function length(element) { |
243 | return $(element).length; | 304 | return $(element).length; |
244 | } | 305 | } |
245 | - function backhistory(){ | ||
246 | - drawTable(column_history,json_history["data"],true,3); | ||
247 | - $("#link-history").remove(); | ||
248 | - search = []; | ||
249 | - for (var i in json_history["data"]){ | ||
250 | - search.push([json_history["data"][i][0],json_history["data"][i][1], | ||
251 | - json_history["data"][i][2],json_history["data"][i][3]]); | ||
252 | - } | ||
253 | - $("#title-table").text(search.length + " {% trans 'record(s)' %}"); | ||
254 | - putpagination(json_history["data"]); | ||
255 | - } | ||
256 | 306 | ||
257 | $("#search-input").on("keyup",function(){ | 307 | $("#search-input").on("keyup",function(){ |
258 | search = []; | 308 | search = []; |
259 | var text = $("#search-input").val(); | 309 | var text = $("#search-input").val(); |
260 | - searcher(text); | 310 | + searcher(text,tabela_atual); |
261 | }); | 311 | }); |
262 | 312 | ||
263 | - function searcher(text, load_histoty = false){ | ||
264 | - if (load_histoty){ | ||
265 | - $("#link-history").remove(); | 313 | + function searcher(text, load_histoty = false,apaga=false){ |
314 | + if(apaga){ | ||
315 | + $("#search-input").val(""); | ||
266 | } | 316 | } |
267 | var data = []; | 317 | var data = []; |
268 | - if ($("#title-table").text() == "{{n_did_table}}" && !load_histoty){ | 318 | + if (!load_histoty){ |
269 | data = $.map(json_n_did["data"], function (obj) { | 319 | data = $.map(json_n_did["data"], function (obj) { |
270 | return $.extend(true, {}, obj); | 320 | return $.extend(true, {}, obj); |
271 | }); | 321 | }); |
@@ -274,12 +324,12 @@ | @@ -274,12 +324,12 @@ | ||
274 | return $.extend(true, {}, obj); | 324 | return $.extend(true, {}, obj); |
275 | }); | 325 | }); |
276 | } | 326 | } |
277 | - if (load_histoty || $("#title-table").text() != "{{n_did_table}}"){ | 327 | + if (load_histoty){ |
278 | for (var i in data){ | 328 | for (var i in data){ |
279 | data[i][3] = moment(data[i][3]).format("DD/MM/YYYY HH:mm"); | 329 | data[i][3] = moment(data[i][3]).format("DD/MM/YYYY HH:mm"); |
280 | } | 330 | } |
281 | } | 331 | } |
282 | - if (load_histoty || $("#title-table").text() != "{{n_did_table}}"){ | 332 | + if (load_histoty){ |
283 | for (var i in data){ | 333 | for (var i in data){ |
284 | if (data[i][0].toLowerCase().includes(text.toLowerCase()) | 334 | if (data[i][0].toLowerCase().includes(text.toLowerCase()) |
285 | || data[i][1].toLowerCase().includes(text.toLowerCase()) | 335 | || data[i][1].toLowerCase().includes(text.toLowerCase()) |
@@ -291,20 +341,20 @@ | @@ -291,20 +341,20 @@ | ||
291 | } | 341 | } |
292 | else { | 342 | else { |
293 | for (var i in data){ | 343 | for (var i in data){ |
294 | - if (data[i][0].toLowerCase().includes(text.toLowerCase()) | ||
295 | - || data[i][1].toLowerCase().includes(text.toLowerCase())){ | 344 | + if (data[i][1].toLowerCase().includes(text.toLowerCase()) |
345 | + || data[i][2].toLowerCase().includes(text.toLowerCase()) | ||
346 | + || data[i][3].toLowerCase().includes(text.toLowerCase())){ | ||
296 | search.push(json_n_did["data"][i]); | 347 | search.push(json_n_did["data"][i]); |
297 | } | 348 | } |
298 | } | 349 | } |
299 | } | 350 | } |
300 | - if (!load_histoty && ($("#title-table").text() == "{{n_did_table}}")){ | 351 | + console.log(search); |
352 | + if (!load_histoty){ | ||
301 | drawTable(column_n_did,pagination(search,1),false); | 353 | drawTable(column_n_did,pagination(search,1),false); |
302 | } else { | 354 | } else { |
303 | drawTable(column_history,pagination(search,1),true,3); | 355 | drawTable(column_history,pagination(search,1),true,3); |
304 | } | 356 | } |
305 | - if (load_histoty || ($("#title-table").text() != "{{n_did_table}}")){ | ||
306 | - $("#title-table").text(search.length + " {% trans 'record(s)' %}"); | ||
307 | - } | 357 | + $("#title-table").text(search.length + " {% trans 'record(s)' %}"); |
308 | putpagination(search); | 358 | putpagination(search); |
309 | } | 359 | } |
310 | 360 | ||
@@ -315,11 +365,11 @@ | @@ -315,11 +365,11 @@ | ||
315 | var search = data.slice(first,end); | 365 | var search = data.slice(first,end); |
316 | return search; | 366 | return search; |
317 | } | 367 | } |
318 | - function clickPagination(pag){ | 368 | + function clickPagination(pag, load_histoty = false){ |
319 | $(".pagination > li").last().remove(); | 369 | $(".pagination > li").last().remove(); |
320 | $(".pagination > li").first().remove(); | 370 | $(".pagination > li").first().remove(); |
321 | 371 | ||
322 | - if (($("#title-table").text() == "{{n_did_table}}")){ | 372 | + if (!load_histoty){ |
323 | drawTable(column_n_did,pagination(search,pag),false); | 373 | drawTable(column_n_did,pagination(search,pag),false); |
324 | } else { | 374 | } else { |
325 | drawTable(column_history,pagination(search,pag),true,3); | 375 | drawTable(column_history,pagination(search,pag),true,3); |
@@ -334,5 +384,26 @@ | @@ -334,5 +384,26 @@ | ||
334 | $(".active").removeClass("active"); | 384 | $(".active").removeClass("active"); |
335 | $("#" + pag).addClass("active"); | 385 | $("#" + pag).addClass("active"); |
336 | } | 386 | } |
387 | + function sendMessage(){ | ||
388 | + $("#send-message-modal").modal("hide"); | ||
389 | + var checked = $("#google-chart-checkbox").serializeArray(); | ||
390 | + var email = []; | ||
391 | + for (var i in checked){ | ||
392 | + email.push(checkbox[checked[i]["name"]]); | ||
393 | + } | ||
394 | + var message = $("#text_chat_form").serializeArray()[0]["value"]; | ||
395 | + $.ajax({ | ||
396 | + type: "GET", | ||
397 | + data: {"message":message,"users[]":email}, | ||
398 | + url: "{% url 'pdf_files:send_message' subject.slug %}", | ||
399 | + success: function(msg){ | ||
400 | + console.log(msg); | ||
401 | + $('#message').summernote("reset"); | ||
402 | + } | ||
403 | + }); | ||
404 | + } | ||
405 | + function openmodal(){ | ||
406 | + $("#send-message-modal").modal("show"); | ||
407 | + } | ||
337 | </script> | 408 | </script> |
338 | {% endblock %} | 409 | {% endblock %} |
pdf_file/urls.py
@@ -9,4 +9,5 @@ urlpatterns = [ | @@ -9,4 +9,5 @@ urlpatterns = [ | ||
9 | url(r'^delete/(?P<slug>[\w_-]+)/$', views.DeleteView.as_view(), name = 'delete'), | 9 | url(r'^delete/(?P<slug>[\w_-]+)/$', views.DeleteView.as_view(), name = 'delete'), |
10 | url(r'^view/(?P<slug>[\w_-]+)/$', views.ViewPDFFile.as_view(), name = 'view'), | 10 | url(r'^view/(?P<slug>[\w_-]+)/$', views.ViewPDFFile.as_view(), name = 'view'), |
11 | url(r'^chart/(?P<slug>[\w_-]+)/$', views.StatisticsView.as_view(), name = 'get_chart'), | 11 | url(r'^chart/(?P<slug>[\w_-]+)/$', views.StatisticsView.as_view(), name = 'get_chart'), |
12 | + url(r'^send-message/(?P<slug>[\w_-]+)/$', views.sendMessage, name = 'send_message'), | ||
12 | ] | 13 | ] |
pdf_file/views.py
@@ -428,8 +428,10 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | @@ -428,8 +428,10 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | ||
428 | json_history["data"] = data_history | 428 | json_history["data"] = data_history |
429 | 429 | ||
430 | not_view = alunos.exclude(email__in=[log.user_email for log in vis_ou.distinct("user_email")]) | 430 | not_view = alunos.exclude(email__in=[log.user_email for log in vis_ou.distinct("user_email")]) |
431 | + index = 0 | ||
431 | for alun in not_view: | 432 | for alun in not_view: |
432 | - data_n_did.append([str(alun),", ".join([str(x) for x in pdf_file.topic.subject.group_subject.filter(participants__email=alun.email)]),str(_('View'))]) | 433 | + data_n_did.append([index,str(alun),", ".join([str(x) for x in pdf_file.topic.subject.group_subject.filter(participants__email=alun.email)]),str(_('View')), str(alun.email)]) |
434 | + index += 1 | ||
433 | json_n_did["data"] = data_n_did | 435 | json_n_did["data"] = data_n_did |
434 | 436 | ||
435 | 437 | ||
@@ -441,10 +443,27 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | @@ -441,10 +443,27 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | ||
441 | context['topic'] = pdf_file.topic | 443 | context['topic'] = pdf_file.topic |
442 | context['subject'] = pdf_file.topic.subject | 444 | context['subject'] = pdf_file.topic.subject |
443 | context['db_data'] = re | 445 | context['db_data'] = re |
444 | - context['title_chart'] = _('Students viewing the PDF File') | 446 | + context['title_chart'] = _('Actions about resource') |
445 | context['title_vAxis'] = _('Quantity') | 447 | context['title_vAxis'] = _('Quantity') |
446 | 448 | ||
447 | context["n_did_table"] = n_did | 449 | context["n_did_table"] = n_did |
448 | context["did_table"] = did | 450 | context["did_table"] = did |
449 | context["history_table"] = history | 451 | context["history_table"] = history |
450 | return context | 452 | return context |
453 | + | ||
454 | + | ||
455 | +from chat.models import Conversation, TalkMessages | ||
456 | +from users.models import User | ||
457 | +from subjects.models import Subject | ||
458 | +def sendMessage(request, slug): | ||
459 | + message = request.GET.get('message','') | ||
460 | + users = request.GET.getlist('users[]','') | ||
461 | + user = request.user | ||
462 | + subject = get_object_or_404(Subject,slug = slug) | ||
463 | + | ||
464 | + for u in users: | ||
465 | + to_user = User.objects.get(email=u) | ||
466 | + talk, create = Conversation.objects.get_or_create(user_one=user,user_two=to_user) | ||
467 | + created = TalkMessages.objects.create(text=message,talk=talk,user=user,subject=subject) | ||
468 | + | ||
469 | + return JsonResponse({"message":"ok"}) |