diff options
author | katkamrachana <katkam.rachana@gmail.com> | 2015-06-05 18:25:52 +0530 |
---|---|---|
committer | katkamrachana <katkam.rachana@gmail.com> | 2015-06-05 18:25:52 +0530 |
commit | 9938c6091180ab0c31799a00c731504411b53c05 (patch) | |
tree | 86be7c1cbef34bb0013f6dc29a1effc708ba3382 /gnowsys-ndf | |
parent | 7ba84cd193f9cffc086069c23387b70c4f401959 (diff) | |
download | gnowsys-9938c6091180ab0c31799a00c731504411b53c05.tar.gz |
MIS Reports for Event
Diffstat (limited to 'gnowsys-ndf')
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/mis_list.html | 15 | ||||
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/mis_report.html | 713 | ||||
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/urls/ajax-urls.py | 1 | ||||
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py | 233 |
4 files changed, 651 insertions, 311 deletions
diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/mis_list.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/mis_list.html index bdc109d..47a56fc 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/mis_list.html +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/mis_list.html @@ -106,17 +106,14 @@ {{each.name}} {% endif %} </div> - </li> + </li> - {% endfor %} + {% endfor %} </ul> {% endblock %} {% block body_content %} {% if title == "MIS" %} - <div> - <a href="{% url 'mis:get_mis_reports' group_id %}">REPORTS</a> - </div> <div class="row"> <div class="small-12 small-centered columns"> @@ -164,6 +161,11 @@ </div> </div> + <div> + <span class="button small"> + <a href="{% url 'mis:get_mis_reports' group_id %}" style="float:right;color:white;">MIS REPORTS</a> + </span> + </div> <div class="small-4 columns end"> <ul> {% for university_name, students_count in university_wise_students_count %} @@ -176,6 +178,7 @@ {% endfor %} </ul> </div> + </div> <!-- Hidden Accordion for University listing --> @@ -656,4 +659,4 @@ return datesList; } -{% endblock %} +{% endblock %} diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/mis_report.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/mis_report.html index f6adc74..5b5f588 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/mis_report.html +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/mis_report.html @@ -15,6 +15,7 @@ <link rel="stylesheet" href="/static/ndf/bower_components/jqueryui-timepicker-addon/dist/jquery-ui-timepicker-addon.css"> <!-- checked --> <link rel="stylesheet" href="/static/ndf/bower_components/jquery-ui/themes/smoothness/jquery-ui.css"> <!-- checked --> + <script sync="text/javascript" src="/static/ndf/bower_components/FileSaver/FileSaver.js" async></script> <!-- checked --> <!-- DataTables --> <script src="/static/ndf/bower_components/DataTables/media/js/jquery.dataTables.js"></script> @@ -25,13 +26,13 @@ {% block style %} {{block.super}} - fieldset{ - border: 1px solid #0b8a91 !important; - width: inherit; - } + fieldset{ + border: 1px solid #0b8a91 !important; + width: inherit; + } .total_val{ - cursor:pointer; + cursor:pointer; } {% endblock %} @@ -43,126 +44,126 @@ </div> {{app_id}} - <div class="row"> - <div style="text-align: center;"> - <div class="small-4 columns end" style="display: inline-block; "> - <h4>{% trans 'Report of :' %}</h4> - </div> - <div class="small-4 columns end" style="display: inline-block; "> - <select id="fetchDataOf"> - <option value="">{% trans '- - - Select - - -' %}</option> - <option id="student">{% trans 'Student' %}</option> - <option id="event">{% trans 'Event' %}</option> - <option id="vt">{% trans 'Voluntary Trainer' %}</option> - </select> - </div> - </div> - </div> - - - - <fieldset> - <legend> - <label>{% trans 'Filters' %}</label> - </legend> - <div class="row"> - <div class="small-4 columns end"> - <label>{% trans 'State :' %}</label> - </div> - <div class="small-8 columns end"> - <select id="state_list"> - </select> - </div> - </div> - <div class="row"> - <div class="small-4 columns end"> - <label>{% trans 'University :' %}</label> - </div> - <div class="small-8 columns end"> - <select id="univ_list" disabled="disabled"> - </select> - </div> - </div> - <div class="row"> - <div class="small-4 columns end"> - <label>{% trans 'College :' %}</label> - </div> - <div class="small-8 columns end"> - <select id="colg_list" disabled="disabled"> - </select> - </div> - </div> - </fieldset> - - <fieldset class="event_duration hide"> - <div class="row"> - <div class="small-6 columns"> - <div class="small-2 columns end"> - <label>{% trans 'From :' %}</label> - </div> - <div class="small-4 columns end"> - <input type="text" id="event_start" name="event_start" value="" placeholder="DD/MM/YYYY" readonly="" required="" class="date_month_day_year" style="float:left; width:10rem"> - </div> - </div> - <div class="small-6 columns"> - <div class="small-2 columns end"> - <label>{% trans 'To :' %}</label> - </div> - <div class="small-4 columns end"> - <input type="text" id="event_end" name="event_end" value="" placeholder="DD/MM/YYYY" readonly="" required="" class="date_month_day_year" style="float:left; width:10rem"> - </div> - </div> - </div> - - </fieldset> - - <fieldset class="ac_year hide"> - <div class="row"> - <div class="small-4 columns end"> - <label>{% trans 'Registration Year :' %}</label> - </div> - <div class="small-8 columns end"> - <select id="ac_year_list"> - <option value="">{% trans '- - - Select Year - - -' %}</option> - <option value="2013">{% trans '2013' %}</option> - <option value="2014">{% trans '2014' %}</option> - <option value="2015">{% trans '2015' %}</option> - <option value="ALL">{% trans 'ALL' %}</option> - </select> - </div> - </div> - </fieldset> - - <div class="row"> - <input type="button" class="button" value="FIND" id="get_reports_btn" style="margin-left:30.25em" disabled="disabled"> - </div> - - <div id="report1"></div> - <div id="report2"></div> + <div class="row"> + <div style="text-align: center;"> + <div class="small-4 columns end" style="display: inline-block; "> + <h4>{% trans 'Report of :' %}</h4> + </div> + <div class="small-4 columns end" style="display: inline-block; "> + <select id="fetchDataOf"> + <option value="">{% trans '- - - Select - - -' %}</option> + <option id="student">{% trans 'Student' %}</option> + <option id="event">{% trans 'Event' %}</option> + <option id="vt">{% trans 'Voluntary Teacher' %}</option> + </select> + </div> + </div> + </div> + + + + <fieldset> + <legend> + <label>{% trans 'Filters' %}</label> + </legend> + <div class="row"> + <div class="small-4 columns end"> + <label>{% trans 'State :' %}</label> + </div> + <div class="small-8 columns end"> + <select id="state_list"> + </select> + </div> + </div> + <div class="row"> + <div class="small-4 columns end"> + <label>{% trans 'University :' %}</label> + </div> + <div class="small-8 columns end"> + <select id="univ_list" disabled="disabled"> + </select> + </div> + </div> + <div class="row"> + <div class="small-4 columns end"> + <label>{% trans 'College :' %}</label> + </div> + <div class="small-8 columns end"> + <select id="colg_list" disabled="disabled"> + </select> + </div> + </div> + </fieldset> + + <fieldset class="event_duration hide"> + <div class="row"> + <div class="small-6 columns"> + <div class="small-2 columns end"> + <label>{% trans 'From :' %}</label> + </div> + <div class="small-4 columns end"> + <input type="text" id="event_start" name="event_start" value="" placeholder="DD/MM/YYYY" readonly="" required="" class="date_month_day_year" style="float:left; width:10rem"> + </div> + </div> + <div class="small-6 columns"> + <div class="small-2 columns end"> + <label>{% trans 'To :' %}</label> + </div> + <div class="small-4 columns end"> + <input type="text" id="event_end" name="event_end" value="" placeholder="DD/MM/YYYY" readonly="" required="" class="date_month_day_year" style="float:left; width:10rem"> + </div> + </div> + </div> + + </fieldset> + + <fieldset class="ac_year hide"> + <div class="row"> + <div class="small-4 columns end"> + <label>{% trans 'Registration Year :' %}</label> + </div> + <div class="small-8 columns end"> + <select id="ac_year_list"> + <option value="">{% trans '- - - Select Year - - -' %}</option> + <option value="2013">{% trans '2013' %}</option> + <option value="2014">{% trans '2014' %}</option> + <option value="2015">{% trans '2015' %}</option> + <option value="ALL">{% trans 'ALL' %}</option> + </select> + </div> + </div> + </fieldset> + + <div class="row"> + <input type="button" class="button" value="FIND" id="get_reports_btn" style="margin-left:30.25em" disabled="disabled"> + </div> + + <div id="report1"></div> + <div id="report2"></div> {% endblock %} {% block script %} - //<script> + //<script> $("select#fetchDataOf").change(function() { - sel_type = $("select#fetchDataOf").val(); - $("#event_start").val(''); - $("#event_end").val(''); - $("select#univ_list").attr("disabled",true).empty(); - $("select#colg_list").attr("disabled",true).empty(); - $("select#state_list").prop("selectedIndex", 0); - - $("#ac_year_list").val('') - if (sel_type == "Student"){ - $(".ac_year").removeClass("hide"); - $(".event_duration").addClass("hide") - } - else{ - $(".ac_year").addClass("hide").val(''); - $(".event_duration").removeClass("hide") - } + sel_type = $("select#fetchDataOf").val(); + $("#event_start").val(''); + $("#event_end").val(''); + $("select#univ_list").attr("disabled",true).empty(); + $("select#colg_list").attr("disabled",true).empty(); + $("select#state_list").prop("selectedIndex", 0); + + $("#ac_year_list").val('') + if (sel_type == "Student"){ + $(".ac_year").removeClass("hide"); + $(".event_duration").addClass("hide") + } + else{ + $(".ac_year").addClass("hide").val(''); + $(".event_duration").removeClass("hide") + } }); $("select#state_list").change(function() { // Get selected State's value (ObjectId) and selected-index @@ -196,7 +197,7 @@ } else { - $("#get_reports_btn").removeAttr("disabled"); + $("#get_reports_btn").removeAttr("disabled"); // First empty all values of Univ field (dropdown/select) $("select#univ_list").empty(); @@ -219,11 +220,11 @@ ); }); - $("select#univ_list").append( - $("<option></option>") - .attr("value", "ALL") - .text("ALL") - ); + $("select#univ_list").append( + $("<option></option>") + .attr("value", "ALL") + .text("ALL") + ); // Set very first entry so that user doesn't forgets to select a value @@ -265,7 +266,7 @@ success_state = data["success"]; if (success_state) { - $("select#colg_list").removeAttr('disabled') + $("select#colg_list").removeAttr('disabled') // First empty all values of College field (dropdown/select) $("select#colg_list").empty(); @@ -285,11 +286,11 @@ ); }); - $("select#colg_list").append( - $("<option></option>") - .attr("value", "ALL") - .text("ALL") - ); + $("select#colg_list").append( + $("<option></option>") + .attr("value", "ALL") + .text("ALL") + ); // Set very first entry so that user doesn't forgets to select a value @@ -312,130 +313,229 @@ } }); - $(document).on("click", ".total_val", function() { - query_data = $(this).attr('data-query'); - $.ajax({ - url:"{% url 'get_students' groupid %}", - - data: { - 'query': query_data, - 'gst_name':gst_name, - 'csrfmiddlewaretoken': "{{csrf_token}}" - }, - - type: "POST", - - dataType: "json", + $(document).on("click", ".total_val", function() { + gst_name = $("#fetchDataOf").val() + if(gst_name == "Student"){ + query_data = $(this).attr('data-query'); + $.ajax({ + url:"{% url 'get_students' groupid %}", + + data: { + 'query': query_data, + 'gst_name':gst_name, + 'csrfmiddlewaretoken': "{{csrf_token}}" + }, + + type: "POST", + + dataType: "json", + + success: function(data) { + success_state = data["success"]; + $("#alertModalLabel").text(data["message"]); + + if (success_state) { + // $("#report2").html(data["students_data_review"]); + + groupid_val = data["groupid"]; + app_id_val = data["app_id"]; + app_set_id_val = data["app_set_id"]; + var caption_college = "" + var caption_university = "" + filename = data["filename"]; + if (data.hasOwnProperty("university")){ + university = data["university"]; + caption_university = '<h4>' + university + '</h4>'; + } + if (data.hasOwnProperty("college")){ + college = data["college"]; + caption_college = '<h3>' + college + '</h3>'; + } + students_count = data["students_count"]; + column_headers = data["column_headers"]; + students_data_set = data["students_data_set"]; + dataTable_columns_set = []; + download_link = "{% static 'filename' %}".replace('filename', filename); + + if (parseInt(students_count) <= 0) { + c = '<div class="row">' + + '<div class="large-4 large-centered columns">' + + '<p class="alert-box alert radius text-center text-size-15">No records match the given criteria !!!</p>' + + '</div>' + + '</div>' + $("#report2").html(c); + } - success: function(data) { - success_state = data["success"]; - $("#alertModalLabel").text(data["message"]); + else { + // Define table + student_data_table = '<table cellpadding="0" cellspacing="0" border="0" class="display" id="student_data_table">' + + '<caption>' + + caption_college + + caption_university + + '<h6>Total No. of Students Registered: <b>' + students_count + '</b></h6>' + + '<a href="' + download_link + '" download="">' + + '<span class="fi-download large"> Download Students\' data (CSV)</span>' + + '</a>' + + '</caption>' + + '</table>'; + $("#report2").html(student_data_table); + + // Prepare title & data headers used in dataTable + $.each(column_headers, function(index, v) { + d = {}; + d["data"] = v[0]; + d["title"] = v[1]; + dataTable_columns_set.push(d); + }); + + // Set defintion dataTable + sce_dt_var = $("#student_data_table").dataTable({ + "data": students_data_set, + "columns": dataTable_columns_set, + "createdRow": function ( row, data, index ) { + // Attaching Student's ObjectId to each row (i.e., assigning to it's id attribute) + s_id = data["stud_id"]; + $(row).attr("id", s_id); + edit_url = "{% url 'mis:mis_app_instance_edit' 'groupid' 'app_id' 'app_set_id' 'stud_id' %}".replace("groupid", groupid_val).replace("app_id", app_id_val).replace("app_set_id", app_set_id_val).replace("stud_id", s_id); + name = data['Name'] + + $(row).find("td:nth-child(3)").html("<a href='" + edit_url + "'>"+name+"</a>"); + } + }); + } + } + else { + $("#alertModal").removeClass("success").removeClass("warning"); + $("#alertModal").addClass("alert"); + $("#alertModal").foundation('reveal', 'open'); + } + }, + }); + } + else{ + query_data = $(this).attr('data-query'); + $.ajax({ + url:"{% url 'get_events' groupid %}", + + data: { + 'query': query_data, + 'gst_name':gst_name, + 'csrfmiddlewaretoken': "{{csrf_token}}" + }, + + type: "POST", + + dataType: "json", + + success: function(data) { + success_state = data["success"]; + $("#alertModalLabel").text(data["message"]); + + if (success_state) { + // $("#report2").html(data["students_data_review"]); + + groupid_val = data["groupid"]; + app_id_val = data["app_id"]; + app_set_id_val = data["app_set_id"]; + var caption_college = "" + var caption_university = "" + filename = data["filename"]; + if (data.hasOwnProperty("university")){ + university = data["university"]; + caption_university = '<h4>' + university + '</h4>'; + } + if (data.hasOwnProperty("college")){ + college = data["college"]; + caption_college = '<h3>' + college + '</h3>'; + } + students_count = data["students_count"]; + column_headers = data["column_headers"]; + students_data_set = data["students_data_set"]; + dataTable_columns_set = []; + download_link = "{% static 'filename' %}".replace('filename', filename); + + if (parseInt(students_count) <= 0) { + c = '<div class="row">' + + '<div class="large-4 large-centered columns">' + + '<p class="alert-box alert radius text-center text-size-15">No records match the given criteria !!!</p>' + + '</div>' + + '</div>' + $("#report2").html(c); + } - if (success_state) { - // $("#report2").html(data["students_data_review"]); - - groupid_val = data["groupid"]; - app_id_val = data["app_id"]; - app_set_id_val = data["app_set_id"]; - var caption_college = "" - var caption_university = "" - filename = data["filename"]; - if (data.hasOwnProperty("university")){ - university = data["university"]; - caption_university = '<h4>' + university + '</h4>'; - } - if (data.hasOwnProperty("college")){ - college = data["college"]; - caption_college = '<h3>' + college + '</h3>'; - } - students_count = data["students_count"]; - column_headers = data["column_headers"]; - students_data_set = data["students_data_set"]; - dataTable_columns_set = []; - download_link = "{% static 'filename' %}".replace('filename', filename); - - if (parseInt(students_count) <= 0) { - c = '<div class="row">' + - '<div class="large-4 large-centered columns">' + - '<p class="alert-box alert radius text-center text-size-15">No records match the given criteria !!!</p>' + - '</div>' + - '</div>' - $("#report2").html(c); - } - - else { - // Define table - student_data_table = '<table cellpadding="0" cellspacing="0" border="0" class="display" id="student_data_table">' + - '<caption>' + - caption_college + - caption_university + - '<h6>Total No. of Students Registered: <b>' + students_count + '</b></h6>' + - '<a href="' + download_link + '" download="">' + - '<span class="fi-download large"> Download Students\' data (CSV)</span>' + - '</a>' + - '</caption>' + - '</table>'; - $("#report2").html(student_data_table); - - // Prepare title & data headers used in dataTable - $.each(column_headers, function(index, v) { - d = {}; - d["data"] = v[0]; - d["title"] = v[1]; - dataTable_columns_set.push(d); - }); - - // Set defintion dataTable - sce_dt_var = $("#student_data_table").dataTable({ - "data": students_data_set, - "columns": dataTable_columns_set, - "createdRow": function ( row, data, index ) { - // Attaching Student's ObjectId to each row (i.e., assigning to it's id attribute) - s_id = data["stud_id"]; - $(row).attr("id", s_id); - edit_url = "{% url 'mis:mis_app_instance_edit' 'groupid' 'app_id' 'app_set_id' 'stud_id' %}".replace("groupid", groupid_val).replace("app_id", app_id_val).replace("app_set_id", app_set_id_val).replace("stud_id", s_id); - name = data['Name'] + else { + // Define table + student_data_table = '<table cellpadding="0" cellspacing="0" border="0" class="display" id="student_data_table">' + + '<caption>' + + caption_college + + caption_university + + '<h6>Total No. of Students Registered: <b>' + students_count + '</b></h6>' + + '<a href="' + download_link + '" download="">' + + '<span class="fi-download large"> Download Students\' data (CSV)</span>' + + '</a>' + + '</caption>' + + '</table>'; + $("#report2").html(student_data_table); - $(row).find("td:nth-child(3)").html("<a href='" + edit_url + "'>"+name+"</a>"); + // Prepare title & data headers used in dataTable + $.each(column_headers, function(index, v) { + d = {}; + d["data"] = v[0]; + d["title"] = v[1]; + dataTable_columns_set.push(d); + }); + + // Set defintion dataTable + sce_dt_var = $("#student_data_table").dataTable({ + "data": students_data_set, + "columns": dataTable_columns_set, + "columnDefs": [{ "width": "15%", "targets": 0 }], + "createdRow": function ( row, data, index ) { + // Attaching Student's ObjectId to each row (i.e., assigning to it's id attribute) + s_id = data["stud_id"]; + $(row).attr("id", s_id); + detail_url = "{% url 'event_app_instance_detail' groupid 'app_set_id' 'stud_id' %}".replace("groupid", groupid_val).replace("app_set_id", app_set_id_val).replace("stud_id", s_id); + $(row).find("td:nth-child(3)").html("<a href='" + detail_url + "' target='_blank'>"+data['Name']+"</a>"); + } + }); } - }); - } - } - else { - $("#alertModal").removeClass("success").removeClass("warning"); - $("#alertModal").addClass("alert"); - $("#alertModal").foundation('reveal', 'open'); - } - }, - }); + } + else { + $("#alertModal").removeClass("success").removeClass("warning"); + $("#alertModal").addClass("alert"); + $("#alertModal").foundation('reveal', 'open'); + } + }, + }); - }) - $(document).on("click", "#get_reports_btn", function() { - data_dict = {}; - gst_name = $("#fetchDataOf").val(); - sel_ac_year = $("#ac_year_list").val(); + } + }) + $(document).on("click", "#get_reports_btn", function() { + data_dict = {}; + gst_name = $("#fetchDataOf").val(); + sel_ac_year = $("#ac_year_list").val(); var selected_state_index = $("select#state_list")[0].selectedIndex; if (selected_state_index > 0){ - data_dict['state'] = $("select#state_list").val(); + data_dict['state'] = $("select#state_list").val(); } var selected_university_index = $("select#univ_list")[0].selectedIndex; if(selected_university_index > 0){ - data_dict['university'] = $("select#univ_list").val(); + data_dict['university'] = $("select#univ_list").val(); } var selected_colg_index = $("select#colg_list")[0].selectedIndex; - if (selected_colg_index > 0){ - data_dict['college'] = $("select#colg_list").val(); - } - - start_date = $("#event_start").val() - if (start_date){ - data_dict['start_date'] = start_date - } - end_date = $("#event_end").val() - if (end_date){ - data_dict['end_date'] = end_date - } - console.log(data_dict) + if (selected_colg_index > 0){ + data_dict['college'] = $("select#colg_list").val(); + } + + start_date = $("#event_start").val() + if (start_date){ + data_dict['start_date'] = start_date + } + end_date = $("#event_end").val() + if (end_date){ + data_dict['end_date'] = end_date + } + console.log(data_dict) $.ajax({ url:"{% url 'mis:get_mis_reports' groupid %}", @@ -453,57 +553,60 @@ dataType: "json", success: function (data) { - column_headers = data["column_headers"]; - console.log(column_headers) - console.log(data["return_data_set"]) - // ac_data_set = JSON.parse(data["return_data_set"]); - ac_data_set = data["return_data_set"]; - console.log(ac_data_set) - dataTable_columns_set = []; - - if (ac_data_set.length > 0) { - // Define table - ac_table = '<table cellpadding="0" cellspacing="0" border="0" class="display" id="ac_table">' + - '</table>'; - - $("#report1").html(ac_table); - - // Prepare title & data headers used in dataTable - $.each(column_headers, function(index, v) { - d = {}; - d["data"] = v[0]; - d["title"] = v[1]; - dataTable_columns_set.push(d); - }); - // report1_data = JSON.stringify(JSON.parse(data['data_for_report1'])) - // Set defintion dataTable - sce_dt_var = $("#ac_table").dataTable({ - "data": ac_data_set, - "columns": dataTable_columns_set, - "createdRow": function ( row, data, index ) { - rec_id = data["rec_id"]; - $(row).attr("id", rec_id); - $(row).find("td:nth-child(4)") - .attr('class','total_val') - .attr('data-query',data['query']) - } - }); - } - else{ - $("#report1").html("No data to display"); - } + column_headers = data["column_headers"]; + console.log(column_headers) + console.log(data["return_data_set"]) + // ac_data_set = JSON.parse(data["return_data_set"]); + ac_data_set = data["return_data_set"]; + console.log(ac_data_set) + dataTable_columns_set = []; + + if (ac_data_set.length > 0) { + // Define table + ac_table = '<table cellpadding="0" cellspacing="0" border="0" class="display" id="ac_table">' + + '</table>'; + + $("#report1").html(ac_table); + + // Prepare title & data headers used in dataTable + $.each(column_headers, function(index, v) { + d = {}; + d["data"] = v[0]; + d["title"] = v[1]; + dataTable_columns_set.push(d); + }); + // report1_data = JSON.stringify(JSON.parse(data['data_for_report1'])) + // Set defintion dataTable + sce_dt_var = $("#ac_table").dataTable({ + "data": ac_data_set, + "columns": dataTable_columns_set, + "createdRow": function ( row, data, index ) { + rec_id = data["rec_id"]; + $(row).attr("id", rec_id); + $(row).find("td:nth-child(4)") + .attr('class','total_val') + .attr('data-query',data['query']) + } + }); + } + else{ + $("#report1").html("No data to display"); + } - }); - }) + } + });//end of ajax call + });//end of click function + + - //</script> + //</script> {% endblock %} {% block document_ready %} var currentYear = (new Date()).getFullYear() lowerYearLimit = currentYear - 5; - var startDtInput = $("#event_start") - var endDtInput = $("#event_end") + var startDtInput = $("#event_start") + var endDtInput = $("#event_end") $("#event_start.date_month_day_year").datepicker({ changeMonth: true, changeYear: true, @@ -559,25 +662,25 @@ }); - data = {{states_list|safe}} - // First empty all values of District field (dropdown/select) - $("select#state_list").empty(); + data = {{states_list|safe}} + // First empty all values of District field (dropdown/select) + $("select#state_list").empty(); - // Make very first entry as given below - $("select#state_list").append( - $("<option></option>") - .attr("value", "") - .text("- - - Select state - - -") - ); + // Make very first entry as given below + $("select#state_list").append( + $("<option></option>") + .attr("value", "") + .text("- - - Select state - - -") + ); - // Fill returned district values based on which state is selected - $.each(data, function(i, value) { - $("select#state_list").append( - $("<option></option>") - .attr("value", value[0]) - .text(value[1]) - ); - }); + // Fill returned district values based on which state is selected + $.each(data, function(i, value) { + $("select#state_list").append( + $("<option></option>") + .attr("value", value[0]) + .text(value[1]) + ); + }); $("select#state_list").append( $("<option></option>") @@ -585,7 +688,7 @@ .text("ALL") ); - // Set very first entry so that user doesn't forgets to select a value - $("select#state_list").prop("selectedIndex", 0); + // Set very first entry so that user doesn't forgets to select a value + $("select#state_list").prop("selectedIndex", 0); {% endblock %}
\ No newline at end of file diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/urls/ajax-urls.py b/gnowsys-ndf/gnowsys_ndf/ndf/urls/ajax-urls.py index 5c84522..91303cb 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/urls/ajax-urls.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/urls/ajax-urls.py @@ -43,6 +43,7 @@ urlpatterns = patterns('gnowsys_ndf.ndf.views.ajax_views', # Ajax-urls required for MIS -------------------------------- + url(r'^get_events/', 'get_events', name='get_events'), url(r'^get_universities/', 'get_universities', name='get_universities'), url(r'^get_students_for_batches/', 'get_students_for_batches', name='get_students_for_batches'), url(r'^get_anncourses_allstudents/', 'get_anncourses_allstudents', name='get_anncourses_allstudents'), diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py index 0ad2935..c63a642 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py @@ -5555,3 +5555,236 @@ def get_universities(request, group_id): except Exception as e: error_message = str(e) return HttpResponse(json.dumps({'message': error_message})) + + +# MIS Reports +@get_execution_time +def get_events(request, group_id): + """ + This view returns list of students along with required data based on selection criteria + to student_data_review.html + + Arguments: + group_id - ObjectId of the currently selected group + + Returns: + A dictionary consisting of following key-value pairs:- + success - Boolean giving the state of ajax call + message - Basestring giving the error/information message + """ + response_dict = {'success': False, 'message': ""} + all_students_text = "" + group_name, group_id = get_group_name_id(group_id) + try: + if request.is_ajax() and request.method == "POST": + # groupid = request.POST.get("groupid", None) + # app_id = request.POST.get("app_id", None) + # app_set_id = request.POST.get("app_set_id", None) + # stud_reg_year = str(request.POST.get("reg_year", None)) + query_rcvd = str(request.POST.get("query", '')) + # university_id = request.POST.get("student_belongs_to_university",None) + # college_id = request.POST.get("student_belongs_to_college",None) + + person_gst = node_collection.one({'_type': "GSystemType", 'name': "Classroom Session"}, {'name': 1, 'type_of': 1}) + + widget_for = [] + query = {} + result_set = None + if query_rcvd: + query = eval(query_rcvd) + groupid = group_id + gapp_gst = node_collection.one({'name':"GAPP"}) + mis_gapp = node_collection.one({'member_of':gapp_gst._id,'name':"MIS"}) + app_id = mis_gapp._id + app_set_id = person_gst._id + + person_gs = node_collection.collection.GSystem() + person_gs.member_of.append(person_gst._id) + person_gs.get_neighbourhood(person_gs.member_of) + # university_gst = node_collection.one({'_type': "GSystemType", 'name': "University"}) + mis_admin = node_collection.one({"_type": "Group", "name": "MIS_admin"}, {"_id": 1}) + + + rec = node_collection.collection.aggregate([{'$match': query}, + {'$project': {'_id': 0, + 'stud_id': '$_id', + 'Name': '$name', + 'Course': '$attribute_set.nussd_course_type', + 'VT': '$relation_set.event_coordinator', + 'Session': '$relation_set.session_of', + 'Start': '$attribute_set.start_time', + 'End': '$attribute_set.end_time', + 'Batch':"$relation_set.event_has_batch", + 'Status': '$attribute_set.event_status', + }}, + {'$sort': {'Name': 1}} + ]) + json_data = [] + filename = "" + column_header = [] + course_section_node_id = course_subsection_node = None + result_set = rec["result"] + if result_set: + # old_dict = result_set[0] + for old_dict in result_set: + if old_dict: + if u"Session" in old_dict: + course_subsection_node = node_collection.one({'_id': ObjectId(old_dict['Session'][0][0])}) + if course_subsection_node: + course_section_node_id = course_subsection_node.prior_node[0] + old_dict.update({'Module': [[course_section_node_id]]}) + if course_section_node_id: + course_section_node = node_collection.one({'_id': ObjectId(course_section_node_id)}) + nussd_course_node = course_section_node.prior_node[0] + old_dict.update({'NUSSD Course': [[nussd_course_node]]}) + if u"stud_id" in old_dict: + event_node = node_collection.one({'_id': ObjectId(old_dict['stud_id'])}) + if event_node: + colg_group_id = event_node.group_set[0] + colg_group_node = node_collection.one({'_id':ObjectId(colg_group_id)}) + if colg_group_node.relation_set: + for rel in colg_group_node.relation_set: + if rel and 'group_of' in rel: + colg_node_id = rel['group_of'][0] + colg_node = node_collection.one({'_id': ObjectId(colg_node_id)},{'name':1,'relation_set':1}) + colg_node_name = colg_node.name + old_dict.update({'College': colg_node_name}) + if colg_node.relation_set: + for rel in colg_node.relation_set: + if rel and 'college_affiliated_to' in rel: + univ_id = rel['college_affiliated_to'][0] + old_dict.update({'University': [[univ_id]]}) + result_set[0] = old_dict + + if result_set: + for each_dict in result_set: + new_dict = {} + for each_key in each_dict: + if each_dict[each_key]: + if type(each_dict[each_key]) == list: + data = each_dict[each_key][0] + else: + data = each_dict[each_key] + + if type(data) == list: + # Perform parsing + if type(data) == list: + # Perform parsing + if type(data[0]) in [unicode, basestring, int]: + new_dict[each_key] = ', '.join(str(d) for d in data) + + elif type(data[0]) in [ObjectId]: + # new_dict[each_key] = str(data) + d_list = [] + for oid in data: + d = node_collection.one({'_id': oid}, {'name': 1}) + d_list.append(str(d.name)) + new_dict[each_key] = ', '.join(str(n) for n in d_list) + + elif type(data) == datetime.datetime: + new_dict[each_key] = data.strftime("%d/%m/%Y") + + elif type(data) == long: + new_dict[each_key] = str(data) + + elif type(data) == bool: + if data: + new_dict[each_key] = "Yes" + else: + new_dict[each_key] = "No" + + else: + new_dict[each_key] = str(data) + + else: + # Perform parsing + if type(data) == list: + # Perform parsing + if type(data[0]) in [unicode, basestring, int]: + new_dict[each_key] = ', '.join(str(d) for d in data) + elif type(data[0]) in [ObjectId]: + new_dict[each_key] = str(data) + + elif type(data) == datetime.datetime: + new_dict[each_key] = data.strftime("%d/%m/%Y") + + elif type(data) == long: + new_dict[each_key] = str(data) + + elif type(data) == bool: + if data: + new_dict[each_key] = "Yes" + else: + new_dict[each_key] = "No" + + else: + new_dict[each_key] = str(data) + + else: + new_dict[each_key] = "" + + json_data.append(new_dict) + + # Start: CSV file processing ------------------------------------------- + column_header = [u'Name', u'Course', u'VT',u'University', u'College', u'NUSSD Course',u'Module', u'Session', u'Start', u'End', u'Batch', u'Status'] + + t = time.strftime("%c").replace(":", "_").replace(" ", "_") + filename = "csv/" + "events_data_" + t + ".csv" + filepath = os.path.join(STATIC_ROOT, filename) + filedir = os.path.dirname(filepath) + if not os.path.exists(filedir): + os.makedirs(filedir) + with open(filepath, 'wb') as csv_file: + fw = csv.DictWriter(csv_file, delimiter=',', fieldnames=column_header) + fw.writerow(dict((col,col) for col in column_header)) + for row in json_data: + v = {} + v["stud_id"] = row.pop("stud_id") + fw.writerow(row) + row.update(v) + # End: CSV file processing -------------------------------------------- + + # Column headers to be displayed on html + column_headers = [ + # ('University', 'University'), + # ('College ( Graduation )', 'College'), + ("University", "University"), + ("College", "College"), + ("Name", "Name"), + ("Course", "Course"), + ("VT", "VT"), + ("NUSSD Course", "NUSSD Course"), + ("Module", "Module"), + ('Session', 'Session'), + ('Start', 'Start'), + ('End', 'End'), + ('Batch', 'Batch'), + ('Status', 'Status'), + ] + # college = node_collection.one({'_id': ObjectId(college_id)}, {"name": 1}) + students_count = len(json_data) + response_dict["success"] = True + response_dict["groupid"] = group_id + response_dict["app_id"] = app_id + response_dict["app_set_id"] = app_set_id + response_dict["filename"] = filename + response_dict["students_count"] = students_count + response_dict["column_headers"] = column_headers + response_dict["students_data_set"] = json_data + return HttpResponse(json.dumps(response_dict, cls=NodeJSONEncoder)) + + else: + error_message = "StudentFindError: Either not an ajax call or not a POST request!!!" + response_dict["message"] = error_message + return HttpResponse(json.dumps(response_dict, cls=NodeJSONEncoder)) + + except OSError as oe: + error_message = "StudentFindError: " + str(oe) + "!!!" + response_dict["message"] = error_message + return HttpResponse(json.dumps(response_dict, cls=NodeJSONEncoder)) + + except Exception as e: + error_message = "StudentFindError: " + str(e) + "!!!" + response_dict["message"] = error_message + return HttpResponse(json.dumps(response_dict, cls=NodeJSONEncoder)) + |