summaryrefslogtreecommitdiff
path: root/gnowsys-ndf/gnowsys_ndf
diff options
context:
space:
mode:
authorSaiEswarEpuri <saieswar36@gmail.com>2015-06-30 13:30:43 +0530
committerSaiEswarEpuri <saieswar36@gmail.com>2015-06-30 13:30:43 +0530
commitef5bc947e50af2b92d09df8d0780faee1df1b22b (patch)
tree1c8a511a4e7fab08b99d7a783f519d75fb3ed5aa /gnowsys-ndf/gnowsys_ndf
parentfdb0a8ba045b8ecb78296a199d756371a385c938 (diff)
parent7bd32861825ec11a5da0a4f61dc800c4770b065d (diff)
downloadgnowsys-ef5bc947e50af2b92d09df8d0780faee1df1b22b.tar.gz
Merge branch 'mongokit' of https://github.com/gnowledge/gstudio into mongokit
Diffstat (limited to 'gnowsys-ndf/gnowsys_ndf')
-rw-r--r--gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/new_create_batch.html549
-rw-r--r--gnowsys-ndf/gnowsys_ndf/ndf/urls/batch.py5
-rw-r--r--gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py167
-rw-r--r--gnowsys-ndf/gnowsys_ndf/ndf/views/batch.py350
-rw-r--r--gnowsys-ndf/gnowsys_ndf/ndf/views/enrollment.py6
-rw-r--r--gnowsys-ndf/gnowsys_ndf/ndf/views/methods.py2
6 files changed, 685 insertions, 394 deletions
diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/new_create_batch.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/new_create_batch.html
index 77dcfa9..f6f9e0d 100644
--- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/new_create_batch.html
+++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/new_create_batch.html
@@ -4,6 +4,17 @@
{% load ndf_tags %}
{% block title %} {{title}} {% endblock %}
+{% block head %}
+ {{block.super}}
+
+ <!-- DataTables -->
+ <script src="/static/ndf/bower_components/DataTables/media/js/jquery.dataTables.js"></script>
+ <script src="/static/ndf/bower_components/datatables-plugins/integration/foundation/dataTables.foundation.js"></script>
+ <!-- DataTables CSS -->
+ <link href="/static/ndf/bower_components/datatables-plugins/integration/foundation/dataTables.foundation.css" rel="stylesheet" type="text/css" />
+{% endblock %}
+
+
{% block style %}
{{block.super}}
@@ -15,6 +26,9 @@
.margin-0 {
margin: 0 !important;
}
+ tr:hover{
+ cursor:pointer;
+ }
.resource-drawer {
border-color: #D3D3D3; border-style: solid;
@@ -40,10 +54,13 @@
font-size: 1rem;
}
+ .existing_batch, .view_batch{
+ text-decoration: underline;
+ }
.posted-by{ color: #808080; font-size: small; }
- .selected-resource { background-color:lightgray !important ; }
+ .selected { background-color:lightgray !important ; }
.resource-type-image {
height:40px;
@@ -73,26 +90,24 @@
position: relative !important;
}
+ .batch_create_edit_table > tr {
+ border: 1px solid black;
+ }
{% endblock %}
{% block body_content %}
<div id="alertModal" class="reveal-modal small alert alert-box radius" data-reveal data-alert>
<label id="alertModalLabel"> </label>
- <div class="row hide">
- <div class="small-3 small-offset-3 columns">
- <input type="button" id="btnConfirmYes" class="button tiny expand" value="Yes">
- </div>
- <div class="small-3 columns end">
- <input type="button" id="btnConfirmNo" class="button tiny expand " value="No">
- </div>
- </div>
<a class="close-reveal-modal">&#215;</a>
</div>
-<form data-abide id="form-batch" method="POST" action="{% url 'save_batch_stud' groupid %}">{% csrf_token %}
+ <div id="batch_info" class="reveal-modal medium" data-reveal style="height:500px;overflow-y: auto !important;">
+ <a class="close-reveal-modal">&#215;</a>
+ </div>
+<div class="course_details_div">
<fieldset id="stud-count" class="small-10 columns">
<div class="row">
<div class="small-2 columns">
@@ -119,43 +134,61 @@
<label id="stud_count" style='display: none'></label>
<label id="lblstud" style='display: none'> {% trans "Student(s)" %}</label>
</div>
-
<div class="small-12 columns" align="center">
<input type="button" class="small button right inline" id="nextbtn" value="Proceed" disabled="disabled" style='display: none'/>
</div>
- <br>
- <fieldset id="make_batch_fs" class="hide small-12 columns">
+</div>
- <div id="drawer-heading" class="row">
- <div class="small-6 columns right inline">
- <input type="text" id="drawer_head" name="drawer_head" disabled="disabled">
+ <br>
+ <div class="batch_div hide">
+ <div class="row">
+ <div style="text-align: center;">
+ <div class="small-4 columns end" style="display: inline-block; ">
+ <h4>{% trans 'Search Student by name : ' %}</h4>
+ </div>
+ <div class="small-4 columns end" style="display: inline-block; ">
+ <input type="text" class="ajax_input_name small-6 columns" value="" placeholder="Enter atleast 3 letters to search">
</div>
</div>
+ </div>
+ </div>
+ <div class="datatable_div"></div>
+
+ <div id="batch-details"></div>
+
- <br>
-
- <div id="drawer-div"> </div><br>
- <div id="batch-details" style='display: block'> </div>
-
- <input type='button' name='add_btn' id='add_btn' value='Add Batch' class='button round small' onclick = 'add_new_batch()' style='display: none'>
- <div>
- <input type="submit" class="button right inline" id="save_batch" name="save_batch" value="Save" disabled="disabled" style='display: none'>&nbsp;&nbsp;
- <input type="hidden" id="batch_user_list_dict" name="batch_user_list_dict">
- <input type="hidden" id="ac_id" name="ac_id">
+ <fieldset id="make_batch_fs" class="hide small-12 columns">
+ <table id="batch_create_edit_table">
+ <tbody>
+ </tbody>
+ </table>
+ <input type="button" class="create_batch_row button small" value="Create Batch" disabled="disabled">
+ <li style="color:red;">Batch once created CANNOT be deleted</li>
+ <li>Click on Batch name to add more students to the batch</li>
+ <li>Click on 'View' to display/remove batch members</li>
+ <div class="batch_create_div hide">
+ <input type="text" class="batch_name_inp" placeholder="Enter name of Batch">
+ <input type="button" class="save small round button" value="Save">
+ <input type="button" class="cancel small round button" value="Cancel">
+ </div>
+ <input type="hidden" name="batch_user_list_dict" id="batch_user_list_dict">
+ <input type="hidden" name="ac_id" id="ac_id">
</div>
</fieldset>
-
- </form>
{% endblock %}
-
+<script>
{% block script%}
//global variables
var ac_id=""
+ var ac;
+ var added_ids_list = []
var batch_name_index;
+ var batch_name;
var ac_name_as_prefix;
var batch_user_list_dict = {}
var batch_user_list_list = {}
var scount_lbl = 0
+ var sce_dt_var;
//For selecting Course type
$("select#nussd_course_type").change(function() {
var nussd_course_type = $("#nussd_course_type").val();
@@ -268,196 +301,343 @@
//Proceed to create batches for selected AC
$("#nextbtn").click(function(event) {
- ac_id = $("#acourse_list").val();
-
if ($("#nextbtn").css("display") != "none") {
$("#nextbtn").css("display", "none");
}
- $("#nussd_course_type").attr("disabled","disabled")
- $("#acourse_list").attr("disabled","disabled")
-
+ // $("#nussd_course_type").attr("disabled","disabled")
+ // $("#acourse_list").attr("disabled","disabled")
+ // Give a textbox to enter name
+
+ $(".batch_div").removeClass("hide");
+ $(".course_details_div").addClass("hide");
+ nc = $("#nussd_course_type").val();
+ ac = $("#acourse_list option:selected").text()
+ ac_id = $("#acourse_list").val();
+ $("aside.medium-2.columns").html("Batch creation for: <b>'"+ac+"'</b> ("+nc+")")
$.ajax({
- url: "{% url 'get_students_for_batches' group_id %}",
+ url: "{% url 'get_possible_batches' groupid %}",
+
data: {
- ac_id: ac_id
+ 'ac_id': ac_id,
+ 'create_new_batch':true,
+ 'csrfmiddlewaretoken': "{{csrf_token}}"
},
- type: "GET",
+
+ type: "POST",
+
dataType: "json",
- success: function(data){
- success_state = data["success"];
- if (data["success"]) {
- drawer_widget = data["drawer_widget"];
- ac_name_as_prefix = $("#acourse_list option:selected").text()
- $("#drawer-div").html(drawer_widget);
- scount_lbl = data["student_count"]
- $("#stud_count").css("font-size", "53px");
- $("#stud_count").text(scount_lbl)
-
-
- batch_name_index = data["batch_name_index"]
- $("#drawer_head").attr("size",ac_name_as_prefix.length+10)
- $("#drawer_head").attr("value",ac_name_as_prefix +"_Batch_"+batch_name_index);
- a = data["batches_for_same_course"]
- a = JSON.parse(a)
-
- $.each(a, function(index, batch_node) {
- arr_batch_mem_nodes = []
- batch_user_list_list_arr = []
- $.each(batch_node["has_batch_member"],function (index, batch_mem_list){
- li_ele = "<li class='bullet-item text-left' value='"+batch_mem_list["_id"]+"'><input type='hidden' value='"+batch_mem_list["_id"]+"' name='"+batch_mem_list["name"]+"' class='node_id new_create_batch_values'><div class='row'><div class='small-1 columns resource-type-image' style='background-image: url();'></div><div class='small-11 columns'><div class='row'><div class='small-12 columns'><b>"+batch_mem_list["name"]+" </b></div><div class='small-12 columns text-left' style='padding-top:3px'><i class='posted-by'>Student by <a class='user' href='/1/dashboard' data-gnow=''></a> on 19 October 2014 </i></div></div><div class='row'><div class='small-12 columns text-left' style='padding-top:5px;'>None</div></div></div></div></li>"
- arr_batch_mem_nodes.push(li_ele)
- batch_user_list_list_arr.push(batch_mem_list["_id"])
- });
- batch_user_list_dict[batch_node["name"]] = arr_batch_mem_nodes
- batch_user_list_list[batch_node["name"]] = batch_user_list_list_arr
- batch_det_str = "<ul class='button-group'><li><a href='#' class='button edit_batch' id='"+batch_node["name"]+"'>"+batch_node["name"]+" -- " + arr_batch_mem_nodes.length + " members.</a></li></ul><br>"
- $("#batch-details").append(batch_det_str)
- });
- }
- else {
- alert("Failed to get drawer")
+ success: function(data){
+ success_state = data["success"]
+ if(success_state){
+ batch_data = data['old_batches']
+ if (batch_data!=""){
+ // batch_user_list_dict = batch_data
+ $("#make_batch_fs").removeClass("hide")
+ var table = document.getElementById("batch_create_edit_table");
+ $.each(batch_data, function(index){
+ $.each(batch_data[index], function(key,val){
+ batch_user_list_dict[key] = val[0]
+ var row = table.insertRow(-1);
+ var cell1 = row.insertCell(0);
+ var cell2 = row.insertCell(1);
+ var cell3 = row.insertCell(2);
+ cell1.innerHTML = "<span data-tooltip title='Click to view/edit'>View</span>";
+ cell1.className = "view_batch";
+ cell2.innerHTML = "<span data-tooltip title='Click to Add to this Batch'>"+key+"</span>";
+ cell2.className = "save";
+ cell2.className += " existing_batch";
+ cell2.id = val[1];
+ cell3.innerHTML = "<span data-tooltip title='Total students'>"+val[0].length+" student(s)<span>";
+ cell3.className = "stud_count_in_batch";
+ val.pop();
+ })
+ })
+ }
}
},
- complete:function(data){
- $("#make_batch_fs").removeClass("hide")
+ });//end of ajax
- if ($("#save_batch").css("display") == "none") {
- $("#save_batch").toggle();
- }
- if ($("#add_btn").css("display") == "none") {
- $("#add_btn").toggle();
- }
- {% if node %}
- $("#{{node.name}}").trigger('click')
- {% endif %}
- }
- });
});//end of nextbtn.click()
- // On click of Batch link
- $(document).on("click",".edit_batch", function(event){
- if ($("#new_create_batch_drawer2").children("li").length==0){
- edit_batch_name = $(this).attr('id');
- edit_batch_name=edit_batch_name
- $("#drawer_head").attr("value",edit_batch_name);
- $("#new_create_batch_drawer2").html("")
+ // Click event: "Student data" Row of DataTable
+ $(document).on( 'click', '#student_data_table tbody tr', function () {
+ $(this).toggleClass('selected');
+ $("#make_batch_fs").removeClass("hide")
+ $(".create_batch_row").removeAttr("disabled")
+ });
+
+ // On click of create batch button
+ $(document).on( 'click', '.create_batch_row', function () {
+ $(".batch_create_div").removeClass("hide")
+ total_batches = Object.keys(batch_user_list_dict).length + 1
+ $(".batch_name_inp").val(ac + " - Batch " + total_batches)
+ .attr("disabled", true)
+ $(".create_batch_row").attr("disabled",true)
+
+ });
- if(batch_user_list_dict.hasOwnProperty(edit_batch_name)){
- for (i=0;i<batch_user_list_dict[edit_batch_name].length;i++){
- $("#new_create_batch_drawer2").append(batch_user_list_dict[edit_batch_name][i])
+ // Create batch and add selected students to it.
+ // Also hide batch_create_div from first row
+ // Add new row to batch create edit table with the batch name as inputted
+ $(document).on( 'click', '.save', function () {
+ arr = []
+ batch_id = null;
+ //do nothing
+ $(".create_batch_row").attr("disabled",true)
+
+ $(".batch_create_div").addClass("hide");
+ batch_name = $(".batch_name_inp").val();
+ sce_dt_var.$("tr.selected").each(function () {
+ $(this).removeClass('selected');
+ arr.push(this.id);
+ });
+ if (arr.length != 0){
+ if($(this).hasClass('existing_batch')){
+ batch_name = $(this).text()
+ if(batch_user_list_dict.hasOwnProperty(batch_name)){
+ old_arr = batch_user_list_dict[batch_name]
+ batch_user_list_dict[batch_name] = old_arr.concat(arr)
+ $(this).next('td').html(batch_user_list_dict[batch_name].length+ " student(s)")
+ arr = batch_user_list_dict[batch_name]
+ batch_id = $(this).attr('id')
}
}
- if ($("#drawer_head").css("display") == "none") {
- $("#drawer_head").toggle()
- }
- if ($("#add_btn").css("display") == "none") {
- $("#add_btn").toggle()
- }
- if (!($("#batch-details").css("display") == "none")) {
- $("#batch-details").toggle()
- }
- $("#save_batch").attr("disabled",true)
- event.preventDefault();
- return false;
+ $.ajax({
+ url: "{% url 'save_batch' groupid %}",
+
+ data: {
+ 'ac_id': ac_id,
+ 'batch_name': batch_name,
+ 'batch_id': batch_id,
+ 'user_list':arr,
+ 'csrfmiddlewaretoken': "{{csrf_token}}"
+ },
+
+ type: "POST",
+
+ dataType: "json",
+
+ success: function(data){
+ new_batch_node = data
+ if(new_batch_node['new_batch_created']){
+ var table = document.getElementById("batch_create_edit_table");
+ var row = table.insertRow(-1);
+ var cell1 = row.insertCell(0);
+ var cell2 = row.insertCell(1);
+ var cell3 = row.insertCell(2);
+ batch_user_list_dict[batch_name] = arr;
+ cell2.innerHTML = "<span data-tooltip title='Click to Add to this Batch'>"+new_batch_node['new_batch_node_name']+"</span>";
+
+ cell2.className = "save";
+ cell2.className += " existing_batch";
+ cell2.id = new_batch_node['new_batch_node_id']
+ cell3.innerHTML = "<span data-tooltip title='Total students'>"+batch_user_list_dict[batch_name].length+" student(s)<span>";
+ cell3.className = "stud_count_in_batch";
+ cell1.innerHTML = "<span data-tooltip title='Click to view/edit'>View</span>";
+
+ cell1.className = "view_batch";
+ }
+ $(".batch_name_inp").val('');
+ $('.ajax_input_name').val('');
+ $(".datatable_div").html('');
+ },
+ });//end of ajax
}
else{
- alert("Please add to batch ");
- event.preventDefault();
- return false;
+ alert("Please select students");
}
- });
-
- // Confirm create batch reveal modal
- var create_batch_flag = false;
- $(document).on("click", "#btnConfirmYes", function() {
- create_batch_flag = true;
- $("#alertModal").foundation('reveal', 'close');
- add_new_batch();
- });
- $(document).on("click", "#btnConfirmNo", function() {
- create_batch_flag = false;
- $("#alertModal").foundation('reveal', 'close');
- });
+ })
- //Add new batch
- function add_new_batch(event){
-
- //Fetch the value of "#drawer_head" which will be key for above dict
- batch_name= $("#drawer_head").val()
-
- arr = [] //Value for above key
- arr1 = []
- //Add the right drawer resources to this list.
- $("#new_create_batch_drawer2").children("li").each(function(c,v){arr.push(v);arr1.push(v.getAttribute("value"))});
- left_drawer_count = $("#new_create_batch_drawer1").children("li").length
- if ((arr.length >= 30 && left_drawer_count >= 26) || (arr.length >= 25 && left_drawer_count == 1)) {
- if(!create_batch_flag){
- $("#alertModal").foundation('reveal', 'open');
- $("#alertModal").find("div.row").removeClass("hide");
- lbl = "Batch once created CANNOT be deleted. Confirm to proceed. Do you want to continue?"
- $("#alertModalLabel").text(lbl);
+ //view batch members on click of 'View'
+ $(document).on( 'click', '.view_batch ', function () {
+
+ batch_id = $(this).next('.existing_batch').attr('id');
+ batch_name = $(this).next('.existing_batch').text();
+ $.ajax({
+ url: "{% url 'batch_detail' groupid %}",
+
+ data: {
+ 'batch_id': batch_id,
+ },
+
+ type: "GET",
+
+ dataType: "json",
+
+ success: function(data){
+ $("#batch_info").html("")
+ if(data!=""){
+ var table = document.createElement("TABLE");
+ table.id = batch_id
+ table.className = "batch_table_id"
+ $.each(data, function(index){
+ var row = table.insertRow(-1);
+ var cell1 = row.insertCell(0);
+ cell1.innerHTML = data[index]['name'];
+ var cell2 = row.insertCell(1);
+ cell2.innerHTML = "Remove from Batch";
+ cell2.id = data[index]['_id'];
+ cell2.className = 'button alert remove_stud';
+ })
+ $("#batch_info").append(table)
}
else{
- create_batch_flag = false;
- $("#save_batch").removeAttr("disabled")
- $("#stud_count").css("font-size", "53px");
- $("#stud_count").text(left_drawer_count-1)
+ $("#batch_info").html("No data to display")
+ }
+ $("#batch_info").append("<a class='close-reveal-modal'>&#215;</a>")
+ $('#batch_info').foundation('reveal', 'open');
- if(batch_user_list_dict.hasOwnProperty(batch_name)){
- batch_user_list_dict[batch_name] = arr
- $("#"+batch_name).text(batch_name + " -- " + arr.length+" members");
- }
- else{
- batch_user_list_dict[batch_name] = arr
- //Display the Batch details
- batch_det_str="<ul class='button-group'><li><a href='#' class='button edit_batch' id='"+batch_name+"'>" + batch_name + " -- " + arr.length + " members.</a></li></ul><br>"
- $("#batch-details").append(batch_det_str)
- batch_name_index += 1;
- }
- batch_user_list_list[batch_name] = arr1
-
- //Remove these resources from right drawer.
- $("#new_create_batch_drawer2").html("")
- if($("#new_create_batch_drawer1").children("li").length==1)
- {
- $("#drawer_head").css("display","none")
- $("#add_btn").css("display","none")
- }
- else{
- $("#drawer_head").attr("value",ac_name_as_prefix + "_Batch_"+ batch_name_index);
- }
- if ($("#batch-details").css("display") == "none") {
- $("#batch-details").toggle()
+ },
+ });//end of ajax
+
+
+
+ })
+
+
+ //remove batch members
+ $(document).on( 'click', '.remove_stud ', function () {
+ stud_id = $(this).attr('id');
+ batch_id = $(".batch_table_id").attr('id')
+ $(this).closest("tr").remove()
+ $.ajax({
+ url: "{% url 'remove_stud_from_batch' groupid %}",
+
+ data: {
+ 'batch_id': batch_id,
+ 'stud_id': stud_id,
+ 'csrfmiddlewaretoken': "{{csrf_token}}"
+ },
+
+ type: "POST",
+
+ dataType: "json",
+
+ success: function(data){
+ status = data
+ if(status=="success"){
+ if(batch_user_list_dict.hasOwnProperty(batch_name)){
+ old_arr = batch_user_list_dict[batch_name]
+ if(old_arr.indexOf(stud_id)>=0){
+ i = old_arr.indexOf(stud_id)
+ old_arr.splice(i,1)
+ }
+ batch_user_list_dict[batch_name] = old_arr
}
+ $("#batch_create_edit_table").find("#"+batch_id).next('.stud_count_in_batch').html(old_arr.length+ " student(s)")
}
- }
- else{
- if(left_drawer_count < 26){
- alertlabel = "Please add Remaining students to the batch. As " + (left_drawer_count-1) + " cannot form a new batch.";
- }
- else{
- alertlabel = "Please select atleast 30 students";
+ },
+ });//end of ajax
+
+
+ })
+
+
+ // Make an ajax call to search approved student
+ // of the selected AC with entered name
+ // ajax search student by name
+ var search_text_old = "";
+ $(document).on( 'keyup', '.ajax_input_name', function (e) {
+ var search_text = (this.value).toLowerCase();
+ var search_text_len = (search_text.length);
+ ac_id = $("#acourse_list").val();
+
+ // if (e.keyCode == 8) {
+ // // If backspace pressed, then do nothing
+ // search_text_len = 0;
+ // }
+ if (search_text_len > 2){
+ for(var key in batch_user_list_dict){
+ added_ids_list = added_ids_list.concat(batch_user_list_dict[key])
}
- $("#alertModalLabel").text(alertlabel);
- $("#alertModal").foundation('reveal', 'open');
- return false;
+
+ $.ajax({
+ type: "POST",
+ url: "{% url 'get_students_for_batches' groupid %}",
+ datatype: "json",
+ data:{
+ 'search_text': search_text,
+ 'ac_id': ac_id,
+ 'added_ids_list':added_ids_list,
+ 'csrfmiddlewaretoken': '{{ csrf_token }}'
+ },
+ success: function(data) {
+ data = JSON.parse(data)
+ success_state = data["success"];
+ search_text_old = search_text
+ // $("#alertModalLabel").text(data["message"]);
+
+ if (success_state) {
+ students_count = data["students_count"];
+ column_headers = data["column_headers"];
+ students_data_set = data["students_data_set"];
+ dataTable_columns_set = [];
+
+ 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>'
+ $(".datatable_div").html(c);
+ }
+
+ else {
+ // Define table
+ student_data_table = '<table cellpadding="0" cellspacing="0" border="0" class="display" id="student_data_table">' +
+ '<caption>' +
+ '<h6>No. of Students: <b>' + students_count + '</b></h6>' +
+ '<label>(Click on Name to select student)</label></caption>' +
+ '</table>';
+ $(".datatable_div").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);
+ }
+ });
+ }
+ }
+ else {
+ $("#alertModal").removeClass("success").removeClass("warning");
+ $("#alertModal").addClass("alert");
+ $("#alertModal").foundation('reveal', 'open');
+ }
+ },
+ });
}
- };
+ })
+
+ //
+ $(document).on('click','.cancel',function(){
+ $(".batch_create_div").addClass("hide")
+ $(".batch_name_inp").val("");
+ $(".create_batch_row").removeAttr("disabled")
+ });
- //Saving students to batch as batch members
- $("#form-batch").submit(function(event){
- $("#batch_user_list_dict").val(JSON.stringify(batch_user_list_list))
- $("#ac_id").val(ac_id)
- }); // end of save_after_create_batch
{% endblock %}
-
+</script>
{% block document_ready %}
{% if nussd_course_name %}
$("select#nussd_course_type").val("{{nussd_course_name}}");
@@ -466,4 +646,5 @@
if ($("select#nussd_course_type :selected").index() > 0) {
$("select#nussd_course_type").trigger("change");
}
+
{% endblock %}
diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/urls/batch.py b/gnowsys-ndf/gnowsys_ndf/ndf/urls/batch.py
index abb8a27..2d8dc6d 100644
--- a/gnowsys-ndf/gnowsys_ndf/ndf/urls/batch.py
+++ b/gnowsys-ndf/gnowsys_ndf/ndf/urls/batch.py
@@ -5,6 +5,11 @@ urlpatterns = patterns('gnowsys_ndf.ndf.views.batch',
url(r'^/edit/(?P<_id>[\w-]+)$', 'new_create_and_edit', name='edit'),
url(r'^/new_batch$', 'new_create_and_edit', name='new_batch'),
url(r'^/save_batch_stud$', 'save_students_for_batches', name='save_batch_stud'),
+ url(r'^/save_batch$', 'save_batch', name='save_batch'),
+ url(r'^/remove_stud_from_batch$', 'remove_stud_from_batch', name='remove_stud_from_batch'),
+ url(r'^/batch_detail$', 'batch_detail', name='batch_detail'),
url(r'^/detail/(?P<_id>[\w-]+)$', 'detail', name='detail'),
url(r'^/delete_batch/(?P<_id>[\w-]+)$', 'delete_batch', name='delete_batch'),
+ url(r'^/get_possible_batches/$', 'get_possible_batches', name='get_possible_batches'),
)
+
diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py
index 6798633..0c3b742 100644
--- a/gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py
+++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py
@@ -4574,110 +4574,79 @@ def mp_approve_students(student_cur, course_ids, course_enrollment_status_text,
p.join()
return resultlist
+# ====================================================================================================
+
@get_execution_time
def get_students_for_batches(request, group_id):
- """
- This view returns ...
-
- 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': ""}
- b_arr=[]
- try:
- if request.is_ajax() and request.method == "GET":
- btn_id = request.GET.get('btn_id', "")
- batch_id = request.GET.get('node_id', "")
- ac_id = request.GET.get('ac_id', "")
-
- batch_name_index = 1
- batches_for_same_course = []
- all_batches_in_grp = []
- batch_mem_dict = {}
- batch_member_list = []
-
- batch_gst = node_collection.one({'_type':"GSystemType", 'name':"Batch"})
-
- batch_for_group = node_collection.find({'member_of': batch_gst._id, 'relation_set.has_course': ObjectId(ac_id)})
-
- for each1 in batch_for_group:
- existing_batch = node_collection.one({'_id': ObjectId(each1._id)})
- batch_name_index += 1
- for each2 in each1.relation_set:
- if "has_batch_member" in each2:
- batch_member_list.extend(each2['has_batch_member'])
- break
- each1.get_neighbourhood(each1.member_of)
- batch_mem_dict[each1.name] = each1
-
- # College's ObjectId is required, if student record can't be found
- # using group's ObjectId
- # A use-case where records created via csv file appends MIS_admin group's
- # ObjectId in group_set field & not college-group's ObjectId
- ann_course = node_collection.one({'_id': ObjectId(ac_id)}, {'relation_set.acourse_for_college': 1,"relation_set.course_has_enrollment":1})
- sce_id = None
- for rel in ann_course.relation_set:
- if rel and "course_has_enrollment" in rel:
- sce_id = rel["course_has_enrollment"][0]
- break
-
- sce_node = node_collection.one({"_id":ObjectId(sce_id)},{"attribute_set.has_approved":1})
-
- approved_students_list = []
- for attr in sce_node.attribute_set:
- if attr and "has_approved" in attr:
- approved_students_list = attr["has_approved"]
- break
-
- approve_not_in_batch_studs = [stud_id for stud_id in approved_students_list if stud_id not in batch_member_list]
-
- student = node_collection.one({'_type': "GSystemType", 'name': "Student"})
-
- res = node_collection.find(
- {
- '_id': {"$in": approve_not_in_batch_studs},
- 'member_of': student._id
- # '$or': [
- # {'group_set': ObjectId(group_id)},
- # {'relation_set.student_belongs_to_college': college_id}
- # ],
- # 'relation_set.selected_course': ObjectId(ac_id)
- },
- {'_id': 1, 'name': 1, 'member_of': 1, 'created_by': 1, 'created_at': 1, 'content': 1}
- ).sort("name", 1)
-
-
- drawer_template_context = edit_drawer_widget("RelationType", group_id, None, None, None, left_drawer_content=res)
- drawer_template_context["widget_for"] = "new_create_batch"
- drawer_widget = render_to_string(
- 'ndf/drawer_widget.html',
- drawer_template_context,
- context_instance = RequestContext(request)
- )
-
- response_dict["success"] = True
- response_dict["drawer_widget"] = drawer_widget
- response_dict["student_count"] = res.count()
- response_dict["batch_name_index"] = batch_name_index
- response_dict["batches_for_same_course"] = json.dumps(batch_mem_dict, cls=NodeJSONEncoder)
+ """
+ This view returns ...
- return HttpResponse(json.dumps(response_dict))
- else:
- error_message = "Batch Drawer: Either not an ajax call or not a GET request!!!"
- response_dict["message"] = error_message
- return HttpResponse(json.dumps(response_dict))
+ 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': ""}
+ result_set = None
+ query = {}
+ try:
+ if request.is_ajax() and request.method == "POST":
+ ann_course_id = unicode(request.POST.get('ac_id', ""))
+ added_ids_list = request.POST.getlist('added_ids_list[]', "")
+ if added_ids_list:
+ added_ids_list = list(set(added_ids_list))
+ search_text = unicode(request.POST.get('search_text', ""))
+ stud_gst = node_collection.one({'_type': "GSystemType", 'name': "Student"})
+ query.update({'member_of': stud_gst._id})
+ if added_ids_list:
+ added_ids_list = [ObjectId(each) for each in added_ids_list]
+ query.update({'_id': {'$nin': added_ids_list}})
+ query.update({'name': {'$regex': search_text, '$options': "i"}})
+ query.update({'attribute_set.course_enrollment_status.' + ann_course_id: 'Enrollment Approved'})
+ response_dict["success"] = True
+ rec = node_collection.collection.aggregate([{'$match': query},
+ {'$project': {'_id': 0,
+ 'stud_id': '$_id',
+ 'enrollment_code': '$attribute_set.enrollment_code',
+ 'name': '$name',
+ # 'email_id': '$attribute_set.email_id',
+ # 'phone': '$attribute_set.mobile_number',
+ 'year_of_study': '$attribute_set.degree_year',
+ 'degree': '$attribute_set.degree_specialization',
+ # 'college': '$relation_set.student_belongs_to_college',
+ # 'college_roll_num': '$attribute_set.college_enroll_num',
+ # 'university': '$relation_set.student_belongs_to_university',
+ }},
+ {'$sort': {'enrollment_code': 1}}
+ ])
+ result_set = rec['result']
+ # Column headers to be displayed on json_data
+ column_headers = [
+ ('enrollment_code', 'Enr Code'),
+ ("name", "Name"),
+ ("degree", "Degree/Stream"),
+ ("year_of_study", "Year of Study"),
+ ]
+
+ students_count = len(result_set)
+ response_dict["students_data_set"] = result_set
+ response_dict["success"] = True
+ response_dict["students_count"] = students_count
+ response_dict["column_headers"] = column_headers
+ return HttpResponse(json.dumps(response_dict, cls=NodeJSONEncoder))
+ else:
+ error_message = "BatchFetchError: Either not an ajax call or not a GET request!!!"
+ response_dict["message"] = json_datarror_message
+ return HttpResponse(json.dumps(response_dict))
- except Exception as e:
- error_message = "Batch Drawer: " + str(e) + "!!!"
- response_dict["message"] = error_message
- return HttpResponse(json.dumps(response_dict))
+ except Exception as e:
+ error_message = "BatchFetchError: " + str(e) + "!!!"
+ response_dict["message"] = error_message
+ return HttpResponse(json.dumps(response_dict))
-# ====================================================================================================
@get_execution_time
def edit_task_title(request, group_id):
@@ -4987,7 +4956,7 @@ def event_assginee(request, group_id, app_set_instance_id=None):
performance_record_dict = {}
marks_dict = {}
student_node = node_collection.find_one({"_id":ObjectId(a['Name'])})
-
+
for i in student_node.attribute_set:
if unicode('student_event_details') in i.keys():
student_dict.update(i['student_event_details'])
diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/batch.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/batch.py
index 7f2a66a..c90530a 100644
--- a/gnowsys-ndf/gnowsys_ndf/ndf/views/batch.py
+++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/batch.py
@@ -1,6 +1,6 @@
from django.http import HttpResponseRedirect
-#from django.http import HttpResponse
-from django.shortcuts import render_to_response #render uncomment when to use
+from django.http import HttpResponse
+from django.shortcuts import render_to_response # render uncomment when to use
from django.template import RequestContext
from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required
@@ -12,10 +12,11 @@ try:
except ImportError: # old pymongo
from pymongo.objectid import ObjectId
-from gnowsys_ndf.settings import GAPPS, MEDIA_ROOT
-from gnowsys_ndf.ndf.models import GSystemType, Node
+# from gnowsys_ndf.settings import GAPPS, MEDIA_ROOT
+# from gnowsys_ndf.ndf.models import GSystemType, Node
+from gnowsys_ndf.ndf.models import NodeJSONEncoder
from gnowsys_ndf.ndf.models import node_collection, triple_collection
-from gnowsys_ndf.ndf.views.methods import create_grelation,get_execution_time
+from gnowsys_ndf.ndf.views.methods import create_grelation, get_execution_time, get_group_name_id
GST_BATCH = node_collection.one({"_type": "GSystemType", 'name': "Batch"})
app = GST_BATCH
@@ -26,59 +27,64 @@ def batch(request, group_id):
"""
* Renders a list of all 'batches' available within the database.
"""
- ins_objectid = ObjectId()
- st_student = node_collection.one({'_type':'GSystemType','name':'Student'})
- if ins_objectid.is_valid(group_id) is False :
- group_ins = node_collection.find_one({'_type': "Group","name": group_id})
- auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) })
- if group_ins:
- group_id = str(group_ins._id)
- else :
- auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) })
- if auth :
- group_id = str(auth._id)
- else :
- pass
+ group_name, group_id = get_group_name_id(group_id)
+ # ins_objectid = ObjectId()
+ # st_student = node_collection.one({'_type':'GSystemType','name':'Student'})
+ # if ins_objectid.is_valid(group_id) is False :
+ # group_ins = node_collection.find_one({'_type': "Group","name": group_id})
+ # auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) })
+ # if group_ins:
+ # group_id = str(group_ins._id)
+ # else :
+ # auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) })
+ # if auth :
+ # group_id = str(auth._id)
+ # else :
+ # pass
nussd_course_type_name = ""
announced_course_name = ""
- print group_id
if request.method == "POST":
- announced_course_name = request.POST.get("announced_course_name", "")
- nussd_course_type_name = request.POST.get("nussd_course_name","")
- colg_gst = node_collection.one({'_type': "GSystemType", 'name': 'College'})
- req_colg_id = node_collection.one({'member_of':colg_gst._id,'relation_set.has_group':ObjectId(group_id)})
- batch_coll = node_collection.find({'member_of':GST_BATCH._id,'relation_set.has_course':ObjectId(announced_course_name)})
- # for each_batch in batch_coll:
- # each_batch['batch_name_human_readble'] = (each_batch.name).replace('_',' ')
+ announced_course_name = request.POST.get("announced_course_name", "")
+ nussd_course_type_name = request.POST.get("nussd_course_name", "")
+ # colg_gst = node_collection.one({'_type': "GSystemType", 'name': 'College'})
+ # req_colg_id = node_collection.one({'member_of': colg_gst._id, 'relation_set.has_group': ObjectId(group_id)})
+ batch_coll = node_collection.find({'member_of': GST_BATCH._id, 'relation_set.has_course': ObjectId(announced_course_name)})
+ # for each_batch in batch_coll:
+ # each_batch['batch_name_human_readble'] = (each_batch.name).replace('_',' ')
else:
- batch_coll = node_collection.find({'member_of': GST_BATCH._id,'relation_set.batch_in_group':ObjectId(group_id)})
+ batch_coll = node_collection.find({'member_of': GST_BATCH._id, 'relation_set.batch_in_group':ObjectId(group_id)})
fetch_ATs = ["nussd_course_type"]
req_ATs = []
for each in fetch_ATs:
- each = node_collection.one({'_type': "AttributeType", 'name': each}, {'_type': 1, '_id': 1, 'data_type': 1, 'complex_data_type': 1, 'name': 1, 'altnames': 1})
-
- if each["data_type"] == "IS()":
- dt = "IS("
- for v in each.complex_data_type:
- dt = dt + "u'" + v + "'" + ", "
- dt = dt[:(dt.rfind(", "))] + ")"
- each["data_type"] = dt
+ each = node_collection.one({'_type': "AttributeType", 'name': each}, {'_type': 1, '_id': 1, 'data_type': 1, 'complex_data_type': 1, 'name': 1, 'altnames': 1})
- each["data_type"] = eval(each["data_type"])
- each["value"] = None
- req_ATs.append(each)
+ if each["data_type"] == "IS()":
+ dt = "IS("
+ for v in each.complex_data_type:
+ dt = dt + "u'" + v + "'" + ", "
+ dt = dt[:(dt.rfind(", "))] + ")"
+ each["data_type"] = dt
- #users_in_group = node_collection.one({'_id':ObjectId(group_id)}).author_set
+ each["data_type"] = eval(each["data_type"])
+ each["value"] = None
+ req_ATs.append(each)
+ # users_in_group = node_collection.one({'_id':ObjectId(group_id)}).author_set
template = "ndf/batch.html"
- variable = RequestContext(request, {'batch_coll': batch_coll,'appId':app._id,'nussd_course_name_var':nussd_course_type_name,'announced_course_name_var':announced_course_name, 'ATs': req_ATs,'group_id':group_id, 'groupid':group_id,'title':GST_BATCH.name,'st_batch_id':GST_BATCH._id})
+ variable = RequestContext(request, {'batch_coll': batch_coll,
+ 'appId': app._id,
+ 'nussd_course_name_var': nussd_course_type_name,
+ 'announced_course_name_var': announced_course_name,
+ 'ATs': req_ATs, 'group_id': group_id,
+ 'groupid': group_id, 'title': GST_BATCH.name,
+ 'st_batch_id': GST_BATCH._id})
return render_to_response(template, variable)
@get_execution_time
def new_create_and_edit(request, group_id, _id=None):
- node = ""
- count = ""
+ # node = ""
+ # count = ""
batch = ""
batch_count = 1
ac = None
@@ -87,14 +93,14 @@ def new_create_and_edit(request, group_id, _id=None):
if request.method == 'POST':
batch_count = int(request.POST.get('batch_count', ''))
- st_student = node_collection.one({'_type':'GSystemType','name':'Student'})
+ st_student = node_collection.one({'_type': 'GSystemType', 'name': 'Student'})
student_coll = node_collection.find(
{'member_of': st_student._id, 'group_set': ObjectId(group_id)}
)
if _id:
batch = node_collection.one(
- {'_id':ObjectId(_id)},
+ {'_id': ObjectId(_id)},
{'relation_set.has_course': 1, 'name': 1}
)
@@ -109,7 +115,8 @@ def new_create_and_edit(request, group_id, _id=None):
if ac:
for attr in ac.attribute_set:
- if attr and attr.has_key("nussd_course_type"):
+ # if attr and attr.has_key("nussd_course_type"):
+ if attr and "nussd_course_type" in attr:
nussd_course_name = attr["nussd_course_type"]
break
@@ -121,28 +128,29 @@ def new_create_and_edit(request, group_id, _id=None):
if each["data_type"] == "IS()":
dt = "IS("
for v in each.complex_data_type:
- dt = dt + "u'" + v + "'" + ", "
+ dt = dt + "u'" + v + "'" + ", "
dt = dt[:(dt.rfind(", "))] + ")"
each["data_type"] = dt
each["data_type"] = eval(each["data_type"])
each["value"] = None
req_ATs.append(each)
-
+
variable = RequestContext(request, {
- 'group_id': group_id, 'groupid': group_id,
+ 'group_id': group_id, 'groupid': group_id,
'appId': app._id, 'title': GST_BATCH.name, 'ATs': req_ATs,
- 'count':batch_count, 'batch_count': xrange(batch_count), 'st_batch_id': GST_BATCH._id,
- 'ac_node': ac,
- 'student_count': student_coll.count(),
- 'nussd_course_name': nussd_course_name,
+ 'count': batch_count, 'batch_count': xrange(batch_count), 'st_batch_id': GST_BATCH._id,
+ 'ac_node': ac,
+ 'student_count': student_coll.count(),
+ 'nussd_course_name': nussd_course_name,
'node': batch
})
-
+
template = "ndf/new_create_batch.html"
return render_to_response(template, variable)
-@get_execution_time
+
+@get_execution_time
def save_students_for_batches(request, group_id):
'''
This save method creates new and update existing the batches
@@ -150,47 +158,68 @@ def save_students_for_batches(request, group_id):
edit_batch = []
if request.method == 'POST':
batch_user_list = request.POST.get('batch_user_list_dict', '')
+ # print "\n\n batch_user_list_dict", batch_user_list
batch_user_list = json.loads(batch_user_list)
ac_id = request.POST.get('ac_id', '')
+ # print "\n\n ac_id", ac_id
+ # raise Exception("batch")
+ for k, v in batch_user_list.items():
+ save_btch(k, v, group_id, request, ac_id)
+ return HttpResponseRedirect(reverse('batch', kwargs={'group_id': group_id}))
- for k,v in batch_user_list.items():
- save_batch(k,v, group_id, request, ac_id)
- return HttpResponseRedirect(reverse('batch',kwargs={'group_id':group_id}))
@get_execution_time
-def save_batch(batch_name, user_list, group_id, request, ac_id):
-
- rt_has_batch_member = node_collection.one({'_type':'RelationType', 'name':'has_batch_member'})
- all_batches_in_grp=[]
- b_node = node_collection.one({'member_of':GST_BATCH._id,'name':unicode(batch_name)})
- if not b_node:
- b_node = node_collection.collection.GSystem()
- b_node.member_of.append(GST_BATCH._id)
- b_node.created_by = int(request.user.id)
- b_node.group_set.append(ObjectId(group_id))
- b_node.name = batch_name
- b_node.name = batch_name
- b_node['altnames'] = batch_name.replace('_',' ')
-
- b_node.contributors.append(int(request.user.id))
- b_node.modified_by = int(request.user.id)
- b_node.save()
- all_batches_in_grp.append(b_node._id)
-
- rt_group_has_batch = node_collection.one({'_type':'RelationType', 'name':'group_has_batch'})
- rt_has_course = node_collection.one({'_type':'RelationType', 'name':'has_course'})
-
- relation_coll = triple_collection.find({'_type':'GRelation','relation_type.$id':rt_group_has_batch._id,'subject':ObjectId(group_id)})
-
- for each in relation_coll:
- all_batches_in_grp.append(each.right_subject)
- #to get all batches of the group
-
- create_grelation(b_node._id,rt_has_batch_member,user_list)
+def save_batch(request, group_id):
+# def save_batch(batch_name, user_list, group_id, request, ac_id):
+
+ group_name, group_id = get_group_name_id(group_id)
+ response_dict = {"success": False}
+ # new_batch_node = None
+ rt_has_batch_member = node_collection.one({'_type': 'RelationType', 'name': 'has_batch_member'})
+ if request.is_ajax() and request.method == "POST":
+ ac_id = request.POST.get("ac_id", '')
+ batch_name = request.POST.get("batch_name", '')
+ batch_id = request.POST.get("batch_id", '')
+ user_list = request.POST.getlist("user_list[]", '')
+ # create_new_batch = request.POST.get("create_new_batch", '')
+ # response_dict["old_batches"] = find_batches_of_ac(ac_id)
+ user_list = [ObjectId(each) for each in user_list]
+ all_batches_in_grp = []
+ if not batch_id:
+ # b_node = node_collection.one({'member_of':GST_BATCH._id,'name':unicode(batch_name)})
+ b_node = node_collection.collection.GSystem()
+ b_node.member_of.append(GST_BATCH._id)
+ b_node.created_by = int(request.user.id)
+ b_node.group_set.append(ObjectId(group_id))
+ b_node.name = batch_name
+ b_node['altnames'] = batch_name.replace('_', ' ')
+
+ b_node.contributors.append(int(request.user.id))
+ b_node.modified_by = int(request.user.id)
+ b_node.save()
+ all_batches_in_grp.append(b_node._id)
+
+ rt_group_has_batch = node_collection.one({'_type': 'RelationType', 'name': 'group_has_batch'})
+ relation_coll = triple_collection.find({'_type': 'GRelation', 'relation_type.$id': rt_group_has_batch._id,'subject':ObjectId(group_id)})
+
+ for each in relation_coll:
+ all_batches_in_grp.append(each.right_subject)
+ # to get all batches of the group
+ rt_has_course = node_collection.one({'_type': 'RelationType', 'name': 'has_course'})
+
+ create_grelation(ObjectId(group_id), rt_group_has_batch, all_batches_in_grp)
+ create_grelation(b_node._id, rt_has_course, ObjectId(ac_id))
+ response_dict['new_batch_created'] = True
+ response_dict['new_batch_node_name'] = b_node.name
+ response_dict['new_batch_node_id'] = str(b_node._id)
+ else:
+ response_dict['new_batch_created'] = False
+ b_node = node_collection.one({'_id': ObjectId(batch_id)})
+ if user_list:
+ create_grelation(b_node._id, rt_has_batch_member, user_list)
+ response_dict['success'] = True
+ return HttpResponse(json.dumps(response_dict, cls=NodeJSONEncoder))
- create_grelation(b_node._id,rt_has_course,ObjectId(ac_id))
-
- create_grelation(ObjectId(group_id),rt_group_has_batch,all_batches_in_grp)
@get_execution_time
def detail(request, group_id, _id):
@@ -198,7 +227,7 @@ def detail(request, group_id, _id):
node = node_collection.one({'_id':ObjectId(_id)})
rt_has_batch_member = node_collection.one({'_type':'RelationType','name':'has_batch_member'})
relation_coll = triple_collection.find({'_type':'GRelation','relation_type.$id':rt_has_batch_member._id,'subject':node._id,'status':u'PUBLISHED'})
-
+
for each in relation_coll:
n = node_collection.one({'_id':ObjectId(each.right_subject)})
student_coll.append(n)
@@ -207,37 +236,104 @@ def detail(request, group_id, _id):
return render_to_response(template, variable)
+@get_execution_time
+def remove_stud_from_batch(request, group_id):
+ group_name, group_id = get_group_name_id(group_id)
+ if request.is_ajax() and request.method == "POST":
+ batch_id = request.POST.get("batch_id", '')
+ stud_id = request.POST.get("stud_id", '')
+ rt_has_batch_member = node_collection.one({'_type':'RelationType','name':'has_batch_member'})
+ grelation_node = triple_collection.one({'_type':'GRelation',
+ 'relation_type.$id':rt_has_batch_member._id,
+ 'subject':ObjectId(batch_id),'status':u'PUBLISHED',
+ 'right_subject': ObjectId(stud_id)})
+ rel_name = grelation_node.relation_type.name
+ inv_rel_name = grelation_node.relation_type.inverse_name
+ subj = grelation_node.subject
+ right_subj = grelation_node.right_subject
+
+ # Remove right-subject-node's ObjectId from the value
+ # corresponding to subject-node's "relation-name" key
+ # referenced in relation_set field
+ res = node_collection.collection.update({
+ '_id': subj,
+ 'relation_set.' + rel_name: {'$exists': True}
+ }, {
+ '$pull': {'relation_set.$.' + rel_name: right_subj}
+ },
+ upsert=False, multi=False
+ )
+ # Remove subject-node's ObjectId from the value corresponding
+ # to right-subject-node's "inverse-relation-name" key
+ # referenced in relation_set field
+ res = node_collection.collection.update({
+ '_id': right_subj,
+ 'relation_set.' + inv_rel_name: {'$exists': True}
+ }, {
+ '$pull': {'relation_set.$.' + inv_rel_name: subj}
+ },
+ upsert=False, multi=False
+ )
+
+ grelation_node.status = u"DELETED"
+ grelation_node.save()
+ status = "success"
+ return HttpResponse(json.dumps(status, cls=NodeJSONEncoder))
+
+
+@get_execution_time
+def batch_detail(request, group_id):
+ group_name, group_id = get_group_name_id(group_id)
+ new_batch_node = None
+ if request.is_ajax() and request.method == "GET":
+ batch_id = request.GET.get("batch_id", '')
+
+ student_coll = []
+ node = node_collection.one({'_id':ObjectId(batch_id)})
+ rt_has_batch_member = node_collection.one({'_type':'RelationType','name':'has_batch_member'})
+ relation_coll = triple_collection.find({'_type':'GRelation','relation_type.$id':rt_has_batch_member._id,'subject':node._id,'status':u'PUBLISHED'})
+
+ for each in relation_coll:
+ n = node_collection.one({'_id':ObjectId(each.right_subject)})
+ student_coll.append(n)
+ return HttpResponse(json.dumps(student_coll, cls=NodeJSONEncoder))
+
+
+
@login_required
@get_execution_time
-def delete_batch(request,group_id,_id):
- if ObjectId.is_valid(group_id) is False :
- group_ins = node_collection.find_one({'_type': "Group","name": group_id})
- auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) })
- if group_ins:
- group_id = str(group_ins._id)
- else :
- auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) })
- if auth :
- group_id = str(auth._id)
- else :
- pass
-
- node = node_collection.one({ '_id': ObjectId(_id)})
- left_relations = triple_collection.find({"_type":"GRelation", "subject":node._id})
- right_relations = triple_collection.find({"_type":"GRelation", "right_subject":node._id})
- attributes = triple_collection.find({"_type":"GAttribute", "subject":node._id})
+def delete_batch(request, group_id, _id):
+
+ group_name, group_id = get_group_name_id(group_id)
+
+ # if ObjectId.is_valid(group_id) is False :
+ # group_ins = node_collection.find_one({'_type': "Group","name": group_id})
+ # auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) })
+ # if group_ins:
+ # group_id = str(group_ins._id)
+ # else :
+ # auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) })
+ # if auth :
+ # group_id = str(auth._id)
+ # else :
+ # pass
+
+ node = node_collection.one({'_id': ObjectId(_id)})
+ left_relations = triple_collection.find({"_type": "GRelation", "subject": node._id})
+ right_relations = triple_collection.find({"_type": "GRelation", "right_subject": node._id})
+ attributes = triple_collection.find({"_type": "GAttribute", "subject": node._id})
for eachobject in right_relations:
# If given node is used in relationship with any other node (as right_subject)
# Then this node's ObjectId must be removed from relation_set field of other node
node_collection.collection.update(
- {'_id': eachobject.subject, 'relation_set.'+eachobject.relation_type.name: {'$exists': True}},
- {'$pull': {'relation_set.$.'+eachobject.relation_type.name: node._id}},
+ {'_id': eachobject.subject, 'relation_set.' + eachobject.relation_type.name: {'$exists': True}},
+ {'$pull': {'relation_set.$.' + eachobject.relation_type.name: node._id}},
upsert=False, multi=False
)
eachobject.delete()
- all_associates = list(left_relations)+list(attributes)
+ all_associates = list(left_relations) + list(attributes)
# Deleting GAttributes and GRelations where given node is used as left subject
for eachobject in all_associates:
eachobject.delete()
@@ -245,3 +341,37 @@ def delete_batch(request,group_id,_id):
# Finally deleting given node
node.delete()
return HttpResponseRedirect(reverse('batch', kwargs={'group_id': group_id}))
+
+
+@login_required
+def get_possible_batches(request, group_id):
+ '''
+ Returns:
+ * Batches of selected course
+ '''
+ group_name, group_id = get_group_name_id(group_id)
+ response_dict = {"success": False}
+ new_batch_node = None
+ if request.is_ajax() and request.method == "POST":
+ ac_id = request.POST.get("ac_id", '')
+ create_new_batch = request.POST.get("create_new_batch", '')
+ response_dict["success"] = True
+ batch_user_list_dict = []
+ list_of_members = []
+ if ac_id:
+ batch_cur = node_collection.find({'member_of': GST_BATCH._id,
+ 'relation_set.has_course': ObjectId(ac_id)})
+ for each_batch in batch_cur:
+ each_batch_dict = {}
+ if each_batch.relation_set:
+ for rel in each_batch.relation_set:
+ list_of_members = []
+ if rel and 'has_batch_member' in rel:
+ list_of_members.append(rel['has_batch_member'])
+ list_of_members.append(str(each_batch._id))
+ each_batch_dict[each_batch.name] = list_of_members
+ batch_user_list_dict.append(each_batch_dict)
+ # batch_user_list_dict.append(str(each_batch._id))
+ # print "\n\nBatches----------", batch_user_list_dict
+ response_dict["old_batches"] = batch_user_list_dict
+ return HttpResponse(json.dumps(response_dict, cls=NodeJSONEncoder))
diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/enrollment.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/enrollment.py
index 87758d7..82e6d2f 100644
--- a/gnowsys-ndf/gnowsys_ndf/ndf/views/enrollment.py
+++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/enrollment.py
@@ -372,7 +372,11 @@ def enrollment_create_edit(request, group_id, app_id, app_set_id=None, app_set_i
for each_enrollment_task in enrollment_task_ids:
if not updated_one_task:
each_enrollment_task_node = node_collection.one({'_id': ObjectId(each_enrollment_task)})
- task_status = each_enrollment_task_node.attribute_set[0]['Status']
+ if each_enrollment_task_node.attribute_set:
+ for each_attr_task in each_enrollment_task_node.attribute_set:
+ if each_attr_task and 'Status' in each_attr_task:
+ task_status = each_attr_task['Status']
+ # task_status = each_enrollment_task_node.attribute_set[0]['Status']
if task_status in list_of_task_status:
task_dict = {}
diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/methods.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/methods.py
index f5d3180..ba06250 100644
--- a/gnowsys-ndf/gnowsys_ndf/ndf/views/methods.py
+++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/methods.py
@@ -4052,3 +4052,5 @@ def repository(request, group_id):
},
context_instance=RequestContext(request)
)
+
+