summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/mis_report.html99
-rw-r--r--gnowsys-ndf/gnowsys_ndf/ndf/urls/ajax-urls.py1
-rw-r--r--gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py209
-rw-r--r--gnowsys-ndf/gnowsys_ndf/ndf/views/mis.py12
4 files changed, 315 insertions, 6 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 5b5f588..097dc4e 100644
--- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/mis_report.html
+++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/mis_report.html
@@ -315,8 +315,9 @@
$(document).on("click", ".total_val", function() {
gst_name = $("#fetchDataOf").val()
+ query_data = $(this).attr('data-query');
+
if(gst_name == "Student"){
- query_data = $(this).attr('data-query');
$.ajax({
url:"{% url 'get_students' groupid %}",
@@ -412,8 +413,7 @@
},
});
}
- else{
- query_data = $(this).attr('data-query');
+ else if (gst_name == "Event"){
$.ajax({
url:"{% url 'get_events' groupid %}",
@@ -507,6 +507,99 @@
}
},
});
+ }
+ 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);
+ }
+
+ 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">&nbsp;&nbsp;&nbsp;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');
+ }
+ },
+ });
}
})
diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/urls/ajax-urls.py b/gnowsys-ndf/gnowsys_ndf/ndf/urls/ajax-urls.py
index 91303cb..c93ebe4 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_voluntary_teachers/', 'get_voluntary_teachers', name='get_voluntary_teachers'),
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'),
diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py
index c63a642..d4b5f9b 100644
--- a/gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py
+++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py
@@ -5788,3 +5788,212 @@ def get_events(request, group_id):
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):
+ """
+ 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': "Voluntary Teacher"}, {'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',
+ '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"]
+ 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 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'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"
+ 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', 'College'),
+ ("Name", "Name"),
+ ("Email ID", "Email ID"),
+ ("Phone", "Phone"),
+ ("Street", "Street"),
+ ("Events", "Events"),
+ ]
+ # 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))
diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/mis.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/mis.py
index 13f6cb0..f3a8cd3 100644
--- a/gnowsys-ndf/gnowsys_ndf/ndf/views/mis.py
+++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/mis.py
@@ -812,7 +812,7 @@ def get_mis_reports(request, group_id, **kwargs):
'relation_set.organization_belongs_to_state': {'$in': state_id_list},
'group_set': mis_admin_grp._id})
else:
- if gst_node.name == "Student":
+ if gst_node.name == "Student" or gst_node.name == "Voluntary Teacher":
query.update({'relation_set.person_belongs_to_state': ObjectId(state_id)})
university_cur = node_collection.find({'member_of': univ_gst._id,
@@ -852,6 +852,10 @@ def get_mis_reports(request, group_id, **kwargs):
if each.relation_set:
for each_rel in each.relation_set:
+ if gst_node.name == "Voluntary Teacher":
+ # if each_rel and "college_has_trainer" in each_rel:
+ # colg_node_id = each_rel["college_has_trainer"][0]
+ query.update({'relation_set.trainer_of_college': ObjectId(each._id)})
if gst_node.name == "Classroom Session":
if each_rel and "has_group" in each_rel:
colg_group_node_id = each_rel["has_group"][0]
@@ -861,6 +865,7 @@ def get_mis_reports(request, group_id, **kwargs):
if each_rel and "organization_belongs_to_state" in each_rel:
statename = each_rel["organization_belongs_to_state"]
# print "\n\n statename", statename
+ print "\n\nquery",query
rec = node_collection.collection.aggregate([
{
'$match': query
@@ -877,7 +882,6 @@ def get_mis_reports(request, group_id, **kwargs):
])
resultset = rec['result']
-
if resultset:
for each in resultset:
each['query'] = str(query)
@@ -896,7 +900,7 @@ def get_mis_reports(request, group_id, **kwargs):
# data_for_report1["college_id"] = str(colg_node._id)
del each['_id']
try:
- print each['total_students']
+ l = each['total_students']
except:
del each['total_students']
@@ -912,6 +916,8 @@ def get_mis_reports(request, group_id, **kwargs):
column_headers.append(('total_students',"Total Students"))
elif gst_node.name == "Classroom Session":
column_headers.append(('total_students',"Total Events"))
+ elif gst_node.name == "Voluntary Teacher":
+ column_headers.append(('total_students',"Total VTs"))
response_dict["column_headers"] = column_headers
response_dict["success"] = True