Commit f90a61aceeb4fb953626983db6b0a63f509ec24d
1 parent
160dc1e7
Exists in
master
and in
2 other branches
criando a página de relatórios para link para arquivo
Showing
4 changed files
with
563 additions
and
2 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 filelink%} | |
| 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>{{filelink}} / {% 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 " %}{{filelink}}</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 'file_links:send_message' filelink.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 'file_links:send_message' filelink.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 %} | ... | ... |
file_link/urls.py
| ... | ... | @@ -8,4 +8,6 @@ urlpatterns = [ |
| 8 | 8 | url(r'^update/(?P<topic_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 | 10 | url(r'^download/(?P<slug>[\w_-]+)/$', views.DownloadFile.as_view(), name = 'download'), |
| 11 | + url(r'^chart/(?P<slug>[\w_-]+)/$', views.StatisticsView.as_view(), name = 'get_chart'), | |
| 12 | + url(r'^send-message/(?P<slug>[\w_-]+)/$', views.SendMessage.as_view(), name = 'send_message'), | |
| 11 | 13 | ] | ... | ... |
file_link/views.py
| ... | ... | @@ -18,6 +18,15 @@ from pendencies.forms import PendenciesForm |
| 18 | 18 | from .forms import FileLinkForm |
| 19 | 19 | from .models import FileLink |
| 20 | 20 | |
| 21 | + | |
| 22 | +import datetime | |
| 23 | +from log.models import Log | |
| 24 | +from chat.models import Conversation, TalkMessages | |
| 25 | +from users.models import User | |
| 26 | +from subjects.models import Subject | |
| 27 | + | |
| 28 | +from webpage.forms import FormModalMessage | |
| 29 | + | |
| 21 | 30 | class DownloadFile(LoginRequiredMixin, LogMixin, generic.DetailView): |
| 22 | 31 | log_component = 'resources' |
| 23 | 32 | log_action = 'view' |
| ... | ... | @@ -343,4 +352,144 @@ class DeleteView(LoginRequiredMixin, LogMixin, generic.DeleteView): |
| 343 | 352 | |
| 344 | 353 | super(DeleteView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) |
| 345 | 354 | |
| 346 | - return reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) | |
| 347 | 355 | \ No newline at end of file |
| 356 | + return reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) | |
| 357 | + | |
| 358 | + | |
| 359 | +class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | |
| 360 | + log_component = 'resources' | |
| 361 | + log_action = 'view_statistics' | |
| 362 | + log_resource = 'filelink' | |
| 363 | + log_context = {} | |
| 364 | + | |
| 365 | + login_url = reverse_lazy("users:login") | |
| 366 | + redirect_field_name = 'next' | |
| 367 | + model = FileLink | |
| 368 | + template_name = 'file_links/relatorios.html' | |
| 369 | + | |
| 370 | + def dispatch(self, request, *args, **kwargs): | |
| 371 | + slug = self.kwargs.get('slug', '') | |
| 372 | + filelink = get_object_or_404(FileLink, slug = slug) | |
| 373 | + | |
| 374 | + if not has_subject_permissions(request.user, filelink.topic.subject): | |
| 375 | + return redirect(reverse_lazy('subjects:home')) | |
| 376 | + | |
| 377 | + return super(StatisticsView, self).dispatch(request, *args, **kwargs) | |
| 378 | + | |
| 379 | + def get_context_data(self, **kwargs): | |
| 380 | + context = super(StatisticsView, self).get_context_data(**kwargs) | |
| 381 | + | |
| 382 | + self.log_context['category_id'] = self.object.topic.subject.category.id | |
| 383 | + self.log_context['category_name'] = self.object.topic.subject.category.name | |
| 384 | + self.log_context['category_slug'] = self.object.topic.subject.category.slug | |
| 385 | + self.log_context['subject_id'] = self.object.topic.subject.id | |
| 386 | + self.log_context['subject_name'] = self.object.topic.subject.name | |
| 387 | + self.log_context['subject_slug'] = self.object.topic.subject.slug | |
| 388 | + self.log_context['topic_id'] = self.object.topic.id | |
| 389 | + self.log_context['topic_name'] = self.object.topic.name | |
| 390 | + self.log_context['topic_slug'] = self.object.topic.slug | |
| 391 | + self.log_context['filelink_id'] = self.object.id | |
| 392 | + self.log_context['filelink_name'] = self.object.name | |
| 393 | + self.log_context['filelink_slug'] = self.object.slug | |
| 394 | + | |
| 395 | + super(StatisticsView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
| 396 | + | |
| 397 | + | |
| 398 | + context['title'] = _('File Link Reports') | |
| 399 | + | |
| 400 | + slug = self.kwargs.get('slug') | |
| 401 | + filelink = get_object_or_404(FileLink, slug = slug) | |
| 402 | + print (self.request.GET.get('init_date','')) | |
| 403 | + date_format = "%d/%m/%Y %H:%M" if self.request.GET.get('language','') == 'pt-br' else "%m/%d/%Y %I:%M %p" | |
| 404 | + if self.request.GET.get('language','') == "": | |
| 405 | + start_date = datetime.datetime.now() - datetime.timedelta(30) | |
| 406 | + end_date = datetime.datetime.now() | |
| 407 | + else : | |
| 408 | + start_date = datetime.datetime.strptime(self.request.GET.get('init_date',''),date_format) | |
| 409 | + end_date = datetime.datetime.strptime(self.request.GET.get('end_date',''),date_format) | |
| 410 | + context["init_date"] = start_date | |
| 411 | + context["end_date"] = end_date | |
| 412 | + alunos = filelink.students.all() | |
| 413 | + if filelink.all_students : | |
| 414 | + alunos = filelink.topic.subject.students.all() | |
| 415 | + | |
| 416 | + vis_ou = Log.objects.filter(context__contains={'filelink_id':filelink.id},resource="filelink",action="view",user_email__in=(aluno.email for aluno in alunos), datetime__range=(start_date,end_date + datetime.timedelta(minutes = 1))) | |
| 417 | + did,n_did,history = str(_("Realized")),str(_("Unrealized")),str(_("Historic")) | |
| 418 | + re = [] | |
| 419 | + data_n_did,data_history = [],[] | |
| 420 | + json_n_did, json_history = {},{} | |
| 421 | + | |
| 422 | + from django.db.models import Count, Max | |
| 423 | + views_user = vis_ou.values("user_email").annotate(views=Count("user_email")) | |
| 424 | + date_last = vis_ou.values("user_email").annotate(last=Max("datetime")) | |
| 425 | + | |
| 426 | + for log_al in vis_ou.order_by("datetime"): | |
| 427 | + data_history.append([str(alunos.get(email=log_al.user_email)), | |
| 428 | + ", ".join([str(x) for x in filelink.topic.subject.group_subject.filter(participants__email=log_al.user_email)]), | |
| 429 | + log_al.action,log_al.datetime]) | |
| 430 | + json_history["data"] = data_history | |
| 431 | + | |
| 432 | + not_view = alunos.exclude(email__in=[log.user_email for log in vis_ou.distinct("user_email")]) | |
| 433 | + index = 0 | |
| 434 | + for alun in not_view: | |
| 435 | + data_n_did.append([index,str(alun),", ".join([str(x) for x in filelink.topic.subject.group_subject.filter(participants__email=alun.email)]),str(_('View')), str(alun.email)]) | |
| 436 | + index += 1 | |
| 437 | + json_n_did["data"] = data_n_did | |
| 438 | + | |
| 439 | + | |
| 440 | + context["json_n_did"] = json_n_did | |
| 441 | + context["json_history"] = json_history | |
| 442 | + c_visualizou = vis_ou.distinct("user_email").count() | |
| 443 | + re.append([str(_('File link')),did,n_did]) | |
| 444 | + re.append([str(_('View')),c_visualizou, alunos.count() - c_visualizou]) | |
| 445 | + context['topic'] = filelink.topic | |
| 446 | + context['subject'] = filelink.topic.subject | |
| 447 | + context['db_data'] = re | |
| 448 | + context['title_chart'] = _('Actions about resource') | |
| 449 | + context['title_vAxis'] = _('Quantity') | |
| 450 | + | |
| 451 | + context["n_did_table"] = n_did | |
| 452 | + context["did_table"] = did | |
| 453 | + context["history_table"] = history | |
| 454 | + return context | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | +class SendMessage(LoginRequiredMixin, LogMixin, generic.edit.FormView): | |
| 459 | + log_component = 'resources' | |
| 460 | + log_action = 'send' | |
| 461 | + log_resource = 'filelink' | |
| 462 | + log_context = {} | |
| 463 | + | |
| 464 | + login_url = reverse_lazy("users:login") | |
| 465 | + redirect_field_name = 'next' | |
| 466 | + | |
| 467 | + template_name = 'file_links/send_message.html' | |
| 468 | + form_class = FormModalMessage | |
| 469 | + | |
| 470 | + def dispatch(self, request, *args, **kwargs): | |
| 471 | + slug = self.kwargs.get('slug', '') | |
| 472 | + filelink = get_object_or_404(FileLink, slug = slug) | |
| 473 | + self.filelink = filelink | |
| 474 | + | |
| 475 | + if not has_subject_permissions(request.user, filelink.topic.subject): | |
| 476 | + return redirect(reverse_lazy('subjects:home')) | |
| 477 | + | |
| 478 | + return super(SendMessage, self).dispatch(request, *args, **kwargs) | |
| 479 | + | |
| 480 | + def form_valid(self, form): | |
| 481 | + message = form.cleaned_data.get('comment') | |
| 482 | + image = form.cleaned_data.get("image") | |
| 483 | + users = (self.request.POST.get('users[]','')).split(",") | |
| 484 | + user = self.request.user | |
| 485 | + subject = self.filelink.topic.subject | |
| 486 | + for u in users: | |
| 487 | + to_user = User.objects.get(email=u) | |
| 488 | + talk, create = Conversation.objects.get_or_create(user_one=user,user_two=to_user) | |
| 489 | + created = TalkMessages.objects.create(text=message,talk=talk,user=user,subject=subject,image=image) | |
| 490 | + return JsonResponse({"message":"ok"}) | |
| 491 | + | |
| 492 | + def get_context_data(self, **kwargs): | |
| 493 | + context = super(SendMessage,self).get_context_data() | |
| 494 | + context["filelink"] = get_object_or_404(FileLink, slug=self.kwargs.get('slug', '')) | |
| 495 | + return context | |
| 496 | + | ... | ... |
topics/templates/resources/list.html
| ... | ... | @@ -29,7 +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 | - | |
| 32 | + {% if resource|class_name == 'filelink' %} | |
| 33 | + <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 | + {% endif %} | |
| 33 | 35 | {% if resource|class_name == 'webpage' %} |
| 34 | 36 | <li><a href="{% url 'webpages:get_chart' resource.slug %}" class="edit"><i class="fa fa-line-chart fa-fw" aria-hidden="true"></i>{% trans 'Reports' %}</a></li> |
| 35 | 37 | {% endif %} | ... | ... |