diff options
author | katkamrachana <katkam.rachana@gmail.com> | 2015-04-13 19:50:06 +0530 |
---|---|---|
committer | katkamrachana <katkam.rachana@gmail.com> | 2015-04-13 19:50:06 +0530 |
commit | 83e238cc279ad5d34a408a13a81c2f8913ccfac8 (patch) | |
tree | 7e622af9889744e5f4887ca44f32727b89a8a2c8 | |
parent | 5197bf2eac95dc98b138273f77a0c9ef332c5175 (diff) | |
download | gnowsys-83e238cc279ad5d34a408a13a81c2f8913ccfac8.tar.gz |
Course Authoring Updated
9 files changed, 582 insertions, 281 deletions
diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course_detail.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course_detail.html index 29a61fa..2392459 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course_detail.html +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course_detail.html @@ -80,7 +80,7 @@ <div id="cs-div"></div> {% if not course_structure_exists %}<div> <label>{% trans "You haven't added any content to this course yet" %}</label></div>{% endif %} - <span class="small-6 columns end right inline" ><a class=" button" href="{% url 'create_course_struct' group_name_tag node.pk %}" target="_blank">{% if course_structure_exists %}{% trans "Edit Course Structure" %}{% else %}{% trans "Add Course Structure" %}{% endif %}</a></span> + <span class="small-6 columns end right inline" ><a class=" button" href="{% url 'create_course_struct' group_id node.pk %}">{% if course_structure_exists %}{% trans "Edit Course Structure" %}{% else %}{% trans "Add Course Structure" %}{% endif %}</a></span> </fieldset> {% endblock %} diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course_details.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course_details.html index d9981d6..9c96f5a 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course_details.html +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course_details.html @@ -50,7 +50,6 @@ <!-- overiding block from node_detail_base.html --> {% block body_content %} -{% get_group_name groupid as group_name_tag %} <header class="row"> <div class="row"> <h2 class="small-6 columns end"> {{node.name}}</h2> @@ -119,7 +118,7 @@ {% if not course_structure_exists %}<div> <label>{% trans "You haven't added any content to this course yet" %}</label></div>{% endif %} - <span class="small-6 columns end right inline" ><a class=" button" href="{% url 'create_course_struct' group_name_tag node.pk %}?app_id={{app_id}}&app_set_id={{app_set_id}}" target="_blank">{% if course_structure_exists %}{% trans "Edit Course Structure" %}{% else %}{% trans "Add Course Structure" %}{% endif %}</a></span> + <span class="small-6 columns end right inline" ><a class=" button" href="{% url 'create_course_struct' groupid node.pk %}?app_id={{app_id}}&app_set_id={{app_set_id}}">{% if course_structure_exists %}{% trans "Edit Course Structure" %}{% else %}{% trans "Add Course Structure" %}{% endif %}</a></span> </fieldset> {% endif %} </div> diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course_units.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course_units.html index a2ff60c..db0a785 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course_units.html +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course_units.html @@ -4,7 +4,7 @@ {% block title %} {{title}} {% endblock %} {% load pagination_tags %} {% block style %} - + {{block.super}} .td_cell{ @@ -19,37 +19,42 @@ cursor:pointer; } - table, th, td { - border: 1px solid white; - } + table, th, td{ + border: 1px solid white; + } - .resource-drawer { - border-color: #D3D3D3; border-style: solid; - padding: 0 !important; - overflow-y: auto; + .resource-drawer{ + border-color: #D3D3D3; border-style: solid; + padding: 0 !important; + overflow-y: auto; } div.resources_drawer_div div{ padding:1px; } + .resource-drawer li.bullet-item:hover{ - background-color: #ecf0f1; cursor:pointer; + background-color: #ecf0f1; cursor:pointer; } - .posted-by{ color: #808080; font-size: small; } - - .selected-resource { background-color:lightgray !important ; } + .posted-by{ + color: #808080; + font-size: small; + } - .resource-type-image { - height:40px; - background-repeat:no-repeat; background-size: 48px 48px; - width:16.667%; + .selected-resource{ + background-color:lightgray !important; } - .resource-type-image + div { - width:83.33333%%; + .resource-type-image{ + height:40px; + background-repeat:no-repeat; background-size: 48px 48px; + width:16.667%; } + .resource-type-image + div{ + width:83.33333%%; + } .resource_icon{ color:#0b8a91 !important; @@ -59,7 +64,7 @@ } ul.no-bullet li ul, ul.no-bullet li ol{ - margin-left:0 !important; + margin-left:0 !important; } {% endblock %} @@ -74,42 +79,71 @@ <input type="text" id="unit_name" value="{% if unit_node %} {{unit_node.name}}{% endif %}"> </div> </div> - {% block collection %} - <div class="collection_block_div"> - <div class="choose"> - <table width="400" align="center"> - <tr class="row"> - <td class="small-4 columns td_cell fi-page-filled"> - {% trans "Page" %} - </td> - <td class="small-4 columns td_cell fi-book"> - {% trans "File" %} - </td> - - <td class="small-4 columns td_cell fi-photo"> - {% trans "Image" %} - </td> - </tr> - <tr class="row"> - <td class="small-4 columns td_cell fi-video"> - {% trans "Video" %} - </td> - <td class="small-4 columns td_cell fi-video"> - {% trans "Pandora" %} - </td> - <td class="small-4 columns td_cell fi-pencil"> - {% trans "Quiz" %} - </td> - </tr> - </table> + <div class="unit-list-div"> + <ul class="button-group"> + <li><a onclick="open_div('Page',this)" class="button">Page </a></li> + <li><a onclick="open_div('File',this)" class="button">File </a></li> + <li><a onclick="open_div('Image')" class="button">Image </a></li> + <li><a onclick="open_div('Video')" class="button">Video </a></li> + <li><a onclick="open_div('Pandora')" class="button">Pandora</a></li> + <li><a onclick="open_div('Quiz')" class="button">Quiz</a></li> + </ul> + </div> + <div id="view_add_page" class="row hide"> + + <h5>{% trans "Add New Page: " %}</h5> + <!-- To enter name of the page --> + <div class="small-6 columns"> + <input class="name_id" name="name" type="text" placeholder="Enter name ..."> + </div> + <div class="small-6 columns"> + <input type="submit" id="add_page" value="Save Page" class="tiny round button"/> + <input type="button" id="cancel_btn" value="Cancel" class="tiny round button"/> + </div> + </div> + + <div id="view_add_file" class="hide"> + <h5>{% trans "Add New File: " %}</h5><br/> + <!-- Upload file --> + <form class="dropzone" id ="docPost" enctype="multipart/form-data" method="post" action="{% url 'add_file' group_id %}?context_node={{unit_node.pk}}"> + {% csrf_token %} + <div> + <span class="fi-upload"><input type="file" name="doc[]" id="docFile" multiple/></span> + </div> + <!-- For making access policy of files PUBLIC initially by uploading it from topic page --> + <input type="hidden" name="login-mode" value="PUBLIC"> + <!-- Just a hidden value which enables us to retun to add_file() in ajax_views when any file gets uploaded --> + <input type="hidden" name="type" value="topic_file"> + <!-- This is for getting the user of the uploaded file --> + <input type="hidden" name="context_name" id="context_name" value="Course"> + <input type="hidden" name="unit_name_file" id="unit_name_file"> + {% if app_id %} + <input type="hidden" name="app_id" id="app_id" value="{{app_id}}"> + <input type="hidden" name="app_set_id" id="app_set_id" value="{{app_set_id}}"> + {% endif %} + <input type="hidden" name="course_node" id="course_node" value="{{course_node.pk}}"> + <input type="hidden" name="css_node_id" id="css_node_id" value="{{css_node.pk}}"> + + <input type="hidden" name="user" value="{{request.user.pk}}"> + <input type="submit" class="small round button" id="add_file" value="Save File"> + </form> </div> - <span data-tooltip title="You will be redirected to Course Authoring page" style="float:right;"><a href="{% url 'create_course_struct' group_id course_node.pk %}?app_id={{app_id}}&app_set_id={{app_set_id}}" class="done_units small button round" style="float:right;">Add more units later..</a></span> - - <div class="resources_drawer_div row"></div> - <input type="button" value="Save Units" class="save_units small button round hide"> - <input type="hidden" name="hidden_unit_node_id" id="hidden_unit_node_id"> - </div> + <div class="res-opt-div hide"> + <input type="button" class="res-option button small"> + </div> + {% block collection %} + <div class="collection_block_div"> + <span data-tooltip title="You will be redirected to Course Authoring page" style="float:right;"> + <a class="done_units small button round" style="float:right;">Add more units later..</a> + </span> + </br></br></br> + + <div class="resources_drawer_div row"></div> + <input type="button" value="Save Units" class="save_units small button round hide"> + <input type="hidden" name="hidden_unit_node_id" id="hidden_unit_node_id"> + <input type="hidden" name="res_type_name" id="res_type_name"> + </div> {% endblock %} {% endblock %} @@ -117,118 +151,210 @@ {% block script %} {{block.super}} - $('td').click(function (event){ - var resource_type_name = $(this).html() - var existing_resources; + $(document).on("click", "#cancel_btn", function(){ + $("#view_add_page").addClass("hide"); + $(".name_id").val(""); + }) + + $(document).on("click", ".res-option", function(){ + n = $("#res_type_name").val(); + if(n == "Page"){ + $(".res-opt-div").append($("#view_add_page")); + $(".res-opt-div").find("#view_add_page").removeClass("hide"); + } + else if(n == "File" || n == "Image" || n == "Video" || n == "Pandora"){ + $(".res-opt-div").append($("#view_add_file")); + $(".res-opt-div").find("#view_add_file").removeClass("hide"); + } + $(".save_units").addClass("hide") + }); + + function open_div(name,this1){ + $(".resources_drawer_div").html(""); + $(".save_units").addClass("hide") + $("#res_type_name").val("") + $("#res_type_name").val(name) + $(".button").removeClass("success") + $(this1).addClass("success") + if(name!="Quiz"){ + $(".res-opt-div").removeClass("hide") + $(".res-option").val("Create new "+ name) + } + else{ + $(".res-opt-div").addClass("hide") + $(".res-option").val("") + } + draw_drawer(name); + }; + + + // function to get drawer + function draw_drawer(name){ + var resource_type_name = name; if(!$("#hidden_unit_node_id").val()==""){ unit_node_id = $("#hidden_unit_node_id").val(); } else{ unit_node_id = "{{unit_node.pk}}" } - resp_dict = {} - $.ajax({ + resp_dict = {} + $.ajax({ - type: "POST", + type: "POST", - url: "{% url 'get_resources' groupid %}", + url: "{% url 'get_resources' group_id %}", - datatype: "json", + datatype: "json", - data:{ - resource_type: resource_type_name, + data:{ + resource_type: resource_type_name, css_node_id : "{{css_node.pk}}", unit_node_id : unit_node_id, - widget_for: "create_course_structure", - csrfmiddlewaretoken: '{{ csrf_token }}' - }, - - success: function (data) { - resp_dict = data - $(".resources_drawer_div").html(""); + widget_for: "create_course_structure", + csrfmiddlewaretoken: '{{ csrf_token }}' + }, + success: function (data) { + resp_dict = data + $(".resources_drawer_div").html(""); $(".save_units").removeClass("hide") - $(".done_units").removeClass("hide") - $(".resources_drawer_div").html(resp_dict); - }, - }); + $(".done_units").removeClass("hide") + $(".resources_drawer_div").html(resp_dict); + }, + }); + } + //save file button, check wether unit name is entered + $("#add_file").click(function() { + unit_name_val = $("#unit_name").val() + if(unit_name_val!=""){ + $("#unit_name_file").val(unit_name_val); + $(".resources_drawer_div").html(""); + } + else{ + alert("Please enter unit name"); + event.preventDefault(); + } + }) + + //save page + $("#add_page").click(function() { + unit_name = $("#unit_name").val() + if(unit_name!=""){ + $.ajax({ + type: "POST", + url: "{% url 'add_page' groupid %}", + datatype: "html", + data:{ + context_node: "{{unit_node.pk}}", + name: $(".name_id").val(), + css_node: "{{css_node.pk}}", + unit_name: unit_name, + context_name: "Course", + csrfmiddlewaretoken: '{{ csrf_token }}' + }, + success: function(data) { + data = JSON.parse(data) + var page = $(".name_id").val(); + + if (data["success"] == false) { + alert("Page name "+ page +" already available, Please choose different name"); + } + + if (data["success"] === true) { + draw_drawer("Page") + $(".save_units").removeClass("hide"); + } + + $(".name_id").val(""); + $(".res-opt-div").addClass("hide"); + $("#hidden_unit_node_id").val(data["unit_node_id"]); + unit_node = data["unit_node_id"] + if(unit_node){ + url_path = window.location.href; + location.replace(url_path.replace("undefined",unit_node));} + } + }); + } + else{ + alert("Please enter unit name"); + event.preventDefault(); + } }); + // Save units $(document).on('click','.save_units',function(){ var resources_in_RHS = [] unit_name_val = $("#unit_name").val() total_resources_in_RHS = $(".resources_drawer_div").find("#create_course_structure_drawer2").children("li") if(!$("#hidden_unit_node_id").val()==""){ - unit_node_id = $("#hidden_unit_node_id").val(); } else{ unit_node_id = "{{unit_node.pk}}" } - if(unit_name_val){ - //check if right drawer has values - if(total_resources_in_RHS.length > 0){ + //check if right drawer has values + if(total_resources_in_RHS.length > 0){ + if(unit_name_val){ //fetch right drawer values $.each(total_resources_in_RHS,function(i,v){ resources_in_RHS.push(v.getAttribute('value')) }); - existing_list = JSON.stringify(resources_in_RHS) - $.ajax({ - - type: "POST", - - url: "{% url 'save_resources' groupid %}", - - datatype: "json", - - data:{ - list_of_res: existing_list, - css_node: "{{css_node.pk}}", - unit_name: unit_name_val, - unit_node_id: unit_node_id, - csrfmiddlewaretoken: '{{ csrf_token }}' - }, - - success: function (data) { - resp_dict = JSON.parse(data) - console.log(data) - $(".resources_drawer_div").html(""); - $(".save_units").addClass("hide") - $(".done_units").removeClass("hide") - if($("#hidden_unit_node_id").val()==""){ - console.log("com"+resp_dict['cu_new_id']) - // $("#hidden_unit_node_id").attr('value',resp_dict['cu_new_id']) - $("#hidden_unit_node_id").val(resp_dict['cu_new_id']) - } - }, - }); - - // $("#"+corr_resource_div).html("") - // $("#"+corr_resource_div).next().css("display", "none"); - // $(".choose").css("display", "none"); - // $(".units-btn").removeClass("hide") - // $(".course-sec-btn").removeAttr("disabled") - // $(".units-btn").removeAttr("disabled") - // $(".sub-section-btn").removeAttr("disabled") - // $(".close-units-btn").addClass("hide") + existing_list = JSON.stringify(resources_in_RHS) + $.ajax({ + + type: "POST", + + url: "{% url 'save_resources' groupid %}", + + datatype: "json", + + data:{ + list_of_res: existing_list, + css_node: "{{css_node.pk}}", + unit_name: unit_name_val, + unit_node_id: unit_node_id, + csrfmiddlewaretoken: '{{ csrf_token }}' + }, + + success: function (data) { + resp_dict = JSON.parse(data) + $(".resources_drawer_div").html(""); + $(".save_units").addClass("hide") + $(".res-opt-div").addClass("hide") + $(".done_units").removeClass("hide") + if($("#hidden_unit_node_id").val()==""){ + $("#hidden_unit_node_id").val(resp_dict['cu_new_id']) + } + }, + }); } else{ - alert("Please select any resource"); + alert("Please enter name for unit"); event.preventDefault(); } } else{ - alert("Please enter name for unit"); + alert("Please select any resource"); event.preventDefault(); } }); $(document).on('click','.done_units',function(){ + turl = "{% url 'create_course_struct' groupid course_node.pk %}" + if("{{app_id}}"!= ""){ + turl += "?app_id={{app_id}}&app_set_id={{app_set_id}}" + } + $(this).attr("href",turl) }) {% endblock %} -</script
\ No newline at end of file + + +{% block document_ready %} + {{block.super}} +{% endblock %} +</script diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/create_course_structure.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/create_course_structure.html index 7b7945d..0876563 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/create_course_structure.html +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/create_course_structure.html @@ -12,7 +12,7 @@ {{block.super}} - /* Resetting css-properties for fieldset (also legend, input) */ + /* Resetting css-properties for fieldset (also legend, input) */ /* fieldset (padding-bottom) */ fieldset { padding: 1.25rem 1.25rem 1.25rem 1.25rem !important; @@ -30,7 +30,8 @@ .edit_course_structure_name{ width: 30%; } - /* Setting css-properties for reveal-modal's label */ + + /* Setting css-properties for reveal-modal's label */ div.reveal-modal > label { color: white; font-weight: bold; @@ -42,7 +43,6 @@ padding-left:0 !important; } - i:hover{ cursor:pointer; } @@ -68,12 +68,15 @@ border: 1px solid; display:block; } + .div_lbl{ margin-top: -5px; } + .course-unit-class{ height:30px; } + #name{ margin: 5px !important; } @@ -82,10 +85,15 @@ font-size:22px; color:#0b8a91 !important; } + + span{ + width:100px; + } .resource_icon{ color:#0b8a91 !important; } + .pricing-table .bullet-item { padding:0 !important; } @@ -107,9 +115,10 @@ .lbl_of_cs, .lbl_of_css{ white-space: nowrap; overflow: hidden; + width: 35% !important; color:#0b8a91 !important; text-overflow: ellipsis; - font-size: 150%; + font-size: 130%; } .unit_name{ @@ -119,8 +128,9 @@ text-overflow: ellipsis; font-size: 80%; } + input.lbl_of_cs, input.lbl_of_css{ - width: 50% !important; + width: 35% !important; margin-top:6px; } @@ -129,49 +139,31 @@ } .unit-anch{ - font-size:150%; + font-size:130%; } - .course-section-class:hover .cs_setting{ display:block; } - - .resource-drawer { - border-color: #D3D3D3; border-style: solid; - padding: 0 !important; - overflow-y: auto; - } - - div.resources_drawer_div div{ - padding:7px; - } - .resource-drawer li.bullet-item:hover{ - background-color: #ecf0f1; cursor:pointer; - } - - .posted-by{ color: #808080; font-size: small; } - - .selected-resource { background-color:lightgray !important ; } - - .resource-type-image { - height:40px; - background-repeat:no-repeat; background-size: 48px 48px; - width:16.667%; - } - - .resource-type-image + div { - width:83.33333%%; - } {% endblock %} + {% block body_content %} - - <div id="alertModal" class="reveal-modal medium alert-box radius" data-reveal data-alert action=> - <label id="alertModalLabel"></label> + + <div id="alertModal" class="reveal-modal medium alert-box radius" data-reveal data-alert> + <p id="alertModalLabel"></p> + <div class="row deletion"> + <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">×</a> </div> + <li class="hide course-section-class" id="course-section"> <div class="row input-cs-row"> <div class="small-2 columns"> @@ -292,6 +284,7 @@ <input type="hidden" id="app_set_id" name="app_set_id" value="{{app_set_id}}"> <input type="hidden" id="app_id" name="app_id" value="{{app_id}}"> {% endblock %} + <script> {% block script %} {{block.super}} @@ -366,9 +359,9 @@ }, complete: function (result) { if(success_state){ - var str_btn="<div class='row'><div class='small-1 columns text-center fold-btn-div'><i class='fi-minus largesize'></i></div>" - var str_lbl="<span data-tooltip title='"+ lbl_val +"'><div class='small-8 columns left inline div_lbl'><label name='lbl_name' class='lbl_of_cs' id = "+ cs_new_id+" style='float:left;'>"+lbl_val+"</label><i class='fi-pencil cs_setting largesize edit_course_structure_name' style='float:left;'></i></div></span>" - var str_prop="<div class='small-2 columns end cs_setting'>"+" "+"<i class='fi-arrow-down largesize'></i>"+" "+"<i class='fi-arrow-up largesize'></i></div></div>" + var str_btn="<div class='row'><div class='small-1 columns text-center fold-btn-div'><span data-tooltip title='Expand/Collapse this Section'><i class='fi-minus largesize'></i></span></div>" + var str_lbl="<span data-tooltip title='"+ lbl_val +"'><div class='small-8 columns left inline div_lbl'><label name='lbl_name' class='lbl_of_cs' id = "+ cs_new_id+" style='float:left;'>"+lbl_val+"</label></span><span data-tooltip title='Edit name'><i class='fi-pencil cs_setting largesize edit_course_structure_name' style='float:left;'></i></span></div>" + var str_prop="<div class='small-2 columns end cs_setting'>"+" "+"<span data-tooltip title='Move Down'><i class='fi-arrow-down largesize'></i></span>"+" "+"<span data-tooltip title='Move Up'><i class='fi-arrow-up largesize'></i></span>"+" "+"<span data-tooltip title='Delete'><i class='fi-trash largesize'></i></span></div></div>" $("#"+parent_id).find("div.input-cs-row").replaceWith(str_btn+str_lbl+str_prop); $("#"+parent_id).attr("value",cs_new_id); $("#"+parent_id).find(".sub-section-btn").removeAttr("disabled"); @@ -432,8 +425,8 @@ }, complete: function () { var str_btn="<div class='row'><div class='small-1 columns text-center'><i class='fi-minus largesize fold-btn'></i></div>" - var str_lbl="<span data-tooltip title='"+ lbl_val +"'><div class='small-8 columns left inline div_lbl'><label name='lbl_name' class='lbl_of_css' id='"+ css_new_id+"' style='float:left;'>"+lbl_val+"</label><i class='fi-pencil css_setting largesize edit_course_structure_name' style='float:right;'></i></div></span>" - var str_prop="<div class='small-2 columns end css_setting'><i class='fi-widget largesize reveal_prop_form' id='widget_id'></i>"+" "+"<i class='fi-arrow-down largesize'></i>"+" "+"<i class='fi-arrow-up largesize'></i></div></div>" + var str_lbl="<span data-tooltip title='"+ lbl_val +"'><div class='small-8 columns left inline div_lbl'><label name='lbl_name' class='lbl_of_css' id='"+ css_new_id+"' style='float:left;'>"+lbl_val+"</label><span><span data-tooltip title='Edit name'><i class='fi-pencil css_setting largesize edit_course_structure_name' style='float:left;'></i></span></div>" + var str_prop="<div class='small-2 columns end css_setting'><span data-tooltip title='Settings'><i class='fi-widget largesize reveal_prop_form' id='widget_id'></i></span>"+" "+"<span data-tooltip title='Move Down'><i class='fi-arrow-down largesize'></i></span>"+" "+"<span data-tooltip title='Move Up'><i class='fi-arrow-up largesize'></i></span>"+" "+"<span data-tooltip title='Deletee'><i class='fi-trash largesize'></i></span></div></div>" $("#"+curr_css_li_id).parents("li").find("div.fold-btn-div").replaceWith("<div class='small-1 columns text-center fold-btn-div'><i class='fi-minus fold-btn largesize'></i></div>") $("#"+curr_css_li_id).parents("li").find("input.sub-section-btn").removeAttr("disabled"); @@ -491,6 +484,78 @@ } }); + var li_ele; + // Deletion----------------------------------------------------------------- + $(document).on('click','.fi-trash',function(){ + li_ele = $(this).closest('li') + oid = $(li_ele).attr("value"); + li_class = $(li_ele).attr('class'); + lbl_msg = "" + + if(li_class == "course-section-class"){ + css_msg = "" + cu_msg = "" + par_li_name = "{{cnode.name}}" + li_name = $(li_ele).find(".lbl_of_cs").text(); + css_count = $(li_ele).find('li.course-sub-section-class').length + cu_count = $(li_ele).find('li.course-unit-class').length + if(cu_count>0){ cu_msg = "And its '"+cu_count+"' unit(s) will also be deleted. "} + if(css_count>0){ css_msg = "And its '"+css_count+"' Subsection(s) will be deleted. "+cu_msg} + lbl_msg = "This will delete Section '"+ li_name +"' from Course '"+ par_li_name +"'. "+ css_msg + "Do you want to continue?" + } + else if(li_class == "course-sub-section-class"){ + cu_msg = "" + par_li_name = $(li_ele).parents('li.course-section-class').find('.lbl_of_cs').text(); + li_name = $(li_ele).find(".lbl_of_css").text(); + cu_count = $(li_ele).find('li.course-unit-class').length + if(cu_count>0){ cu_msg = "And its '"+cu_count+"' unit(s) will be deleted. "} + lbl_msg = "This will delete Subsection '"+ li_name +"' from Section '"+ par_li_name +"'. "+ cu_msg + "Do you want to continue?" + } + else if(li_class == "course-unit-class"){ + par_li_name = $(li_ele).parents('li.course-sub-section-class').find('label').text(); + li_name = $(li_ele).find('a').text(); + lbl_msg = "This will delete Unit '"+ li_name +"' from Subsection '"+ par_li_name +"'. Do you want to continue?" + } + $("#alertModalLabel").text(lbl_msg); + $("#alertModal") + .removeClass("medium").addClass("small") + .addClass("alert") + $("#alertModal").foundation('reveal', 'open'); + }); + + //trigger the ajax call to delete + function delete_func(){ + $.ajax({ + url: "{% url 'delete_from_cs' group_id %}", + + data: { + oid: oid, + 'csrfmiddlewaretoken': "{{csrf_token}}" + }, + + type: "POST", + + dataType: "json", + + success: function(data){ + success_state = data["success"] + if(success_state){ + $(li_ele).remove() + } + }, + });//end of ajax + } + + //Confirm or Cancel Deletion + $(document).on("click", "#btnConfirmYes", function() { + $("#alertModal").foundation('reveal', 'close'); + delete_func(); + }); + + $(document).on("click", "#btnConfirmNo", function() { + $("#alertModal").foundation('reveal', 'close'); + }); + // Reordering li elements to move DOWN----------------------------------------------------------------- $(document).on('click','.fi-arrow-down',function(){ var $current = $(this).closest('li'); @@ -530,31 +595,32 @@ } }, });//end of ajax - } else{ alert("You are on Last element") } }); + var var_this; // Rename Edit course structure name------------------------------------------------------------------- $(document).on('click','.edit_course_structure_name',function(){ var_this = $(this) - node_id = $(var_this).prev().attr("id"); + node_id = $(var_this).parent().prev().attr("id"); if($(var_this).hasClass("fi-pencil")){ //Only one course name can be renamed at once - node_for_edit = $(".ul-course-section").find(".fi-check").prev().attr('id') + node_for_edit = $(".ul-course-section").find(".fi-check").parent().prev().attr('id') if(node_for_edit){ node_for_edit_class = $("#"+node_for_edit).attr('class') node_for_edit_text = $("#"+node_for_edit).val() $("#"+node_for_edit).replaceWith("<label name='lbl_name' class='"+node_for_edit_class+"' id='"+node_for_edit+"' style='float:left;'>"+ node_for_edit_text+"</label>") $(".ul-course-section").find(".fi-check").removeClass("fi-check").addClass("fi-pencil") } - lbl_text = $(var_this).prev().text() - lbl_text_class = $(var_this).prev().attr('class') + lbl_text = $(var_this).parent().prev().text() + lbl_text_class = $(var_this).parent().prev().attr('class') $(var_this).removeClass("fi-pencil").addClass("fi-check"); + $(var_this).parent().attr('title','Click to Save') $("#"+node_id).replaceWith("<input type='text' id='"+node_id+"' class='"+lbl_text_class+"' value='"+ lbl_text +"' style='float:left;'>") $("#"+node_id).focus(); } @@ -580,6 +646,7 @@ success_state = data["success"] if(success_state){ $(var_this).removeClass("fi-check").addClass("fi-pencil"); + $(var_this).parent().attr('title','Edit name') $("#"+node_id).replaceWith("<label name='lbl_name' class='"+lbl_text_class+"' id='"+node_id+"' style='float:left;'>"+ new_name+"</label>") } }, @@ -588,6 +655,7 @@ else{ $("#"+node_id).replaceWith("<label name='lbl_name' class='"+lbl_text_class+"' id='"+node_id+"' style='float:left;'>"+ lbl_text+"</label>") $(var_this).removeClass("fi-check").addClass("fi-pencil"); + $(var_this).parent().attr('title','Edit name') } } }); @@ -748,11 +816,15 @@ if($(this).data("unitId")){ unit_node = $(this).data("unitId"); } - turl = "{% url 'add_units' groupid %}?css_node_id="+ css_node+"&unit_node_id="+ unit_node+"&app_id={{app_id}}&app_set_id={{app_set_id}}&course_node={{cnode.pk}}" + turl = "{% url 'add_units' groupid %}?css_node_id="+ css_node+"&unit_node_id="+ unit_node+"&course_node={{cnode.pk}}" + if("{{app_id}}"){ + turl += "&app_id={{app_id}}&app_set_id={{app_set_id}}" + } $(this).attr("href",turl) }); {% endblock %} + </script> {% block document_ready %} {{block.super}} @@ -762,9 +834,9 @@ $(".course-sec-btn").before($("#course-section").clone().attr('id',function(i,id){ cloned_ele_id = id+"_cloned"+cs_cloned_id; return cloned_ele_id}).removeClass("hide").attr("value","{{cs_node.pk}}")) - var str_btn="<div class='row'><div class='small-1 columns text-center'><i class='fi-minus largesize fold-btn'></i></div>" - var str_lbl="<span data-tooltip title='{{cs_node.name}}'><div class='small-8 columns left inline div_lbl'><label name='lbl_name' class='lbl_of_cs' id='{{cs_node.pk}}' style='float:left;'>{{cs_node.name}}</label><i class='fi-pencil cs_setting largesize edit_course_structure_name' style='float:left;'></i></div></span>" - var str_prop="<div class='small-2 columns end cs_setting'>"+" "+"<i class='fi-arrow-down largesize'></i>"+" "+"<i class='fi-arrow-up largesize'></i></div></div>" + var str_btn="<div class='row'><div class='small-1 columns text-center'><span data-tooltip title='Collapse/Expand this Section'><i class='fi-minus largesize fold-btn'></i></span></div>" + var str_lbl="<span data-tooltip title='{{cs_node.name}}'><div class='small-8 columns left inline div_lbl'><label name='lbl_name' class='lbl_of_cs' id='{{cs_node.pk}}' style='float:left;'>{{cs_node.name}}</label></span><span data-tooltip title='Edit name'><i class='fi-pencil cs_setting largesize edit_course_structure_name' style='float:left;'></i></span></div>" + var str_prop="<div class='small-2 columns end cs_setting'>"+" "+"<span data-tooltip title='Move Down'><i class='fi-arrow-down largesize'></i></span>"+" "+"<span data-tooltip title='Move Up'><i class='fi-arrow-up largesize'></i></span>"+" "+"<span data-tooltip title='Delete'><i class='fi-trash largesize'></i></span></div></div>" $("#"+cloned_ele_id).find(".sub-section-btn").removeAttr("disabled"); $("#"+cloned_ele_id).find("div.input-cs-row").replaceWith(str_btn+str_lbl+str_prop) cs_cloned_id += 1 @@ -778,11 +850,11 @@ return cloned_ss_ele_id}).removeClass("hide").attr("value","{{css_node.pk}}")); $("#"+cloned_ss_ele_id).find(".units-btn").attr("data-css-id","{{css_node.pk}}") - var str_btn1="<div class='row'><div class='small-1 columns text-center'><i class='fi-minus largesize fold-btn'></i></div>" - var str_lbl1="<span data-tooltip title='{{css_node.name}}'><div class='small-8 columns left inline div_lbl'><label name='lbl_name' class='lbl_of_css' id='{{css_node.pk}}' style='float:left;'>{{css_node.name}}</label><i class='fi-pencil css_setting largesize edit_course_structure_name' style='float:left;'></i></div></span>" + var str_btn1="<div class='row'><div class='small-1 columns text-center'><span data-tooltip title='Collapse/Expand this SubSection'><i class='fi-minus largesize fold-btn'></i></span></div>" + var str_lbl1="<span data-tooltip title='{{css_node.name}}'><div class='small-8 columns left inline div_lbl'><label name='lbl_name' class='lbl_of_css' id='{{css_node.pk}}' style='float:left;'>{{css_node.name}}</label></span><span data-tooltip title='Edit name'><i class='fi-pencil css_setting largesize edit_course_structure_name' style='float:left;'></i></span></div>" - var str_prop1="<div class='small-1 columns end css_setting'><i class='fi-widget largesize reveal_prop_form' id='widget_id'></i>"+" "+"<i class='fi-arrow-down largesize'></i>"+" "+"<i class='fi-arrow-up largesize'></i></div></div>" + var str_prop1="<div class='small-1 columns end css_setting'><span data-tooltip title='Settings'><i class='fi-widget largesize reveal_prop_form' id='widget_id'></i></span>"+" "+"<span data-tooltip title='Move Down'><i class='fi-arrow-down largesize'></i></span>"+" "+"<span data-tooltip title='Move Up'><i class='fi-arrow-up largesize'></i></span>"+" "+"<span data-tooltip title='Delete'><i class='fi-trash largesize'></i></span></div></div>" css_cloned_id+=1 $(".units-btn-div").removeClass("hide") @@ -794,7 +866,7 @@ {% get_node each_unit as unit_node %} str_unit = "<li class='course-unit-class' value='{{unit_node.pk}}'> <div class='small-4 columns end'> <a class='units-btn unit-anch' data-unit-id='{{unit_node.pk}}' style='width:50%;' data-css-id='{{css_node.pk}}'>{{unit_node.name}}</a></div>" - str_opt = "<div class='small-2 columns end'>"+" "+"<i class='fi-arrow-down largesize'></i>"+" "+"<i class='fi-arrow-up largesize'></i></div></li>" + str_opt = "<div class='small-2 columns end'>"+" "+"<span data-tooltip title='Move Down'><i class='fi-arrow-down largesize'></i></span>"+" "+"<span data-tooltip title='Move Up'><i class='fi-arrow-up largesize'></i></span>"+" "+"<span data-tooltip title='Delete'><i class='fi-trash largesize'></i></span></div></li>" $("#"+cloned_ss_ele_id).find(".new-units-btn").before(str_unit+ str_opt) {% endfor %} diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/node_details_base.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/node_details_base.html index 950806b..fa6c5d8 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/node_details_base.html +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/node_details_base.html @@ -127,6 +127,7 @@ <input type="hidden" name="login-mode" value="PUBLIC"> <!-- Just a hidden value which enables us to retun to add_file() in ajax_views when any file gets uploaded --> <input type="hidden" name="type" value="topic_file"> + <input type="hidden" name="context_name" id="context_name" value="Topic"> <!-- This is for getting the user of the uploaded file --> <input type="hidden" name="user" value="{{request.user.pk}}"> <input type="submit" class="small round button" id="add_file" value="Save File"> @@ -171,14 +172,14 @@ $("#add_page").click(function() { csrfmiddlewaretoken: '{{ csrf_token }}' }, success: function(data) { - + data = JSON.parse(data) var page = $(".name_id").val(); - if ($.trim(data) === "failure") { + if ($.trim(data["success"]) === false) { alert("Page name "+ page +" already available, Please choose different name"); } - if ($.trim(data) === "success") { + if ($.trim(data["success"]) === true) { location.reload(true); } diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/urls/course.py b/gnowsys-ndf/gnowsys_ndf/ndf/urls/course.py index e8da871..02c40d3 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/urls/course.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/urls/course.py @@ -21,4 +21,5 @@ urlpatterns = patterns('gnowsys_ndf.ndf.views.course', url(r'^/save_units/', 'save_resources', name='save_resources'), url(r'^/change_node_name/$', 'change_node_name', name='change_node_name'), url(r'^/change_order/$', 'change_order', name='change_order'), + url(r'^/delete/$', 'delete_from_course_structure', name='delete_from_cs'), ) diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py index f3bb215..bcfe36e 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py @@ -850,65 +850,130 @@ def add_page(request, group_id): if request.is_ajax() and request.method == "POST": context_node_id = request.POST.get("context_node", '') - gst_page = node_collection.one({'_type': "GSystemType", 'name': "Page"}) - context_node = node_collection.one({'_id': ObjectId(context_node_id)}) - name =request.POST.get('name','') + css_node_id = request.POST.get("css_node", '') + unit_name = request.POST.get("unit_name", '') + context_name = request.POST.get("context_name", '') + gst_page = node_collection.one({'_type': "GSystemType", 'name': "Page"}) + name = request.POST.get('name', '') collection_list = [] - if context_node: - for each in context_node.collection_set: + context_node = None + response_dict = {"success": False} + try: + context_node = node_collection.one({'_id': ObjectId(context_node_id)}) + except: + if context_name == "Course": + cu_gst = node_collection.one({'_type': "GSystemType", 'name': "CourseUnit"}) + cu_new = node_collection.collection.GSystem() + cu_new.member_of.append(cu_gst._id) + cu_new.name = unit_name.strip() + cu_new.modified_by = int(request.user.id) + cu_new.created_by = int(request.user.id) + cu_new.contributors.append(int(request.user.id)) + css_node = node_collection.one({'_id': ObjectId(css_node_id)}) + cu_new.prior_node.append(css_node._id) + cu_new.save() + context_node = cu_new + response_dict["unit_node_id"] = str(cu_new._id) + node_collection.collection.update({'_id': css_node._id}, {'$push': {'collection_set': cu_new._id }}, upsert=False, multi=False) + + for each in context_node.collection_set: obj = node_collection.one({'_id': ObjectId(each), 'group_set': ObjectId(group_id)}) collection_list.append(obj.name) - if name not in collection_list: - + if name not in collection_list: page_node = node_collection.collection.GSystem() page_node.save(is_changed=get_node_common_fields(request, page_node, group_id, gst_page)) - context_node.collection_set.append(page_node._id) context_node.save() + response_dict["success"] = True + return HttpResponse(json.dumps(response_dict)) - return HttpResponse("success") - - else: - return HttpResponse("failure") + else: + response_dict["success"] = False + return HttpResponse(json.dumps(response_dict)) - return HttpResponse("None") + response_dict["success"] = None + return HttpResponse(json.dumps(response_dict)) @get_execution_time def add_file(request, group_id): - # this is context node getting from the url get request - context_node_id=request.GET.get('context_node','') - - if request.method == "POST": - - new_list = [] - # For checking the node is already available in gridfs or not - for index, each in enumerate(request.FILES.getlist("doc[]", "")): - fileobj = node_collection.collection.File() - filemd5 = hashlib.md5(each.read()).hexdigest() - if not fileobj.fs.files.exists({"md5": filemd5}): - # If not available append to the list for making the collection for topic bellow - new_list.append(each) - else: - # If availbale ,then return to the topic page - var1 = "/"+group_id+"/topic_details/"+context_node_id+"" - return HttpResponseRedirect(var1) - - # After taking new_lst[] , now go for saving the files - submitDoc(request, group_id) + # this is context node getting from the url get request + context_node_id = request.GET.get('context_node', '') - # After file gets saved , that file's id should be saved in collection_set of context topic node - context_node = node_collection.one({'_id': ObjectId(context_node_id)}) - for k in new_list: - file_obj = node_collection.one({'_type': 'File', 'name': unicode(k) }) + if request.method == "POST": - context_node.collection_set.append(file_obj._id) - context_node.save() + context_name = request.POST.get("context_name", "") + css_node_id = request.POST.get("css_node_id", "") + course_node = request.POST.get("course_node", "") + unit_name = request.POST.get("unit_name_file", "") + app_id = request.POST.get("app_id", "") + app_set_id = request.POST.get("app_set_id", "") - var1 = "/"+group_id+"/topic_details/"+context_node_id+"" + if context_name is "Topic": + url_name = "/" + group_id + "/topic_details/" + context_node_id + "" + else: + # i.e if context_name is "Course" + url_name = "/" + group_id + "/course/add_units/?css_node_id=" + \ + css_node_id + "&unit_node_id=" + context_node_id + "&course_node="+ course_node + if app_id and app_set_id: + url_name += "&app_id=" + app_id + "&app_set_id=" + app_set_id + "" + if context_node_id: + # set the unit node name + node_collection.collection.update({'_id': ObjectId(context_node_id)}, {'$set': {'name': unit_name }}, upsert=False, multi=False) + + new_list = [] + # For checking the node is already available in gridfs or not + for index, each in enumerate(request.FILES.getlist("doc[]", "")): + fileobj = node_collection.collection.File() + filemd5 = hashlib.md5(each.read()).hexdigest() + if not fileobj.fs.files.exists({"md5": filemd5}): + # If not available append to the list for making the collection for topic below + new_list.append(each) + else: + # If availbale ,then return to the topic page + return HttpResponseRedirect(url_name) + # After taking new_lst[] , now go for saving the files + submitDoc(request, group_id) - return HttpResponseRedirect(var1) + # After file gets saved , that file's id should be saved in collection_set of context topic node + try: + context_node = node_collection.one({'_id': ObjectId(context_node_id)}) + except: + context_node = None + # If unit node is not found, create CourseUnit GS + if context_name == "Course": + cu_gst = node_collection.one({'_type': "GSystemType", 'name': "CourseUnit"}) + cu_new = node_collection.collection.GSystem() + cu_new.member_of.append(cu_gst._id) + cu_new.name = unit_name.strip() + cu_new.modified_by = int(request.user.id) + cu_new.created_by = int(request.user.id) + cu_new.contributors.append(int(request.user.id)) + css_node = node_collection.one({'_id': ObjectId(css_node_id)}) + cu_new.prior_node.append(css_node._id) + cu_new.save() + node_collection.collection.update({'_id': css_node._id}, {'$push': {'collection_set': cu_new._id }}, upsert=False, multi=False) + # context_node = node_collection.one({'_id': cu_new._id}) + context_node = cu_new + context_node_id = str(cu_new._id) + url_name = "/" + group_id + "/course/add_units/?css_node_id=" + \ + css_node_id + "&unit_node_id=" + context_node_id + "&course_node="+ course_node + if app_id and app_set_id: + url_name += "&app_id=" + app_id + "&app_set_id=" + app_set_id + "" + + for k in new_list: + try: + file_obj = node_collection.one({'_type': 'File', 'name': unicode(k)}) + except: + return HttpResponseRedirect(url_name) + file_obj.prior_node.append(context_node._id) + file_obj.status = u"PUBLISHED" + file_obj.save() + context_node.collection_set.append(file_obj._id) + file_obj.save() + context_node.save() + return HttpResponseRedirect(url_name) diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/course.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/course.py index 9988f92..5af1c3e 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/views/course.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/course.py @@ -28,7 +28,7 @@ from gnowsys_ndf.ndf.models import Node, AttributeType, RelationType from gnowsys_ndf.ndf.models import node_collection, triple_collection from gnowsys_ndf.ndf.views.file import save_file from gnowsys_ndf.ndf.templatetags.ndf_tags import edit_drawer_widget -from gnowsys_ndf.ndf.views.methods import get_node_common_fields, parse_template_data,get_execution_time +from gnowsys_ndf.ndf.views.methods import get_node_common_fields, parse_template_data, get_execution_time, delete_node from gnowsys_ndf.ndf.views.notify import set_notif_val from gnowsys_ndf.ndf.views.methods import get_property_order_with_value from gnowsys_ndf.ndf.views.methods import create_gattribute, create_grelation, create_task @@ -119,7 +119,6 @@ def course(request, group_id, course_id=None): variable = RequestContext(request, {'title': title, 'course_nodes_count': course_coll.count(), 'course_coll': course_coll, 'groupid':group_id, 'appId':app._id, 'group_id':group_id}) return render_to_response(template, variable) - @login_required @get_execution_time def create_edit(request, group_id, node_id=None): @@ -854,7 +853,7 @@ def create_course_struct(request, group_id, node_id): app_id = request.GET.get("app_id", "") app_set_id = request.GET.get("app_set_id", "") return render_to_response("ndf/create_course_structure.html", - { 'cnode': course_node, + {'cnode': course_node, 'groupid': group_id, 'group_id': group_id, 'title': title, @@ -902,6 +901,7 @@ def save_course_section(request, group_id): return HttpResponse(json.dumps(response_dict)) +@login_required def save_course_sub_section(request, group_id): ''' Accepts: @@ -941,6 +941,7 @@ def save_course_sub_section(request, group_id): return HttpResponse(json.dumps(response_dict)) +@login_required def change_node_name(request, group_id): ''' Accepts: @@ -962,6 +963,7 @@ def change_node_name(request, group_id): return HttpResponse(json.dumps(response_dict)) +@login_required def change_order(request, group_id): ''' Accepts: @@ -992,6 +994,7 @@ def change_order(request, group_id): return HttpResponse(json.dumps(response_dict)) +@login_required def course_sub_section_prop(request, group_id): ''' Accepts: @@ -1057,6 +1060,8 @@ def course_sub_section_prop(request, group_id): return HttpResponse(json.dumps(response_dict)) + +@login_required def add_units(request,group_id): ''' Accepts: @@ -1084,8 +1089,8 @@ def add_units(request,group_id): 'group_id': group_id, 'groupid': group_id, 'css_node': css_node, 'title': title, - 'app_set_id':app_set_id, - 'app_id':app_id, + 'app_set_id': app_set_id, + 'app_id': app_id, 'unit_node': unit_node, 'course_node': course_node }) @@ -1094,7 +1099,7 @@ def add_units(request,group_id): return render_to_response(template, variable) - +@login_required def get_resources(request, group_id): ''' Accepts: @@ -1159,7 +1164,7 @@ def get_resources(request, group_id): return HttpResponse(json.dumps(response_dict)) - +@login_required def save_resources(request, group_id): ''' Accepts: @@ -1207,3 +1212,40 @@ def save_resources(request, group_id): response_dict["success"] = True response_dict["cu_new_id"] = str(cu_new._id) return HttpResponse(json.dumps(response_dict)) + + +@login_required +def delete_from_course_structure(request, group_id): + ''' + Accepts: + * ObjectId of node that is to be deleted. + It can be CourseSection/CourseSubSection/CourseUnit + + Actions: + * Deletes the received node + + Returns: + * success (i.e True/False) + ''' + response_dict = {"success": False} + del_stat = False + if request.is_ajax() and request.method == "POST": + oid = request.POST.get("oid", '') + del_stat = delete_item(oid) + if del_stat: + response_dict["success"] = True + return HttpResponse(json.dumps(response_dict)) + + +def delete_item(item): + node_item = node_collection.one({'_id': ObjectId(item)}) + + if u"CourseUnit" not in node_item.member_of_names_list and node_item.collection_set: + for each in node_item.collection_set: + d_st = delete_item(each) + + del_status, del_status_msg = delete_node( + node_id=node_item._id, + deletion_type=0 + ) + return del_status diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/file.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/file.py index 7a499ed..f17c364 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/views/file.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/file.py @@ -766,128 +766,123 @@ def save_file(files,title, userid, group_id, content_org, tags, img_type = None, filemd5 = hashlib.md5(files.read()).hexdigest() files.seek(0) size, unit = getFileSize(files) - size = {'size':round(size, 2), 'unit':unicode(unit)} - - if fileobj.fs.files.exists({"md5":filemd5}): + size = {'size': round(size, 2), 'unit': unicode(unit)} + + if fileobj.fs.files.exists({"md5": filemd5}): # gridfs_collection = get_database()['fs.files'] - cur_oid = gridfs_collection.find_one({"md5":filemd5}, {'docid':1, '_id':0}) - # coll_new = get_database()['Nodes'] - new_name = node_collection.find_one({'_id':ObjectId(str(cur_oid["docid"]))}) + cur_oid = gridfs_collection.find_one({"md5": filemd5}, {'docid': 1, '_id': 0}) + + # coll_new = get_database()['Nodes'] + new_name = node_collection.find_one({'_id': ObjectId(str(cur_oid["docid"]))}) # if calling function is passing oid=True as last parameter then reply with id and name. if "oid" in kwargs: - if kwargs["oid"]: - # gridfs_collection = get_database()['fs.files'] - cur_oid = gridfs_collection.find_one({"md5":filemd5}, {'docid':1, '_id':0}) - # returning only ObjectId (of GSystem containing file info) in dict format. - # e.g : {u'docid': ObjectId('539a999275daa21eb7c048af')} - return cur_oid["docid"], 'True' + if kwargs["oid"]: + # gridfs_collection = get_database()['fs.files'] + cur_oid = gridfs_collection.find_one({"md5": filemd5}, {'docid': 1, '_id': 0}) + # returning only ObjectId (of GSystem containing file info) in dict format. + # e.g : {u'docid': ObjectId('539a999275daa21eb7c048af')} + return cur_oid["docid"], 'True' else: - return [files.name, new_name.name],'True' + return [files.name, new_name.name], 'True' else: try: files.seek(0) - filetype = magic.from_buffer(files.read(100000), mime = 'true') #Gusing filetype by python-magic + filetype = magic.from_buffer(files.read(100000), mime='true') # Gusing filetype by python-magic filetype1 = mimetypes.guess_type(files.name)[0] if filetype1: filetype1 = filetype1 - else : + else: filetype1 = "" filename = files.name fileobj.name = unicode(title) if language: - fileobj.language= unicode(language) + fileobj.language = unicode(language) fileobj.created_by = int(userid) fileobj.modified_by = int(userid) if int(userid) not in fileobj.contributors: fileobj.contributors.append(int(userid)) - if access_policy: - fileobj.access_policy = unicode(access_policy) # For giving privacy to file objects - + fileobj.access_policy = unicode(access_policy) # For giving privacy to file objects fileobj.file_size = size - group_object = node_collection.one({'_id':ObjectId(group_id)}) - + + group_object = node_collection.one({'_id': ObjectId(group_id)}) + if group_object._id not in fileobj.group_set: - fileobj.group_set.append(group_object._id) #group id stored in group_set field + fileobj.group_set.append(group_object._id) # group id stored in group_set field if usrname: - user_group_object=node_collection.one({'$and':[{'_type':u'Author'},{'name':usrname}]}) + user_group_object = node_collection.one({'$and': [{'_type': u'Author'},{'name': usrname}]}) if user_group_object: - if user_group_object._id not in fileobj.group_set: # File creator_group_id stored in group_set field + if user_group_object._id not in fileobj.group_set: # File creator_group_id stored in group_set field fileobj.group_set.append(user_group_object._id) fileobj.member_of.append(GST_FILE._id) - #### ADDED ON 14th July.IT's DONE + # ADDED ON 14th July.IT's DONE fileobj.url = set_all_urls(fileobj.member_of) fileobj.mime_type = filetype - if img_type == "" or img_type == None: + if img_type == "" or img_type is None: if content_org: fileobj.content_org = unicode(content_org) # Required to link temporary files with the current user who is modifying this document filename_content = slugify(title) + "-" + usrname + "-" - fileobj.content = org2html(content_org, file_prefix = filename_content) + fileobj.content = org2html(content_org, file_prefix=filename_content) if not type(tags) is list: tags = [unicode(t.strip()) for t in tags.split(",") if t != ""] fileobj.tags = tags - fileobj.save() + files.seek(0) #moving files cursor to start objectid = fileobj.fs.files.put(files.read(), filename=filename, content_type=filetype) #store files into gridfs - node_collection.find_and_modify({'_id':fileobj._id},{'$push':{'fs_file_ids':objectid}}) - + node_collection.find_and_modify({'_id': fileobj._id}, {'$push': {'fs_file_ids': objectid}}) + # For making collection if uploaded file more than one if count == 0: first_object = fileobj else: - node_collection.find_and_modify({'_id':first_object._id},{'$push':{'collection_set':fileobj._id}}) - - - """ + node_collection.find_and_modify({'_id': first_object._id}, {'$push': {'collection_set': fileobj._id}}) + + """ code for converting video into webm and converted video assigning to varible files """ - if 'video' in filetype or 'video' in filetype1 or filename.endswith('.webm') == True: + if 'video' in filetype or 'video' in filetype1 or filename.endswith('.webm') is True: is_video = 'True' - node_collection.find_and_modify({'_id':fileobj._id},{'$push':{'member_of':GST_VIDEO._id}}) - node_collection.find_and_modify({'_id':fileobj._id},{'$set':{'mime_type':'video'}}) - # webmfiles, filetype, thumbnailvideo = convertVideo(files, userid, fileobj._id, filename) - + node_collection.find_and_modify({'_id': fileobj._id}, {'$push': {'member_of': GST_VIDEO._id}}) + node_collection.find_and_modify({'_id': fileobj._id}, {'$set': {'mime_type': 'video'}}) + # webmfiles, filetype, thumbnailvideo = convertVideo(files, userid, fileobj._id, filename) + # '''storing thumbnail of video with duration in saved object''' # tobjectid = fileobj.fs.files.put(thumbnailvideo.read(), filename=filename+"-thumbnail", content_type="thumbnail-image") - # node_collection.find_and_modify({'_id':fileobj._id},{'$push':{'fs_file_ids':tobjectid}}) - - # if filename.endswith('.webm') == False: + # if filename.endswith('.webm') == False: # tobjectid = fileobj.fs.files.put(webmfiles.read(), filename=filename+".webm", content_type=filetype) # # saving webm video id into file object # node_collection.find_and_modify({'_id':fileobj._id},{'$push':{'fs_file_ids':tobjectid}}) - + '''creating thread for converting vedio file into webm''' t = threading.Thread(target=convertVideo, args=(files, userid, fileobj, filename, )) t.start() - - '''storing thumbnail of pdf and svg files in saved object''' + + '''storing thumbnail of pdf and svg files in saved object''' # if 'pdf' in filetype or 'svg' in filetype: # thumbnail_pdf = convert_pdf_thumbnail(files,fileobj._id) # tobjectid = fileobj.fs.files.put(thumbnail_pdf.read(), filename=filename+"-thumbnail", content_type=filetype) # node_collection.find_and_modify({'_id':fileobj._id},{'$push':{'fs_file_ids':tobjectid}}) - - '''storing thumbnail of image in saved object''' if 'image' in filetype: - node_collection.find_and_modify({'_id':fileobj._id},{'$push':{'member_of':GST_IMAGE._id}}) + node_collection.find_and_modify({'_id': fileobj._id}, {'$push': {'member_of': GST_IMAGE._id}}) thumbnailimg = convert_image_thumbnail(files) tobjectid = fileobj.fs.files.put(thumbnailimg, filename=filename+"-thumbnail", content_type=filetype) - node_collection.find_and_modify({'_id':fileobj._id},{'$push':{'fs_file_ids':tobjectid}}) - + node_collection.find_and_modify({'_id': fileobj._id}, {'$push': {'fs_file_ids': tobjectid}}) + files.seek(0) mid_size_img = convert_mid_size_image(files) - if mid_size_img: + if mid_size_img: mid_img_id = fileobj.fs.files.put(mid_size_img, filename=filename+"-mid_size_img", content_type=filetype) - node_collection.find_and_modify({'_id':fileobj._id},{'$push':{'fs_file_ids':mid_img_id}}) + node_collection.find_and_modify({'_id': fileobj._id}, {'$push': {'fs_file_ids':mid_img_id}}) count = count + 1 return fileobj._id, is_video except Exception as e: |