diff options
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/mis_report.html | 367 | ||||
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/urls/ajax-urls.py | 9 | ||||
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py | 617 |
3 files changed, 333 insertions, 660 deletions
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 097dc4e..444976f 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/mis_report.html +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/mis_report.html @@ -316,292 +316,97 @@ $(document).on("click", ".total_val", function() { gst_name = $("#fetchDataOf").val() query_data = $(this).attr('data-query'); + $.ajax({ + url:"{% url 'get_detailed_report' groupid %}", - if(gst_name == "Student"){ - $.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); - } + data: { + 'query': query_data, + 'gst_name':gst_name, + 'csrfmiddlewaretoken': "{{csrf_token}}" + }, - 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 if (gst_name == "Event"){ - $.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); - } + type: "POST", - 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, - "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 if (gst_name == "Voluntary Teacher"){ - $.ajax({ - url:"{% url 'get_voluntary_teachers' 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); - } + dataType: "json", - 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, - "columnDefs": [{ "width": "15%", "targets": 1 }], - "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); - } - }); - } - } - else { - $("#alertModal").removeClass("success").removeClass("warning"); - $("#alertModal").addClass("alert"); - $("#alertModal").foundation('reveal', 'open'); - } - }, - }); + 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); + } + + 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, + "columnDefs": [{ "width": "15%", "targets": 1 }], + "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); + } + }); + } + } + else { + $("#alertModal").removeClass("success").removeClass("warning"); + $("#alertModal").addClass("alert"); + $("#alertModal").foundation('reveal', 'open'); + } + }, + }); }) $(document).on("click", "#get_reports_btn", function() { data_dict = {}; diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/urls/ajax-urls.py b/gnowsys-ndf/gnowsys_ndf/ndf/urls/ajax-urls.py index c93ebe4..9e279cb 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/urls/ajax-urls.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/urls/ajax-urls.py @@ -42,15 +42,13 @@ urlpatterns = patterns('gnowsys_ndf.ndf.views.ajax_views', url(r'^get_data_for_batch_drawer/', 'get_data_for_batch_drawer', name='get_data_for_batch_drawer'), # Ajax-urls required for MIS -------------------------------- - - url(r'^get_voluntary_teachers/', 'get_voluntary_teachers', name='get_voluntary_teachers'), - url(r'^get_events/', 'get_events', name='get_events'), + + url(r'^get_detailed_report/', 'get_detailed_report', name='get_detailed_report'), 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'), url(r'^get_courses/', 'get_courses', name='get_courses'), url(r'^get_batches_with_acourse/', 'get_batches_with_acourse', name='get_batches_with_acourse'), - url(r'^get_announced_courses_with_ctype/', 'get_announced_courses_with_ctype', name='get_announced_courses_with_ctype'), url(r'^get_colleges/(?P<app_id>[\w-]+)$', 'get_colleges', name='get_colleges'), url(r'^get_districts/', 'get_districts', name='get_districts'), @@ -58,7 +56,6 @@ urlpatterns = patterns('gnowsys_ndf.ndf.views.ajax_views', url(r'^get_students/', 'get_students', name='get_students'), url(r'^get_students_for_approval/', 'get_students_for_approval', name='get_students_for_approval'), url(r'^approve_students/', 'approve_students', name='approve_students'), - url(r'^get_statewise_data/', 'get_statewise_data', name='get_statewise_data'), url(r'^get_college_wise_students_data/', 'get_college_wise_students_data', name='get_college_wise_students_data'), url(r'^rechedule_event/(?P<node>[\w-]+)$','reschedule_task',name='reschedule_task'), @@ -83,7 +80,7 @@ urlpatterns = patterns('gnowsys_ndf.ndf.views.ajax_views', url(r'^edit_task_content/', 'edit_task_content', name='edit_task_content'), url(r'^insert_picture/', 'insert_picture', name="insert_picture"), #url for infinite scroll down - url(r'^page_scroll/(?P<page>[^/]+)$', 'page_scroll', name='page_scroll'), + url(r'^page_scroll/(?P<page>[^/]+)$', 'page_scroll', name='page_scroll'), url(r'^check_date/(?P<node>[\w-]+)$', 'check_date', name='check_date'), url(r'^save_time/(?P<node>[\w-]+)$', 'save_time', name='save_time'), ) diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py index d4b5f9b..204c5d9 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py @@ -2265,7 +2265,7 @@ def get_students(request, group_id): 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", '')) + # 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) @@ -2273,13 +2273,13 @@ def get_students(request, group_id): widget_for = [] query = {} - 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 = node_collection.one({'_type':"GSystemType",'name':"Student"})._id + # 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 = node_collection.one({'_type':"GSystemType",'name':"Student"})._id person_gs = node_collection.collection.GSystem() person_gs.member_of.append(person_gst._id) @@ -2305,85 +2305,83 @@ def get_students(request, group_id): # Fetch field(s) from POST object # if request.POST.has_key("student_belongs_to_university"): # university_id = query_data = request.POST.get("student_belongs_to_university", "") - if not query_rcvd: - for each in widget_for: - field_name = each["name"] - - if each["_type"] == "BaseField": - if field_name in request.POST: - query_data = request.POST.get(field_name, "") - query_data = parse_template_data(each["data_type"], query_data) - if field_name == "name": - query.update({field_name: {'$regex': query_data, '$options': "i"}}) - else: - query.update({field_name: query_data}) - - elif each["_type"] == "AttributeType": - if field_name in request.POST: - query_data = request.POST.get(field_name, "") - query_data = parse_template_data(each["data_type"], query_data) - query.update({"attribute_set."+field_name: query_data}) - - # elif each["_type"] == "RelationType": - # if request.POST.has_key(field_name): - # print field_name,"\n\n" - # query_data = request.POST.get(field_name, "") - # query_data = parse_template_data(each["data_type"], query_data, field_instance=each) - # print query_data,"\n\n" - - # if field_name == "student_belongs_to_university": - # university_id = query_data - # else: - # query.update({"relation_set."+field_name: query_data}) - - student = node_collection.one({'_type': "GSystemType", 'name': "Student"}, {'_id': 1}) - query["member_of"] = student._id - - date_lte = datetime.datetime.strptime("31/12/" + stud_reg_year, "%d/%m/%Y") - date_gte = datetime.datetime.strptime("1/1/" + stud_reg_year, "%d/%m/%Y") - query["attribute_set.registration_date"] = {'$gte': date_gte, '$lte': date_lte} + for each in widget_for: + field_name = each["name"] + + if each["_type"] == "BaseField": + if field_name in request.POST: + query_data = request.POST.get(field_name, "") + query_data = parse_template_data(each["data_type"], query_data) + if field_name == "name": + query.update({field_name: {'$regex': query_data, '$options': "i"}}) + else: + query.update({field_name: query_data}) + + elif each["_type"] == "AttributeType": + if field_name in request.POST: + query_data = request.POST.get(field_name, "") + query_data = parse_template_data(each["data_type"], query_data) + query.update({"attribute_set."+field_name: query_data}) + + # elif each["_type"] == "RelationType": + # if request.POST.has_key(field_name): + # print field_name,"\n\n" + # query_data = request.POST.get(field_name, "") + # query_data = parse_template_data(each["data_type"], query_data, field_instance=each) + # print query_data,"\n\n" + + # if field_name == "student_belongs_to_university": + # university_id = query_data + # else: + # query.update({"relation_set."+field_name: query_data}) + + student = node_collection.one({'_type': "GSystemType", 'name': "Student"}, {'_id': 1}) + query["member_of"] = student._id + + date_lte = datetime.datetime.strptime("31/12/" + stud_reg_year, "%d/%m/%Y") + date_gte = datetime.datetime.strptime("1/1/" + stud_reg_year, "%d/%m/%Y") + query["attribute_set.registration_date"] = {'$gte': date_gte, '$lte': date_lte} + college_groupid = None + if college_id: + # Get selected college's groupid, where given college should belongs to MIS_admin group + college_groupid = node_collection.one({'_id': ObjectId(college_id), 'group_set': mis_admin._id, 'relation_set.has_group': {'$exists': True}}, + {'relation_set.has_group': 1, 'name': 1} + ) + response_dict["college"] = college_groupid.name + + if college_groupid: + for each in college_groupid.relation_set: + if "has_group" in each.keys(): + college_groupid = each["has_group"][0] + break + else: college_groupid = None - if college_id: - # Get selected college's groupid, where given college should belongs to MIS_admin group - college_groupid = node_collection.one({'_id': ObjectId(college_id), 'group_set': mis_admin._id, 'relation_set.has_group': {'$exists': True}}, - {'relation_set.has_group': 1, 'name': 1} - ) - response_dict["college"] = college_groupid.name + groupid = ObjectId(groupid) + group_set_to_check = [] + + if groupid == mis_admin._id: + # It means group is either a college group or MIS_admin group + # In either case append MIS_admin group's ObjectId + # and if college_groupid exists, append it's ObjectId too! if college_groupid: - for each in college_groupid.relation_set: - if "has_group" in each.keys(): - college_groupid = each["has_group"][0] - break + group_set_to_check.append(college_groupid) else: - college_groupid = None + group_set_to_check.append(mis_admin._id) - groupid = ObjectId(groupid) - group_set_to_check = [] + else: + # Otherwise, append given group's ObjectId + group_set_to_check.append(groupid) - if groupid == mis_admin._id: - # It means group is either a college group or MIS_admin group - # In either case append MIS_admin group's ObjectId - # and if college_groupid exists, append it's ObjectId too! - if college_groupid: - group_set_to_check.append(college_groupid) - else: - group_set_to_check.append(mis_admin._id) + if university_id: + university_id = ObjectId(university_id) + university = node_collection.one({'_id': university_id}, {'name': 1}) + if university: + response_dict["university"] = university.name + query.update({'relation_set.student_belongs_to_university': university_id}) - else: - # Otherwise, append given group's ObjectId - group_set_to_check.append(groupid) - - if university_id: - university_id = ObjectId(university_id) - university = node_collection.one({'_id': university_id}, {'name': 1}) - if university: - response_dict["university"] = university.name - query.update({'relation_set.student_belongs_to_university': university_id}) - - query.update({'group_set': {'$in': group_set_to_check}}) - query.update({'status': u"PUBLISHED"}) - # till here + query.update({'group_set': {'$in': group_set_to_check}}) + query.update({'status': u"PUBLISHED"}) rec = node_collection.collection.aggregate([{'$match': query}, {'$project': {'_id': 0, 'stud_id': '$_id', @@ -2550,6 +2548,7 @@ def get_students(request, group_id): response_dict["message"] = error_message return HttpResponse(json.dumps(response_dict, cls=NodeJSONEncoder)) + @get_execution_time def get_statewise_data(request, group_id): """ @@ -5557,241 +5556,10 @@ def get_universities(request, group_id): 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)) - # MIS Reports @get_execution_time -def get_voluntary_teachers(request, group_id): +def get_detailed_report(request, group_id): """ This view returns list of students along with required data based on selection criteria to student_data_review.html @@ -5805,73 +5573,149 @@ def get_voluntary_teachers(request, group_id): message - Basestring giving the error/information message """ response_dict = {'success': False, 'message': ""} - all_students_text = "" + # all_students_text = "" + column_header = [] group_name, group_id = get_group_name_id(group_id) + app_set_id = None 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': "Voluntary Teacher"}, {'name': 1, 'type_of': 1}) - - widget_for = [] - query = {} + gst_name = str(request.POST.get("gst_name", '')) + if gst_name == "Event": + gst_name = "Classroom Session" + person_gst = node_collection.one({'_type': "GSystemType", 'name': gst_name}) + gapp_gst = node_collection.one({'name':"GAPP"}) + mis_gapp = node_collection.one({'member_of':gapp_gst._id,'name':"MIS"}) + # groupid = group_id + app_id = mis_gapp._id 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}) + if person_gst.name == "Voluntary Teacher": + column_header = [u'University', u'College',u'Name', u'Email ID', u'Phone', u'Street',u'Events'] + + rec = node_collection.collection.aggregate([{'$match': query}, + {'$project': {'_id': 0, + 'stud_id': '$_id', + 'Name': '$name', + 'Email ID': '$attribute_set.email_id', + 'Phone': '$attribute_set.mobile_number', + 'Street': '$attribute_set.town_city', + 'Events': '$relation_set.coordinator_of_event' + }}, + {'$sort': {'Name': 1}} + ]) + elif person_gst.name == "Classroom Session": + app_set_id = person_gst._id + 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'] + + 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': {'Start': 1}} + ]) + elif person_gst.name == "Student": + column_header = [u"Enrollment Code", u'Name', u'Reg# Date', u'Gender', u'Birth Date', u'Religion', u'Email ID', u'Languages Known', u'Caste', u'Contact Number (Mobile)', u'Alternate Number / Landline', u'House / Street', u'Village', u'Taluka', u'Town / City', u'District', u'State', u'Pin Code', u'Year of Passing 12th Standard', u'Degree Name / Highest Degree', u'Year of Study', u'Stream / Degree Specialization', u'College Enrolment Number / Roll No', u'College ( Graduation )', u'Are you registered for NSS?','University'] + rec = node_collection.collection.aggregate([{'$match': query}, + {'$project': {'_id': 0, + 'stud_id': '$_id', + 'Enrollment Code': '$attribute_set.enrollment_code', + 'Name': '$name', + # 'First Name': '$attribute_set.first_name', + # 'Middle Name': '$attribute_set.middle_name', + # 'Last Name': '$attribute_set.last_name', + 'Reg# Date': '$attribute_set.registration_date', + 'Gender': '$attribute_set.gender', + 'Birth Date': '$attribute_set.dob', + 'Religion': '$attribute_set.religion', + 'Email ID': '$attribute_set.email_id', + 'Languages Known': '$attribute_set.languages_known', + 'Caste': '$relation_set.student_of_caste_category', + 'Contact Number (Mobile)': '$attribute_set.mobile_number', + 'Alternate Number / Landline': '$attribute_set.alternate_number', + 'House / Street': '$attribute_set.house_street', + 'Village': '$attribute_set.village', + 'Taluka': '$attribute_set.taluka', + 'Town / City': '$attribute_set.town_city', + 'District': '$relation_set.person_belongs_to_district', + 'State': '$relation_set.person_belongs_to_state', + 'Pin Code': '$attribute_set.pin_code', + 'Year of Passing 12th Standard': '$attribute_set.12_passing_year', + 'Degree Name / Highest Degree': '$attribute_set.degree_name', + 'Year of Study': '$attribute_set.degree_year', + 'Stream / Degree Specialization': '$attribute_set.degree_specialization', + 'College Enrolment Number / Roll No': '$attribute_set.college_enroll_num', + 'College ( Graduation )': '$relation_set.student_belongs_to_college', + 'University': '$relation_set.student_belongs_to_university', + 'Are you registered for NSS?': '$attribute_set.is_nss_registered' + }}, + {'$sort': {'Enrollment Code': 1}} + ]) - rec = node_collection.collection.aggregate([{'$match': query}, - {'$project': {'_id': 0, - 'stud_id': '$_id', - 'Name': '$name', - 'Email ID': '$attribute_set.email_id', - 'Phone': '$attribute_set.mobile_number', - 'Street': '$attribute_set.town_city', - 'Events':'$relation_set.coordinator_of_event' - }}, - {'$sort': {'Name': 1}} - ]) json_data = [] filename = "" - column_header = [] course_section_node_id = course_subsection_node = None result_set = rec["result"] + print "\n\n result_set",result_set if result_set: # old_dict = result_set[0] for old_dict in result_set: if old_dict: - if u"stud_id" in old_dict: - vt_node = node_collection.one({'_id': ObjectId(old_dict['stud_id'])}) - if vt_node: - for rel in vt_node.relation_set: - if rel and 'trainer_of_college' in rel: - colg_node_id = rel['trainer_of_college'][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 person_gst.name == "Voluntary Teacher": + if u"stud_id" in old_dict: + vt_node = node_collection.one({'_id': ObjectId(old_dict['stud_id'])}) + if vt_node: + for rel in vt_node.relation_set: + if rel and 'trainer_of_college' in rel: + colg_node_id = rel['trainer_of_college'][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]]}) + if person_gst.name == "Classroom Session": + 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: @@ -5943,10 +5787,9 @@ def get_voluntary_teachers(request, group_id): json_data.append(new_dict) # Start: CSV file processing ------------------------------------------- - column_header = [u'University', u'College',u'Name', u'Email ID', u'Phone', u'Street',u'Events'] t = time.strftime("%c").replace(":", "_").replace(" ", "_") - filename = "csv/" + "voluntary_teachers_" + t + ".csv" + filename = "csv/" + gst_name + "_" + t + ".csv" filepath = os.path.join(STATIC_ROOT, filename) filedir = os.path.dirname(filepath) if not os.path.exists(filedir): @@ -5961,17 +5804,45 @@ def get_voluntary_teachers(request, group_id): row.update(v) # End: CSV file processing -------------------------------------------- - # Column headers to be displayed on html - column_headers = [ - ('University', 'University'), - ('College', 'College'), - ("Name", "Name"), - ("Email ID", "Email ID"), - ("Phone", "Phone"), - ("Street", "Street"), - ("Events", "Events"), - ] - # college = node_collection.one({'_id': ObjectId(college_id)}, {"name": 1}) + if person_gst.name == "Voluntary Teacher": + # Column headers to be displayed on html + column_headers = [ + ('University', 'University'), + ('College', 'College'), + ("Name", "Name"), + ("Email ID", "Email ID"), + ("Phone", "Phone"), + ("Street", "Street"), + ("Events", "Events"), + ] + elif person_gst.name == "Classroom Session": + column_headers = [ + ("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'), + ] + elif person_gst.name == "Student": + column_headers = [ + ('University', 'University'), + ('College ( Graduation )', 'College'), + ("Name", "Name"), + ("Enrollment Code", "Enr Code"), + ("Email ID", "Email ID"), + ('Year of Study', 'Year of Study'), + ('Contact Number (Mobile)', 'Phone'), + ('Degree Name / Highest Degree', 'Degree'), + ('House / Street', 'Street') + ] + students_count = len(json_data) response_dict["success"] = True response_dict["groupid"] = group_id |