diff options
author | katkamrachana <katkam.rachana@gmail.com> | 2015-07-08 20:23:41 +0530 |
---|---|---|
committer | katkamrachana <katkam.rachana@gmail.com> | 2015-07-08 20:23:41 +0530 |
commit | cb288c924e1ba32a533ee5cf8271a156fa5494d9 (patch) | |
tree | aa4bc969ce297dbcb5f76816ae889fcd0224070a /gnowsys-ndf/gnowsys_ndf | |
parent | 894aa88195a7087792940d1e2f0541877d047737 (diff) | |
parent | b48299fc356219b5c69540e81f4101eee35c5e58 (diff) | |
download | gnowsys-cb288c924e1ba32a533ee5cf8271a156fa5494d9.tar.gz |
Merge branch 'mongokit' of https://github.com/gnowledge/gstudio into mongokit
Diffstat (limited to 'gnowsys-ndf/gnowsys_ndf')
35 files changed, 2412 insertions, 861 deletions
diff --git a/gnowsys-ndf/gnowsys_ndf/benchmarker/benchmarkreport.py b/gnowsys-ndf/gnowsys_ndf/benchmarker/benchmarkreport.py index 9fa9c01..d25eebe 100644 --- a/gnowsys-ndf/gnowsys_ndf/benchmarker/benchmarkreport.py +++ b/gnowsys-ndf/gnowsys_ndf/benchmarker/benchmarkreport.py @@ -10,13 +10,13 @@ import json ''' db = get_database() col = db[Benchmark.collection_name] - + def report(request): date1=datetime.date.today() ti=time(0,0) listofmethods = [] Today=datetime.datetime.combine(date1,ti) - bench_cur = col.find({'last_update':{'$gte':Today}}).sort('last_update', -1).sort('time_taken',-1) + bench_cur = col.find({'last_update':{'$gte':Today}}).sort('last_update', -1) search_cur = [] if request.method == "POST": diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/management/commands/shift_Triples.py b/gnowsys-ndf/gnowsys_ndf/ndf/management/commands/shift_Triples.py index f763bd2..e8aba88 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/management/commands/shift_Triples.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/management/commands/shift_Triples.py @@ -35,7 +35,7 @@ class Command(BaseCommand): try: triple_collection_name = Triple.collection_name node_collection_name = Node.collection_name - + if triple_collection_name not in db.collection_names(): try: # [A] Create Triples collection diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/models.py b/gnowsys-ndf/gnowsys_ndf/ndf/models.py index 37b8894..10fd215 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/models.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/models.py @@ -235,9 +235,8 @@ class Node(DjangoDocument): # ready. default_values = {'created_at': datetime.datetime.utcnow, 'status': u'DRAFT'} use_dot_notation = True - + ########## Setter(@x.setter) & Getter(@property) ########## - @property def user_details_dict(self): """Retrieves names of created-by & modified-by users from the given @@ -1560,7 +1559,7 @@ class Triple(DjangoDocument): 'lang': basestring, # Put validation for standard language codes 'status': STATUS_CHOICES_TU } - + required_fields = ['name', 'subject'] use_dot_notation = True use_autorefs = True diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/Upload_File.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/Upload_File.html new file mode 100644 index 0000000..157f575 --- /dev/null +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/Upload_File.html @@ -0,0 +1,426 @@ +{% load i18n %} +{% load ndf_tags %} + +<style type="text/css"> + + + #tags_error{ + color: red; + } + + div.tags{ + /*padding: 5px 10px; */ + margin: 2px 5px; + /*color: white;*/ + font-size: 1em; + border: solid thin #FFD400; + } + + i.remove-tag{ + padding-left: 8px; + font-size: 1.1em; + cursor: pointer; + } + +</style> + +{% get_group_name groupid as group_name_tag %} +{% if user.is_authenticated %} + + <form class="dropzone" id ="docPost" enctype="multipart/form-data" method="post" action="{% url 'submitDoc' group_name_tag %}">{% csrf_token %} + + <!-- file browse and name --> + <fieldset style="background:#ccc;"> + <legend style="background:#10c1cb">{% trans "Upload File" %}</legend> + <div class ="row"> + <div class="large-3 columns"> + <label>{% trans "Choose File" %}</label> + <input type="file" name="doc[]" id="docFile"/> + </div> + <div class="large-9 columns"> + <label>{% trans "Title of File" %}</label> + <input type="text" name="docTitle" id ="docTitle" placeholder="Enter Title of File"> + </div> + </div> + </fieldset> + + <!-- other details --> + <fieldset style="background:#ccc;"> + <legend style="background:#10c1cb">{% trans "Enter Details" %}</legend> + + <div class ="row"> + <div class="large-5 columns"> + <b>Add Description</b> + {% include "ndf/add_editor.html" with var_name="content_org" var_placeholder="Please enter question" %} + + <div class="row"> + + <b class="small-3 columns"> {% trans "Add Tag" %}: + </b> + + <div class="small-9 columns"> + <div class="row collapse" data-tooltip class="has-tip" title="{% trans 'Tags help identify similiar work easily. Just add tag text and click Add Tag button' %}"> + + <div class="small-9 columns"> + <input id="tags_id" tabindex="2" type="text" value="" placeholder="{% trans 'Add tag text and click on [Add Tag] button' %}"> + <input type="hidden" value="{{node.tags|join:', '|default_if_none:""}}" name="tags"> + </div> + <div class="small-3 columns"> + <span tabindex="3" id="add-tag-btn" class="tiny button"> + {% trans 'Add Tag' %} + </span> + </div> + + </div> + + <!-- show tags error msg --> + <div class="row hide" id="tags_error"> + <div class="small-10 columns">{% trans 'Non empty tags can have only alphanumeric characters, dash(-) and spaces.' %}</div> + </div> + + <!-- show added tags --> + <div class="row"> + <div id="added_tags" class="small-9 columns"> + {% for each_tag in node.tags %} + <div class="tags label radius info">{{each_tag}}<i title="Remove this tag" class="fi-x-circle remove-tag"></i></div> + {% endfor %} + </div> + </div> + + </div> + + </div> + + </div> + + <div class="large-7 columns"> + <div class ="row"> + <div class="large-4 columns"> + <b>Set Language</b> + <select name="lan"> + {% get_language_info_list for LANGUAGES as languages %} + {% for language in languages %} + <option value="{{ language.code }}"> + {{ language.name }} + </option> + {% endfor %} + </select> + </div> + <div class="large-4 columns"> + <b>Location</b> + <a href="#view-map-edit-widget" data-reveal-id="view-map-edit-widget" title="Click to add location markers" class="tiny secondary button expand"> <i class="fi-marker"></i> {% trans "Add Location" %} + </a> + </div> + <div class="large-4 columns"> + <b>Set Privacy</b><br/> + <input id="PUBLIC" name="login-mode" value="PUBLIC" type="radio" checked> + <label for="PUBLIC" onclick="">{% trans "Public" %} <i class="fi-torsos-all"></i></label> + <input id="PRIVATE" name="login-mode" value="PRIVATE" type="radio"> + <label for="PRIVATE" onclick="">{% trans "Private" %} <i class="fi-lock"></i></label> + </div> + </div> + + <div class ="row"> + <div class="large-4 columns"> + <b>Target Audience</b> + {% get_metadata_values as metadata %} + {% for k,v in metadata.items %} + {% if k == "audience" %} + <select name="audience"> + <option>---Select from list---</option> + {% for opts in v %} + <option>{% trans opts %}</option> + {% endfor %} + </select> + {% endif %} + {% endfor %} + </div> + + {% comment %} + <!-- <div class="large-4 columns"> + <b>File Type</b> + {% get_metadata_values as metadata %} + {% for k,v in metadata.items %} + {% if k == "educationaluse" %} + <select name="FileType"> + <option>---Select from list---</option> + {% for opts in v %} + <option>{% trans opts %}</option> + {% endfor %} + </select> + {% endif %} + {% endfor %} + </div> --> + {% endcomment %} + + <div class="large-4 columns"> + <b>Subject</b> + {% get_metadata_values as metadata %} + {% for k,v in metadata.items %} + {% if k == "educationalsubject" %} + <select name="Subject"> + <option>---Select from list---</option> + {% for opts in v %} + <option>{% trans opts %}</option> + {% endfor %} + </select> + {% endif %} + {% endfor %} + </div> + + <div class="large-4 columns"> + <b>Educational Level</b> + {% get_metadata_values as metadata %} + {% for k,v in metadata.items %} + {% if k == "educationallevel" %} + <select name="Level"> + <option>---Select from list---</option> + {% for opts in v %} + <option>{% trans opts %}</option> + {% endfor %} + </select> + {% endif %} + {% endfor %} + </div> + </div> + + <div class ="row"> + <div class="large-2 columns"> + <b>License</b> + </div> + <div class="large-10 columns"> + <!-- <input id="license_id" name="License" type="text" placeholder="Enter source name"/> --> + {% get_licence as licence %} + <select name="License"> + <option value="CC BY-SA">---Select from list---</option> + {% for each_licence in licence %} + <option value="{{each_licence}}"> + {% trans each_licence %} + </option> + {% endfor %} + </select> + </div> + </div> + + <div class ="row"> + <div class="large-2 columns"> + <b>Source</b> + </div> + <div class="large-10 columns"> + <input id="source_id" name="Source" type="text" placeholder="Enter source name"/> + </div> + </div> + + <div class ="row"> + <div class="large-3 columns"> + <b>Based on url</b> + </div> + <div class="large-9 columns"> + <input id="based_on_id" name="based_url" type="text" placeholder="Enter valid url"/> + </div> + </div> + + </div> + + + </fieldset> + + <input type="hidden" name="user" value="{{user.id}}"> + <input type="hidden" name="page_url" value="{{page_url}}"> + <input type="submit" id="submitpostid" value="Submit" class="button round medium"> + <p id="message" style="display:none"> + {% trans "Depending on the size of file/s and your Internet speed, upload process may take time. Please do not close this window." %} <br/> + {% trans "Please upload videos in webm format. If you upload videos of other formats, it will take longer to publish them." %} + </p> + + + <!-- Overlay : Map Widget --> + <div class="content reveal-modal graph-div" id="view-map-edit-widget" data-reveal> + <!-- #{#% #if '/edit/' in request.path or '/image_detail/' in request.path or '/video_detail/' in request.path%} --> + <a class="close-reveal-modal" >×</a> + {% include "ndf/map_widget.html" with mode="edit" %} + <!-- <div style="background-color:gray; width:100%; height:80%;"></div> --> + <!-- #{#%# endif %} --> + </div> + + </form> + +{% else %} + <p><em>{% trans "You are not an authorised user. Please login to upload files." %} </em></p> +{% endif %} + +<script type="text/javascript"> + + $("#docFile").change(function() { + var max_size =100000 + var fsize=this.files[0].size + fsize=fsize/1024 + {% check_is_gstaff groupid request.user as gstaff_access %} + if(fsize> max_size){ + {% if gstaff_access%} + $('#docFile').val(this.value); + {% else %} + alert("Sorry. Max File Size Limit Exceeded"); + $(this).val("") + $('#docFile').val(this.value); + {% endif %} + } + else{ + $('#docFile').val(this.value);} + }); + + $(document).on('submit',"form",function(){ + if($("#docFile").val() != "") + { + + $("#message").show(); + $("#submitpostid").hide(); + $("#submitpostid").submit(); + + } + else + { + alert("select a file"); + return false; + } + }); + + // --- tags --- + var tags = document.getElementById("tags_id"); + var addedTags = document.getElementById("added_tags"); + + function checkTag() + { + var textValue = tags.value.trim(); + // console.log(textValue.length); + + if(textValue.length < 1){ return false; } + + if(textValue.match(/[^A-Za-z0-9\-\ ]/g)) + { // having special characters + $('#tags_error').removeClass("hide"); + return false; + } + else + { // passed the test and now add tag label + $('#tags_error').addClass("hide") // fadeout fastly ongoing fadeout event + return true; + } + } + + tags.onchange = checkTag; + tags.onmouseup = checkTag; + tags.onkeyup = checkTag; + + function updateAllTags() { + + var tagsArr = new Array(); + + $("#added_tags").children("div.tags.label").each(function(){ + tagsArr.push(this.textContent.trim().toLowerCase()); + }); + + $("input:hidden[name='tags']").val(tagsArr.toString()); + // console.log(tagsArr) + } + + + function removeTag(){ + $(this).parent().fadeOut("slow", function(){ + $(this).detach(); + }); + + updateAllTags(); + }; + + $(".remove-tag").click(removeTag); + + $(".remove-tag").mouseenter(function(){ + $(this).parent("div.tags").css("text-decoration", "line-through"); + }); + + $(".remove-tag").mouseleave(function(){ + $(this).parent("div.tags").css("text-decoration", "none"); + }); + + function addTag() { + if(checkTag()) + { + var textValue = tags.value.trim().toLowerCase(); + tags.value = ''; + + var tagDiv = document.createElement("div"); + tagDiv.className = "tags label radius info"; + tagDiv.appendChild(document.createTextNode(textValue)); + // tagDiv.setAttribute("data-primary-type", selFieldPrimaryType); + + var closeBtn = document.createElement("i"); + closeBtn.className = "fi-x-circle remove-tag"; + closeBtn.title = "Remove this tag"; + closeBtn.onclick = removeTag; + + $(closeBtn).mouseenter(function(){ + $(this).parent("div.tags").css("text-decoration", "line-through"); + }); + + $(closeBtn).mouseleave(function(){ + $(this).parent("div.tags").css("text-decoration", "none"); + }); + + tagDiv.appendChild(closeBtn); + + addedTags.appendChild(tagDiv); + + updateAllTags(); + } + else + { + $('#tags_error').removeClass("hide"); + } + tags.focus(); + } + + var addTagBtn = document.getElementById("add-tag-btn"); + addTagBtn.onclick = addTag; + addTagBtn.onkeypress = addTag; + + + // --- map --- + $(document).on('open', '#view-map-edit-widget[data-reveal]', function () { + + $.ajax({ + url: "{% url 'get_visited_location' groupid %}", + success: function(data){ + + data = JSON.parse(data); + + var lastVisitedLocationVal = data; + + if(lastVisitedLocationVal){ + + if(lastVisitedLocationVal == "[]"){ + lastVisitedLocationVal = JSON.parse(lastVisitedLocationVal); + } + + if(lastVisitedLocationVal.length > 0){ + // lastVisitedLocationVal = JSON.parse(lastVisitedLocationVal); + var zoom = lastVisitedLocationVal.pop(), + lng = lastVisitedLocationVal[1], + lat = lastVisitedLocationVal[0]; + map.setView([lat, lng], zoom); + } + } + else if( tempArr.length ) + { + var group = new L.featureGroup(tempArr) + map.fitBounds(group.getBounds()); + } + } + }); + }); + + $(document).on('opened', '#view-map-edit-widget[data-reveal]', function () { + map.invalidateSize(); + }); + +</script>
\ No newline at end of file diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/Uploader_Form.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/Uploader_Form.html new file mode 100644 index 0000000..423a650 --- /dev/null +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/Uploader_Form.html @@ -0,0 +1,25 @@ +{% extends "ndf/base.html" %} +{% load i18n %} + +{% block title %} Upload Resource {% endblock %} + + +{% block meta_content %} + <!-- This content displayed into the left panel to display the info/hrlp document --> + <h3>{% trans "Uploader Form" %}</h3> + <p class="text-justify subheader"> + {% trans "You can upload <b>files</b> of any format to your group library." %} + </p> + +{% endblock %} + + +{% block body_content %} + + {% include "ndf/Upload_File.html" %} + +{% endblock %} + + + + diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course.html index 6573df0..bed3a68 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course.html +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course.html @@ -12,16 +12,27 @@ {% block meta_content %} - <h2 class="subheader">{% trans "Courses" %}</h2> - {% if user.is_authenticated %} - {% user_access_policy groupid request.user as user_access %} - {% if user_access == "allow" %} - <a class="small button" href="{% url 'create_edit' group_name_tag %}"> - <span class="fi-plus"> {% trans "New" %} {{title}} </span> - </a> - <a class="small publish-btn button" style="width:73%" href="{% url 'ann_course_create_edit' group_id app_id app_set_id %}">{% trans "Announce" %}</a> - {% endif %} + + <a href="{% url course_gst.name|lower group_name_tag %}"> + <h2 class="subheader"> + {% if course_gst.altnames and course_gst.altnames != "None" %} + {{course_gst.altnames}} + {% else %} + {{course_gst.name}} + {% endif%} + </h2> + {{course_gst.content|default_if_none:""|safe}} + </a> + + {% if user.is_authenticated %} + {% user_access_policy groupid request.user as user_access %} + {% if user_access == "allow" %} + <a class="small button" href="{% url 'create_edit' group_name_tag %}"> + <span class="fi-plus"> {% trans "New" %} {{title}} </span> + </a> + <a class="small publish-btn button" style="width:73%" href="{% url 'ann_course_create_edit' group_id app_id app_set_id %}">{% trans "Announce" %}</a> {% endif %} + {% endif %} {% endblock %} diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/ebook.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/ebook.html index b1a184f..4b969ba 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/ebook.html +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/ebook.html @@ -4,6 +4,21 @@ {% block title %} Repository {% endblock %} + +{% block meta_content %} + <a href="{% url 'e-book' group_name_tag %}" title="Click to go to ebooks"> + <h2 class="subheader"> + {% if ebook_gst.altnames and ebook_gst.altnames != "None" %} + {{ebook_gst.altnames}} + {% else %} + {{ebook_gst.name}} + {% endif%} + </h2> + </a> + {{ebook_gst.content|default_if_none:""|safe}} +{% endblock %} + + {% block body_content %} <ul class="small-block-grid-1 medium-block-grid-2 large-block-grid-4"> diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/file.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/file.html index 1eeadbf..3cf5c35 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/file.html +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/file.html @@ -44,7 +44,18 @@ <!-- left top panel --> {% block meta_content %} - <h2 class="subheader">{% trans title %}</h2> + + <a href="{% url app_gst.name|lower group_name_tag %}"> + <h2 class="subheader"> + {% if app_gst.altnames and app_gst.altnames != "None" %} + {{app_gst.altnames}} + {% else %} + {{app_gst.name}} + {% endif%} + </h2> + {{app_gst.content|default_if_none:""|safe}} + </a> + {% endblock %} @@ -53,18 +64,6 @@ <div class="panel" style="background-color:#ddd;"> - <!-- radio buttons for E-Library app: CR and XCR --> - {% comment %} - <!-- - {% if title == "E-Library" %} - <input type="radio" name="crxcr" value="cr" id="cr-rad" title="Curricular"> - <label for="cr-rad" title="Curricular">CR</label> - <input type="radio" name="crxcr" value="xcr" id="xcr-rad" title="Extra Curricular"> - <label for="xcr-rad" title="Extra Curricular">XCR</label> - {% endif %} - --> - {% endcomment %} - <ul class="side-nav"> <dl class="tabs" data-tab > @@ -191,15 +190,9 @@ {% if user_is_joined == "joined" or user_is_joined == "author" %} <b>{% trans "Actions" %}</b><br/><br/> - {% user_access_policy groupid request.user as user_access %} - {% if user_access == "allow" %} - <a href="{% url 'uploadDoc' group_name_tag %}?next={{request.path}}" class="tiny round button"> {% trans "Upload File" %} </a><br/><br/> - - {% endif %} - <b>{% trans "Review" %}</b><br/><br/> diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/group.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/group.html index 25bc57c..0829d8e 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/group.html +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/group.html @@ -6,10 +6,26 @@ {% block title %} Group {% endblock %} -{% block meta_content %} -<h2 class="subheader">{% trans "Groups" %}</h2> -{% endblock %} +<!-- left top panel --> +{% block meta_content %} + + <h2 class="subheader">{% trans "Groups" %}</h2> +<!-- +{% comment %} + <a href="{% url app_gst.name|lower group_name_tag %}"> + <h2 class="subheader"> + {% if app_gst.altnames and app_gst.altnames != "None" %} + {{app_gst.altnames}} + {% else %} + {{app_gst.name}} + {% endif%} + </h2> + {{app_gst.content|safe}} + </a> +{% endcomment %} + --> +{% endblock %} {% block help_content %} {% blocktrans %}<p>Groups are an easy way to share content and conversation, either privately or with the world. Many times, a group already exist for a specific interest or topic. If you can't find one you like, feel free to start your own.</p> diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/hierarchy_tree.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/hierarchy_tree.html new file mode 100644 index 0000000..2864bba --- /dev/null +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/hierarchy_tree.html @@ -0,0 +1,623 @@ +{% load i18n %} + +{% load ndf_tags %} +{% get_group_name groupid as group_name_tag %} + +<style> + + /*#app-set-item li { padding:0.5em }*/ + + .jqtree-closed > .jqtree-element i.icon-folder-open:before { + content: "\f07b"; + } + + .jqtree-tree i { + margin-right: 4px; + } + + ul.jqtree-tree ul.jqtree_common { + margin-left: 36px; + } +</style> + + +<script type="text/javascript"> + + // $(document).ready(function() { + function plotHierarchyTree() { + // Funtion for loading tree for showing collection list left side panel + doc(); + + // Function for manipulating tree when user visits to page directly via browser url + {% if selected %} TreeTillNode(); {% endif %} + } + // }); + + + function TreeTillNode () { + + // This gives the last hierarchy node id from browser url. + var url = "{{selected}}"; + + var tree_build = $(".themes").not(".jqtree-loading"); + var node = tree_build.tree('getNodeById', url); + tree_build.tree('openNode', node); + + // Javascript function to be used for checking objects in specific time of interval + setTimeout(function(){ + + // console.log($(".themes")) + if( ($(".themes").length > 0) ) { TreeTillNode() } + }, 100 ); + } + + + function doc() { + + var $tree = $('.themes'); + var user = "{{user.is_authenticated}}"; + var unfold = "{{unfold}}"; + + if(unfold == "true"){ + unfold = true + } + else{ + unfold = false + } + + $tree.tree({ + autoOpen: unfold, + + onCreateLi: function(node, $li) { + + if (node.node_type == "Topic"){ + $li.find('.jqtree-title').before('  <span class="fi-page"></span> '); + } + else{ + $li.find('.jqtree-title').before('  <span class="fi-folder" style="color:orange"></span> '); + } + + if (node.node_type == "Topic"){ + $li.find('.jqtree-element').append( + + ' <a id='+node.id+' name='+node.name+' class="topic" href="/{{groupid}}/topics/'+node.id+'/"> </a>' + ); + } + else{ + if (user == "True"){ + + $li.find('.jqtree-element').append( + {% user_access_policy groupid request.user as user_access %} + {% if user_access == "allow" %} + + ' <a href="/{{groupid}}/topics/'+node.id+'/"> <i class="fi-pencil edit"></i></a> <a id='+node.id+' class="objectsCheckbox"> <input type="checkbox"> </a>' + + {% endif %} + ); + } + } + } + }); + + // bind 'tree.click' event + $tree.bind( + 'tree.click', + function(event) { + // The clicked node is 'event.node' + var node = event.node; + + var parent_arr = []; + var parent_node = node; + parent_arr.push(node.id); + + // Bellow code manipulates the parent hierarchy of clicked node in a tree + while (parent_node) { + if (parent_node.name !== undefined){ + $tree.tree('openNode', parent_node); + parent_node = parent_node.parent; + if (parent_node.name !== undefined){ + parent_arr.push(parent_node.id); + } + } + else{ + break; + } + } + var nav_list = parent_arr.reverse(); + // alert(nav_list); + + // If its topic node i.e no children of this node then show the detail view for topic + if( node.children[0] == null ){ + + if (node.node_type == "Topic"){ + location.href = "/{{group_name_tag}}/topic_details/"+node.id+"?nav_li="+nav_list+""; + } + + } + + } + ); + + $tree.bind( + 'tree.contextmenu', + function(event) { + // The clicked node is 'event.node' + var node = event.node; + {% user_access_policy groupid request.user as user_access %} + {% if user_access == "allow" %} + var msg = confirm("Do you want to delete this topic ?"); + if (msg == true) { + + $.ajax({ + url: "{% url 'delete_themes' groupid %}", + type: 'POST', + data:{ + deleteobj: node.id, + csrfmiddlewaretoken: '{{ csrf_token }}' + }, + success: function(result){ + alert("Topic "+node.name+" deleted successfully"); + location.reload(true); + }, + + }); + + } + {% endif %} + + } + ); + + + }; + + + // method to handle hover on topics + function showTopicStats(){ + // Javascript function to be used for checking objects in specific time of interval + setTimeout(function(){ + // On hover of topic node manipulate resources only once + + $(".jqtree-title.jqtree_common").hover( function(){ + + topic_id = $(this).siblings("a").attr("id"); + // var topic_name = $(this).siblings("a").attr("name"); + var data_info = $(this).attr("data-info"); + var hover_context = this; + if ( ! data_info && topic_id ){ + $(".topic_stats").css("display", "none"); + + $.ajax({ + url: "{% url 'get_topic_contents' groupid %}", + type: 'POST', + data:{ + node_id: topic_id, + csrfmiddlewaretoken: '{{ csrf_token }}' + }, + success: function(data){ + + count = display_top_res(data) + + if (data != "{}"){ + + $(".topic_stats").html(count); + $(hover_context).attr("data-info", data) + + $(".topic_stats").css("display", "block"); + + } + else{ + $(hover_context).attr("data-info", data); + } + + }, + + }); + + + } + else{ + + if (topic_id){ + var data = $(this).attr("data-info"); + count = display_top_res(data) + $(".topic_stats").html(count); + $(".topic_stats").css("display", "block"); + } + + } + }); + + // console.log($(".jqtree-element.jqtree_common")) + if( ($(".jqtree-title.jqtree_common").length <= 0) ) { + showTopicStats() + } + + }, 1000 ); + } + + + function display_top_res(data){ + data_obj = JSON.parse(data); + count = "" + + if (data != "{}"){ + var k = Object.keys(data_obj); // To get the keys from incomming data + + for (var m = 0; m < k.length; m++) { + var key = k[m]; + var len = data_obj[key].length; // length of list as a value of key + // alert(key+": "+len); + count += key+": "+len+"<br/>"; + } + + } + else{ + count += "No Resources !<br/>"; + } + + return count + + } + + showTopicStats(); + + $("document").on("hover", ".jqtree-title.jqtree_common", function(){ + setTimeout(function(){ + }, 1000); + + alert($(this).siblings("a").attr("id")); + }); + + $("#add_theme_item").click(function() { + $.ajax({ + type: "POST", + url: "{% url 'add_theme_item' groupid %}", + datatype: "html", + data:{ + context_theme: "{{node.pk}}", + name: $(".name_id").val(), + csrfmiddlewaretoken: '{{ csrf_token }}' + }, + success: function(data) { + + var item = $(".name_id").val(); + + if ($.trim(data) === "failure") { + alert("Theme item "+ item +" already available, Please choose different name"); + } + + if ($.trim(data) === "success") { + location.reload(true); + } + + $(".name_id").val(""); + } + }); + + }); + + // script for fold themes_cards hierarchy + $(".fold").click(function() { + $(function() { + location.href = "{% url 'theme_page' group_name_tag app_id %}"; + }); + }); + + // script for unfold themes hierarchy + $(".unfold").click(function() { + $(function() { + location.href = "{% url 'theme_page' group_name_tag app_id %}?unfold=true"; + }); + }); + + $(".tree_browser").click(function() { + $(function() { + location.href = "{% url 'theme_page' group_name_tag app_id %}"; + }); + }); + + // script for delete themes + $(document).on('click',".button.deleteObjects",function(){ + var selectedobject = $(".objectsCheckbox input:checked") + + if(selectedobject.length > 0) + { + $('#myModal').foundation('reveal', 'open'); + + var i = 0; + var str = ""; + $.map(selectedobject,function(each){ + if(i == 0) + { + str = str.concat(each.parentElement.id) + } + else + { + str = str.concat(","+each.parentElement.id) + } + + i= i+1 + }) + + $.ajax({ + url: "{% url 'delete_themes' groupid %}", + type: 'POST', + data:{ + context_theme: "{{node.pk}}", + deleteobjects: str, + csrfmiddlewaretoken: '{{ csrf_token }}' + }, + success: function(result){ + + $("#deletion_results").html(""); + for(var obj in result) + { + var li = $("<ul><li><b>"+result[obj].title+"</b></li></ul>").appendTo($("#deletion_results")); + } + + }, + }); + + } + else + { + alert("select object to delete") + } + + }); + + // Script for delete themes after confirm delete. + $(document).on('click',".button.confirmDeleteObjects",function(){ + var selectedobject = $(".objectsCheckbox input:checked") + + if(selectedobject.length > 0) + { + var i = 0; + var str = ""; + + $.map(selectedobject,function(each){ + if(i == 0) + { + str = str.concat(each.parentElement.id) + } + else + { + str = str.concat(","+each.parentElement.id) + } + + i= i+1 + }); + + $.ajax({ + url: "{% url 'delete_themes' groupid %}", + type: 'POST', + data:{ + context_theme: "{{node.pk}}", + deleteobjects: str, + confirm:"yes", + csrfmiddlewaretoken: '{{ csrf_token }}' + }, + success: function(result){ + alert("Themes deleted successfully"); + $('#myModal').foundation('reveal', 'close'); + location.reload(true); + }, + + }); + + } + else{ + alert("select object to delete") + } + + }); + + // Script for selecting all objects + $(document).on('click',".checkedAll",function(){ + if($(this).is(":checked")==true) + { + $('.objectsCheckbox input').prop( "checked", true ); + } + else + { + $('.objectsCheckbox input').prop( "checked", false ); + } + }); + + // Script for cancel option for deleting themes + $(document).on('click',".button.cancelDeleteObjects",function(){ + $('#myModal').foundation('reveal', 'close'); + }); + + + $("document").on("hover", ".jqtree-title.jqtree_common", function(){ + setTimeout(function(){ + }, 1000); + + alert($(this).siblings("a").attr("id")); + }); + + // Script for selecting all objects + $(document).on('click',".checkedAll",function(){ + if($(this).is(":checked")==true) + { + $('.objectsCheckbox input').prop( "checked", true ); + } + else + { + $('.objectsCheckbox input').prop( "checked", false ); + } + }); + + // Script for cancel option for deleting themes + $(document).on('click',".button.cancelDeleteObjects",function(){ + $('#myModal').foundation('reveal', 'close'); + }); + + // script for delete themes + $(document).on('click',".button.deleteObjects",function(){ + var selectedobject = $(".objectsCheckbox input:checked") + + if(selectedobject.length > 0) + { + $('#myModal').foundation('reveal', 'open'); + + var i = 0; + var str = ""; + $.map(selectedobject,function(each){ + if(i == 0) + { + str = str.concat(each.parentElement.id) + } + else + { + str = str.concat(","+each.parentElement.id) + } + + i= i+1 + }) + + $.ajax({ + url: "{% url 'delete_themes' groupid %}", + type: 'POST', + data:{ + context_theme: "{{node.pk}}", + deleteobjects: str, + csrfmiddlewaretoken: '{{ csrf_token }}' + }, + success: function(result){ + + $("#deletion_results").html(""); + for(var obj in result) + { + var li = $("<ul><li><b>"+result[obj].title+"</b></li></ul>").appendTo($("#deletion_results")); + } + + }, + }); + + } + else + { + alert("select object to delete") + } + + }); + + + // Script for delete themes after confirm delete. + $(document).on('click',".button.confirmDeleteObjects",function(){ + var selectedobject = $(".objectsCheckbox input:checked") + + if(selectedobject.length > 0) + { + var i = 0; + var str = ""; + + $.map(selectedobject,function(each){ + if(i == 0) + { + str = str.concat(each.parentElement.id) + } + else + { + str = str.concat(","+each.parentElement.id) + } + + i= i+1 + }); + + $.ajax({ + url: "{% url 'delete_themes' groupid %}", + type: 'POST', + data:{ + context_theme: "{{node.pk}}", + deleteobjects: str, + confirm:"yes", + csrfmiddlewaretoken: '{{ csrf_token }}' + }, + success: function(result){ + alert("Themes deleted successfully"); + $('#myModal').foundation('reveal', 'close'); + location.reload(true); + }, + + }); + + } + else{ + alert("select object to delete") + } + + }); + + + </script> + + + {% if themes_hierarchy %} <!-- bool --> + + <h2> {{node.name}}</h2> + <div class="row"> + <div class="large-4 columns"> + + {% if user_access == "allow" %} + + <a class="button tiny" data-reveal-id="view_add_page" title="Add Theme Item"> + + Add Theme Item + </a> + + <div id="view_add_page" class="reveal-modal" data-reveal style="height:300px;"> + + <h3>Add New Theme Item:</h3> + <!-- To enter name of theme item --> + <div> + <input class="name_id" name="name" type="text" placeholder="Enter name..."> + </div> <br/> + + <input type="submit" id="add_theme_item" value="Save Theme Item" class="medium round button"/> + + <a class="close-reveal-modal">×</a> + + </div> + {% endif %} + </div> + + <div class="large-4 columns"> + + <a data-dropdown="hover1" data-options="is_hover:true; hover_timeout:5000" class="tree_browser" style="border: 2px solid #0eacb5; padding: 5px;"><b> {% trans "Tree Browser" %} </b></a> + <ul id="hover1" class="f-dropdown" data-dropdown-content> + <li><a class="fold"><i class="fi-plus"></i> {% trans "Fold" %} </a></li> + <li><a class="unfold"><i class="fi-minus"></i> {% trans "Unfold" %} </a></li> + </ul> + + <a class="collapsible_tree" style="border: 2px solid #0eacb5; padding: 5px;"><b> {% trans "Collapsible Tree" %} </b></a> + + </div> + + <div class="large-4 columns"> + {% if user.is_authenticated %} + {% if user_access == "allow" %} + + <input class="button tiny deleteObjects right" type="button" value="Delete"> + <span class="right"><input class="checkedAll" type="checkbox"> Select All </span> + + <div id="myModal" class="reveal-modal" data-reveal style="height:500px;overflow:scroll;"> + + <h3>{% trans "Are you sure you want to delete? All of the related items for the following themes also will be deleted:" %}</h3> + + <input class="button confirmDeleteObjects" type="button" value="Confirm"> + <input class="button cancelDeleteObjects" type="button" value="Cancel"> + <div id="deletion_results"></div> + <a class="close-reveal-modal">×</a> + + </div> + + {% endif %} + {% endif %} + </div> + </div> + <hr/> + + {% endif %} diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/node_ajax_view.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/node_ajax_view.html index 59e9cf3..6548448 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/node_ajax_view.html +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/node_ajax_view.html @@ -303,7 +303,6 @@ ul#navigation li a.last { <div class="row page" itemscope itemtype="{{schema.1.type}}"> <section class="medium-9 columns"> - {% if breadcrumbs_list %} <ul class="breadcrumbs"> {% for e in breadcrumbs_list %} @@ -316,6 +315,15 @@ ul#navigation li a.last { </b></li> {% endfor %} </ul> + {% elif node.teaches %} + <ul class="breadcrumbs"> + <li> + {% for each_topic in node.teaches %} + <a href="{% url 'topic_details' group_name_tag each_topic.pk %}" style="color:black;">{{ each_topic.name }},</a> + {% endfor %} + </li> + </ul> + {% endif %} {% if node.status == 'MODERATION' %} @@ -559,23 +567,7 @@ ul#navigation li a.last { --> {% endcomment %} - <div class="small-4 columns"> - {% get_teaches_list node as teaches_list %} - {% if teaches_list %} - <div class="panel"> - <h6>Resource for: </h6> - {% for each_node in teaches_list %} - {% get_grid_fs_object each_node as grid_fs_obj %} - {% if each_node.mime_type %} - <a href="{% url 'read_file' group_name_tag each_node.pk grid_fs_obj.filename %}{% if nav_list %}?nav_li={{nav_list}}{% endif %}">{{ each_node.name }}</a>, - {% else %} - <a href="{% url 'topic_details' group_name_tag each_node.pk %}{% if nav_list %}?nav_li={{nav_list}}{% endif %}">{{ each_node.name }}</a> - {% if not forloop.last %}, {% endif %} - {% endif %} - {% endfor %} - </div> - {% endif %} - </div> + <div class="small-4 columns"> </div> <div class="small-4 small-pull-4 columns"> <!-- {#% if node.assesses %#} --> @@ -1291,7 +1283,8 @@ ul#navigation li a.last { {% edit_policy groupid node request.user as status %} - {% if user.is_authenticated and status == "allow" and user_access == "allow" and "Group" in group_object.member_of_names_list %} + {% if user.is_authenticated and status == "allow" and user_access == "allow" %} + {% if "Group" in group_object.member_of_names_list or "Author" in group_object.member_of_names_list %} {% get_edit_url node.pk as edit_url %} {% check_group node as is_group %} @@ -1460,6 +1453,7 @@ ul#navigation li a.last { {% endif %} {% endif %} {% endif %} + {% endif %} </div> {% endif %} @@ -1661,7 +1655,7 @@ ul#navigation li a.last { {% if topic %} - location.href = "{% url 'theme_page' group_name_tag theme_id %}?selected="+clicked_node+""; + location.href = "{% url 'theme_page' group_name_tag theme_id %}?tree=hierarchical&selected="+clicked_node+""; {% else %} diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/node_edit_base.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/node_edit_base.html index 64b3cdb..5a930fe 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/node_edit_base.html +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/node_edit_base.html @@ -378,15 +378,28 @@ i.remove-tag{ </label> </div> {% endfor %} - <div class="small-6 columns"> <label> <h5>{% trans "Based on Url: " %} </h5> - <input name="basedonurl" type="text" value=""> + <input name="basedonurl" type="text" value="{{node.basedonurl}}"> </label> </div> </div> + <div class="row"> + <div class="small-6 columns"> + <label> + <h5>{% trans "License: " %} </h5> + <input name="license" type="text" value="{{node.license}}"> + </label> + </div> + <div class="small-6 columns"> + <label> + <h5>{% trans "Source: " %} </h5> + <input name="source" type="text" value="{{node.source}}"> + </label> + </div> + </div> <div id="metadata_info"></div> </div> {% endcache %} diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/partner.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/partner.html index b12f90b..1349b1d 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/partner.html +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/partner.html @@ -7,7 +7,16 @@ {% block title %} {{groups_category}} {% endblock %} {% block meta_content %} -<h2 class="subheader">{{groups_category}}</h2> + + <h2 class="subheader"> + {% if app_gst.altnames and app_gst.altnames != "None" %} + {{app_gst.altnames}} + {% else %} + {{app_gst.name}} + {% endif%} + </h2> + {{app_gst.content|default_if_none:''|safe}} + {% endblock %} diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/partner_list.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/partner_list.html index 4223e87..5432d1a 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/partner_list.html +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/partner_list.html @@ -8,6 +8,19 @@ {% block meta_content %} <h2 class="subheader">{{groups_category}}s</h2> +<!-- + {% comment %} + <a href="{% url app_gst.name|lower group_name_tag %}"> + <h2 class="subheader"> + {% if app_gst.altnames and app_gst.altnames != "None" %} + {{app_gst.altnames}} + {% else %} + {{app_gst.name}} + {% endif%} + </h2> + {{app_gst.content|safe}} + </a> + {% endcomment %} --> {% endblock %} diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/repository.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/repository.html index 9b4b4a8..d04853c 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/repository.html +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/repository.html @@ -1,5 +1,5 @@ {% extends "ndf/base.html" %} - +{% load i18n %} {% load ndf_tags %} {% load cache %} @@ -14,8 +14,8 @@ } .app-card{ - width: 12rem; - min-height: 20rem; + width: 17rem; + min-height: 17rem; margin: 20px 1rem; background-color: #efefef; border: thin solid lightgray; @@ -35,31 +35,24 @@ font-size: 7em; z-index: 0; opacity: 0.1; - padding-top: 5rem; + padding-top: 2rem; } {% endblock %} + +{% block meta_content %} + <h2 class="subheader">{% trans "Repository" %}</h2> +{% endblock %} + +{% block related_content%} + content goes here... +{% endblock %} + {% block body_content %} - {% comment %} - <!-- - <ul class="inline-list"> - {% for each_gapp in gapps_dict %} - <li> - <a class="app-card text-center" - {% if each_gapp.values.0 %} href="{% url each_gapp.values.0 group_id %}" {% endif %} > - <i class="icons fi-asterisk"></i> - <h4><small>{{ each_gapp.keys.0 }}</small></h4> - <hr/> - </a> - </li> - {% endfor %} - </ul> - --> - {% endcomment %} - - <ul class="inline-list card-holder"> + <!-- <ul class="inline-list card-holder"> --> + <ul class="small-block-grid-1 medium-block-grid-2 large-block-grid-3"> {% for each_gapp in gapps_obj_list %} <li> <a class="app-card text-center" href="{% url each_gapp.name|lower group_id %}"> @@ -73,12 +66,12 @@ </ul> <script type="text/javascript"> - // removing left panel: - $("main.row > aside.columns").detach(); + // // removing left panel: + // $("main.row > aside.columns").detach(); - // making body_content block to take 12-large columns - $article = $("main.row > article.columns"); - $article.removeClass("medium-10").addClass("large-12"); + // // making body_content block to take 12-large columns + // $article = $("main.row > article.columns"); + // $article.removeClass("medium-10").addClass("large-12"); </script> {% endblock %} diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/theme.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/theme.html index 280f231..7fa7240 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/theme.html +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/theme.html @@ -7,52 +7,47 @@ {% get_group_name groupid as group_name_tag %} - {% block title %} {{ title }} {% endblock %} {% block head %} - <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> + + <!-- Scripts required for D3 graph --> + <script type="text/javascript" src="/static/ndf/bower_components/d3/d3.min.js"></script> + <script type="text/javascript" src="/static/ndf/bower_components/underscore/underscore.js"></script> + <script sync="text/javascript" src="/static/ndf/bower_components/FileSaver/FileSaver.js" ></script> - <!-- Scripts required for D3 graph --> - <script type="text/javascript" src="/static/ndf/bower_components/d3/d3.min.js"></script> <!-- checked --> - <script type="text/javascript" src="/static/ndf/bower_components/underscore/underscore.js"></script> <!-- checked --> - <script sync="text/javascript" src="/static/ndf/bower_components/FileSaver/FileSaver.js" ></script> <!-- checked --> + <link href="/static/ndf/bower_components/jqtree/jqtree.css" rel="stylesheet"> + <script src="/static/ndf/bower_components/jqtree/tree.jquery.js"></script> - <link href="/static/ndf/bower_components/jqtree/jqtree.css" rel="stylesheet"> - <script src="/static/ndf/bower_components/jqtree/tree.jquery.js"></script> <!-- checked --> - - <script type="text/javascript"> +<!-- <script type="text/javascript"> $(document).ready(function() { + // Funtion for loading tree for showing collection list left side panel + doc(); - // Funtion for loading tree for showing collection list left side panel - doc(); + // Function for manipulating tree when user visits to page directly via browser url + {% if selected %} TreeTillNode(); {% endif %} + }); - // Function for manipulating tree when user visits to page directly via browser url - {% if selected %} - TreeTillNode(); - {% endif %} + function TreeTillNode () { - }); + // This gives the last hierarchy node id from browser url. + var url = "{{selected}}"; + var tree_build = $(".themes").not(".jqtree-loading"); + var node = tree_build.tree('getNodeById', url); + tree_build.tree('openNode', node); - function TreeTillNode () { - // This gives the last hierarchy node id from browser url. - var url = "{{selected}}"; + // Javascript function to be used for checking objects in specific time of interval + setTimeout(function(){ - var tree_build = $(".themes").not(".jqtree-loading"); - var node = tree_build.tree('getNodeById', url); - tree_build.tree('openNode', node); - - // Javascript function to be used for checking objects in specific time of interval - setTimeout(function(){ - // console.log($(".themes")) - if( ($(".themes").length > 0) ) { TreeTillNode() } - }, 100 ); - + // console.log($(".themes")) + if( ($(".themes").length > 0) ) { TreeTillNode() } + }, 100 ); } @@ -80,16 +75,12 @@ else{ $li.find('.jqtree-title').before('  <span class="fi-folder" style="color:orange"></span> '); } - if (node.node_type == "Topic"){ - $li.find('.jqtree-element').append( ' <a id='+node.id+' name='+node.name+' class="topic" href="/{{groupid}}/topics/'+node.id+'/"> </a>' - ); - } else{ if (user == "True"){ @@ -103,12 +94,8 @@ {% endif %} ); } - } - - } - }); // bind 'tree.click' event @@ -143,7 +130,6 @@ if (node.node_type == "Topic"){ location.href = "/{{group_name_tag}}/topic_details/"+node.id+"?nav_li="+nav_list+""; - } } @@ -239,8 +225,6 @@ } } - - }); // console.log($(".jqtree-element.jqtree_common")) @@ -278,9 +262,9 @@ showTopicStats(); </script> - + --> <style> - +/* #app-set-item li { padding:0.5em } .jqtree-closed > .jqtree-element i.icon-folder-open:before { @@ -289,7 +273,7 @@ .jqtree-tree i { margin-right: 4px; } - /* for reingold tilford tree */ +*/ /* for reingold tilford tree */ /* .node { cursor: pointer; @@ -313,26 +297,31 @@ */ /* for reingold tilford tree -- end */ - .node { + /*.node { cursor: pointer; - } - + }*/ +/* .node circle { fill: #fff; stroke: steelblue; stroke-width: 1.5px; } - - .node text { +*/ + /*.node text { font-size:10px; font-family:sans-serif; - } - + }*/ +/* .link { fill: none; stroke: #ccc; stroke-width: 1.5px; } +*/ + #theme-drag-zoom-tree-container{ + border: medium dashed #D8BFD8; + border-radius: 5px; + } /* .templink { fill: none; @@ -340,28 +329,51 @@ stroke-width: 3px; } */ - .ghostCircle.show{ + /*.ghostCircle.show{ display:block; - } - + }*/ +/* .ghostCircle, .activeDrag .ghostCircle{ display: none; + }*/ + + .download-graph{ + color: gray + } + .download-graph:hover { + color: black; + background-color: #e5e5e5; + font-size: large; + cursor: pointer; + padding: 0.5em; + transition: all 1s; } </style> {% endblock%} -{% block shelf_content %} - {% if user.is_authenticated %} - {% include "ndf/shelf.html" %} - {% else %} - <h4>Please Login to create your shelf</h4> - {% endif %} -{% endblock %} +{% comment %} + {% block shelf_content %} + {% if user.is_authenticated %} + {% include "ndf/shelf.html" %} + {% else %} + <h4>Please Login to create your shelf</h4> + {% endif %} + {% endblock %} +{% endcomment %} {% block meta_content %} - <a class="Tp" href="{% url 'topics' group_name_tag %}" title="Click to go to themes card view"><h2 class="subheader">{% trans "Themes" %}</h2></a> + <a class="Tp" href="{% url 'topics' group_name_tag %}" title="Click to go to themes card view"> + <h3 class="subheader"> + {% if theme_GST.altnames and theme_GST.altnames != "None" %} + {{theme_GST.altnames}} + {% else %} + {{theme_GST.name}} + {% endif%} + </h3> + </a> + {{theme_GST.content|default_if_none:""|safe}} {% endblock %} {% block related_content %} @@ -371,17 +383,17 @@ <div class="panel" style="background-color:#ddd;"> <ul class="no-bullet" id="app-set-item"> - {% get_memberof_objects_count theme_GST_id groupid as count %} - + {% get_memberof_objects_count theme_GST.pk groupid as count %} + <li class="selected-app-set-item"> <div> {% if user_access == "allow" %} - <a href="{% url "theme_topic_create" groupid theme_GST_id %}" style="float:right;color:#0b8a91;" title="Add Theme"> + <a href="{% url "theme_topic_create" groupid theme_GST.pk %}" style="float:right;color:#0b8a91;" title="Add Theme"> + Add </a> {% endif %} - <a href="{% url "theme_list" groupid app_id theme_GST_id %}" style="color:#0b8a91;"> + <a href="{% url "theme_list" groupid app_id theme_GST.pk %}" style="color:#0b8a91;"> Theme ({{count}}) </a> @@ -398,90 +410,30 @@ {% block body_content %} -{% user_access_policy groupid request.user as user_access %} - - <!-- This overlay is for displaying topic details from collapsible tree --> - <!-- <div id="collaps_topic_details" class="reveal-modal" style="height:500px;overflow:hidden;width:80%" data-reveal> - <h3>Topic details comming soon !!!</h3> - <a class="close-reveal-modal" >×</a> - </div> --> - <!-- End of overlay --> - - {% if themes_hierarchy %} - - <h2> {{node.name}}</h2> - <div class="row"> - <div class="large-4 columns"> - - {% if user_access == "allow" %} - - <a class="button tiny" data-reveal-id="view_add_page" title="Add Theme Item"> - + Add Theme Item - </a> - - <div id="view_add_page" class="reveal-modal" data-reveal style="height:300px;"> - - <h3>Add New Theme Item:</h3> - <!-- To enter name of theme item --> - <div> - <input class="name_id" name="name" type="text" placeholder="Enter name..."> - </div> <br/> - - <input type="submit" id="add_theme_item" value="Save Theme Item" class="medium round button"/> - - <a class="close-reveal-modal">×</a> - </div> - {% endif %} - </div> - - <div class="large-4 columns"> + {% user_access_policy groupid request.user as user_access %} - <a data-dropdown="hover1" data-options="is_hover:true; hover_timeout:5000" class="tree_browser" style="border: 2px solid #0eacb5; padding: 5px;"><b> {% trans "Tree Browser" %} </b></a> - <ul id="hover1" class="f-dropdown" data-dropdown-content> - <li><a class="fold"><i class="fi-plus"></i> {% trans "Fold" %} </a></li> - <li><a class="unfold"><i class="fi-minus"></i> {% trans "Unfold" %} </a></li> - </ul> - - <a class="collapsible_tree" style="border: 2px solid #0eacb5; padding: 5px;"><b> {% trans "Collapsible Tree" %} </b></a> - </div> + {% if themes_hierarchy and node %} - <div class="large-4 columns"> - {% if user.is_authenticated %} - {% if user_access == "allow" %} - - <input class="button tiny deleteObjects right" type="button" value="Delete"> - <span class="right"><input class="checkedAll" type="checkbox"> Select All </span> - <div id="myModal" class="reveal-modal" data-reveal style="height:500px;overflow:scroll;"> - - <h3>{% trans "Are you sure you want to delete? All of the related items for the following themes also will be deleted:" %}</h3> - - <input class="button confirmDeleteObjects" type="button" value="Confirm"> - <input class="button cancelDeleteObjects" type="button" value="Cancel"> - <div id="deletion_results"></div> - <a class="close-reveal-modal">×</a> + {% cache 300 theme_tree node.pk request.LANGUAGE_CODE tree unfold %} - </div> + {% include "ndf/hierarchy_tree.html" %} + <div id="app-set-item" class="themes hide" data-url="{% url 'get_tree_hierarchy' groupid node.pk %}"> + </div> - {% endif %} - {% endif %} - </div> - </div> - <hr/> - - {% if node %} - {% cache 300 theme_tree node.pk request.LANGUAGE_CODE %} - <!-- If "Theme" node --> - <div id="app-set-item" class="themes" data-url="{% url 'get_tree_hierarchy' groupid node.pk %}"></div> - - <!-- testing --> + <div id="theme-drag-zoom-tree-container" class="hide"> + <div id="theme-drag-zoom-tree"></div> + <div class="row"> + <div class="small-6 small-centered text-center columns download-graph" onclick='downloadCollapsibleGraph("{{node.name}}");'> + Download "{{node.name}}" Collapsible Graph + </div> + </div> + </div> {% include 'ndf/theme_drag_zoom_d3tree.html' %} - {% endcache %} - - {% endif %} - + {% endcache %} + {% endif %} <!-- For displaying themes items --> @@ -654,358 +606,316 @@ <script type="text/javascript"> // ------ jqtree tree ------ - $("document").on("hover", ".jqtree-title.jqtree_common", function(){ - setTimeout(function(){ - }, 1000); + // script for fold themes_cards hierarchy - alert($(this).siblings("a").attr("id")); - }); + // being the common template for all, to distinguish between the tree landing using following condition: + {% if node and tree %} + + {% if tree == "hierarchical" %} + if({{unfold}}) + { + $("article").block({message: '<h4>Building a graph... <br/>Please hold on...</h4>'}); + $("#theme-drag-zoom-tree-container").addClass("hide") + $(".themes").removeClass("hide"); + plotHierarchyTree(true); + } + else + { + $("article").block({message: '<h4>Building a graph... <br/>Please hold on...</h4>'}); + $("#theme-drag-zoom-tree-container").addClass("hide") + $(".themes").removeClass("hide"); + plotHierarchyTree(false); + } + + {% else %} + + $(".themes").addClass("hide"); + + {% if node %} + + $("article").block({message: '<h4>Building a graph... <br/>Please hold on...</h4>'}); + $.getJSON("{% url 'get_tree_hierarchy' group_id node.pk %}?collapsible=true", function(data){ treeData = data;}) + .done(function(){plotDragZoomTree(treeData); + }); + + {% endif %} + + $("#theme-drag-zoom-tree-container").removeClass("hide"); + + {% endif %} + + {% endif %} - $("#add_theme_item").click(function() { - $.ajax({ - type: "POST", - url: "{% url 'add_theme_item' groupid %}", - datatype: "html", - data:{ - context_theme: "{{node.pk}}", - name: $(".name_id").val(), - csrfmiddlewaretoken: '{{ csrf_token }}' - }, - success: function(data) { - - var item = $(".name_id").val(); - - if ($.trim(data) === "failure") { - alert("Theme item "+ item +" already available, Please choose different name"); - } - - if ($.trim(data) === "success") { - location.reload(true); - } - - $(".name_id").val(""); - } - }); - }); - // script for fold themes_cards hierarchy $(".fold").click(function() { - $(function() { - location.href = "{% url 'theme_page' group_name_tag app_id %}"; - }); + + // $("#theme-drag-zoom-tree-container").addClass("hide") + // $(".themes").removeClass("hide"); + // plotHierarchyTree(false); + // $(function() { + location.href = "{% url 'theme_page' group_name_tag app_id %}?tree=hierarchical"; + // }); }); // script for unfold themes hierarchy $(".unfold").click(function() { - $(function() { - location.href = "{% url 'theme_page' group_name_tag app_id %}?unfold=true"; - }); + + // $("#theme-drag-zoom-tree-container").addClass("hide") + // $(".themes").removeClass("hide"); + // plotHierarchyTree(true); + // $(function() { + location.href = "{% url 'theme_page' group_name_tag app_id %}?tree=hierarchical&unfold=true"; + // }); }); $(".tree_browser").click(function() { - $(function() { - location.href = "{% url 'theme_page' group_name_tag app_id %}"; - }); + + // $("#theme-drag-zoom-tree-container").addClass("hide") + // $(".themes").removeClass("hide"); + // plotHierarchyTree() + // $(function() { + location.href = "{% url 'theme_page' group_name_tag app_id %}?tree=hierarchical"; + // }); }); - // script for delete themes - $(document).on('click',".button.deleteObjects",function(){ - var selectedobject = $(".objectsCheckbox input:checked") - if(selectedobject.length > 0) - { - $('#myModal').foundation('reveal', 'open'); - - var i = 0; - var str = ""; - $.map(selectedobject,function(each){ - if(i == 0) - { - str = str.concat(each.parentElement.id) - } - else - { - str = str.concat(","+each.parentElement.id) - } - - i= i+1 - }) - - $.ajax({ - url: "{% url 'delete_themes' groupid %}", - type: 'POST', - data:{ - context_theme: "{{node.pk}}", - deleteobjects: str, - csrfmiddlewaretoken: '{{ csrf_token }}' - }, - success: function(result){ - - $("#deletion_results").html(""); - for(var obj in result) - { - var li = $("<ul><li><b>"+result[obj].title+"</b></li></ul>").appendTo($("#deletion_results")); - } - - }, - }); - - } - else - { - alert("select object to delete") - } - - }); - - // Script for delete themes after confirm delete. - $(document).on('click',".button.confirmDeleteObjects",function(){ - var selectedobject = $(".objectsCheckbox input:checked") - - if(selectedobject.length > 0) - { - var i = 0; - var str = ""; - - $.map(selectedobject,function(each){ - if(i == 0) - { - str = str.concat(each.parentElement.id) - } - else - { - str = str.concat(","+each.parentElement.id) - } + $(".collapsible_tree").click(function() { + location.href = "{% url 'theme_page' group_name_tag app_id %}?tree=collapsible"; - i= i+1 - }); + // $(".themes").addClass("hide"); - $.ajax({ - url: "{% url 'delete_themes' groupid %}", - type: 'POST', - data:{ - context_theme: "{{node.pk}}", - deleteobjects: str, - confirm:"yes", - csrfmiddlewaretoken: '{{ csrf_token }}' - }, - success: function(result){ - alert("Themes deleted successfully"); - $('#myModal').foundation('reveal', 'close'); - location.reload(true); - }, - - }); - - } - else{ - alert("select object to delete") - } + // {% if node %} - }); + // $.getJSON("{% url 'get_tree_hierarchy' group_id node.pk %}?collapsible=true", function(data){ treeData = data;}) + // .done(function(){plotDragZoomTree(treeData)}); - // Script for selecting all objects - $(document).on('click',".checkedAll",function(){ - if($(this).is(":checked")==true) - { - $('.objectsCheckbox input').prop( "checked", true ); - } - else - { - $('.objectsCheckbox input').prop( "checked", false ); - } + // {% endif %} + + // $("#theme-drag-zoom-tree-container").removeClass("hide") }); - // Script for cancel option for deleting themes - $(document).on('click',".button.cancelDeleteObjects",function(){ - $('#myModal').foundation('reveal', 'close'); + // $("#theme-drag-zoom-container").removeClass("hide"); + + // // calling function plotDragZoomTree defined in theme_drag_zoom_d3tree.html + // } + + + $("#add_theme_item").click(function() { + $.ajax({ + type: "POST", + url: "{% url 'add_theme_item' groupid %}", + datatype: "html", + data:{ + context_theme: "{{node.pk}}", + name: $(".name_id").val(), + csrfmiddlewaretoken: '{{ csrf_token }}' + }, + success: function(data) { + + var item = $(".name_id").val(); + + if ($.trim(data) === "failure") { + alert("Theme item "+ item +" already available, Please choose different name"); + } + + if ($.trim(data) === "success") { + location.reload(true); + } + + $(".name_id").val(""); + } + }); + }); + // ------END of jqtree tree ------ // --- start of D3 collapsible tree --- - treeData = "" + // treeData = "" - $(".collapsible_tree").click(function() { + // $(".collapsible_tree").click(function() { - if(treeData.length != 0) - { - plotCollapsibleTree(treeData) - } - else{ - {% if node %} - $.getJSON("{% url 'get_tree_hierarchy' group_id node.pk %}?collapsible=true", function(data){ treeData = data;}) - .done(function(){plotCollapsibleTree(treeData)}); - {% endif %} - } - }); - - function plotCollapsibleTree (treeData) { - $(".themes").html(""); + // if(treeData.length != 0) + // { + // plotCollapsibleTree(treeData) + // } + // else{ + // {% if node %} - var margin = {top: 20, right: 40, bottom: 20, left: 40}, - width = Math.max($(".themes").width(), 960) - margin.right - margin.left, - height = Math.max($(".themes").height(), 800) - margin.top - margin.bottom; - - var i = 0, - duration = 750, - root; - - var tree = d3.layout.tree() - .size([height, width]); - - var diagonal = d3.svg.diagonal() - .projection(function(d) { return [d.y, d.x]; }); - - var svg = d3.select(".themes").append("svg") - .attr("width", width + margin.right + margin.left) - .attr("height", height + margin.top + margin.bottom) - .append("g") - .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); - - {% if node %} - // d3.json("{% url 'get_tree_hierarchy' group_id node.pk %}?collapsible=true", function(error, flare) { - root = treeData; - root.x0 = height / 2; // the point from where it starts it's animation. - root.y0 = 0; - - function collapse(d) { - if (d.children) { - d._children = d.children; - d._children.forEach(collapse); - d.children = null; - } - } - - root.children.forEach(collapse); - update(root); - // }); - {% endif %} - - // d3.select(self.frameElement).style("height", "800px"); - - function update(source) { - - // Compute the new tree layout. - var nodes = tree.nodes(root).reverse(), - links = tree.links(nodes); - - // Normalize for fixed-depth. - nodes.forEach(function(d) { d.y = d.depth * 150;}); - - // Update the nodes - var node = svg.selectAll("g.node") - .data(nodes, function(d) { return d.id || (d.id = ++i); }); - - // Enter any new nodes at the parent's previous position. - var nodeEnter = node.enter().append("g") - .attr("class", "node") - .attr("transform", function(d) { return "translate(" + source.y0 + "," + source.x0 + ")"; }) - .attr("title", function(d) { return d.name; }) - .on("click", click); - - nodeEnter.append("circle") - .attr("r", 1e-6) - .style("fill", function(d) { return d._children ? "#10c1cb" : "#fff"; }); - - nodeEnter.append("text") - .attr("x", function(d) { return d.children || d._children ? -10 : 10; }) - .attr("dy", "0.35em") - .attr("text-anchor", function(d) { return d.children || d._children ? "end" : "start"; }) - .text(function(d) { return d.name; }) - .style("fill-opacity", 1e-6); - - // Transition nodes to their new position. - var nodeUpdate = node.transition() - .duration(duration) - .attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; }); - - nodeUpdate.select("circle") - .attr("r", 6.5) - .style("fill", function(d) { return d._children ? "#10c1cb" : "#fff"; }); - - nodeUpdate.select("text") - .style("fill-opacity", 1); - - // Transition exiting nodes to the parent's new position. - var nodeExit = node.exit().transition() - .duration(duration) - .attr("transform", function(d) { return "translate(" + source.y + "," + source.x + ")"; }) - .remove(); - - nodeExit.select("circle") - .attr("r", 1e-6); - - nodeExit.select("text") - .style("fill-opacity", 1e-6); - - // Update the links - var link = svg.selectAll("path.link") - .data(links, function(d) { return d.target.id; }); - - // Enter any new links at the parent's previous position. - link.enter().insert("path", "g") - .attr("class", "link") - .attr("d", function(d) { - var o = {x: source.x0, y: source.y0}; - return diagonal({source: o, target: o}); - }); - - // Transition links to their new position. - link.transition() - .duration(duration) - .attr("d", diagonal); - - // Transition exiting nodes to the parent's new position. - link.exit().transition() - .duration(duration) - .attr("d", function(d) { - var o = {x: source.x, y: source.y}; - return diagonal({source: o, target: o}); - }) - .remove(); - - // Stash the old positions for transition. - nodes.forEach(function(d) { - d.x0 = d.x; - d.y0 = d.y; - }); - } + // $.getJSON("{% url 'get_tree_hierarchy' group_id node.pk %}?collapsible=true", function(data){ treeData = data;}) + // .done(function(){plotCollapsibleTree(treeData)}); - // Toggle children on click. - function click(d) { - if (d.children) { - d._children = d.children; - d.children = null; - // console.log("non-leaf 1"); - } - else { - if(d._children){ - d.children = d._children; - d._children = null; - // console.log("non-leaf 2"); - } - else if (d.node_type == "Topic"){ - // console.log("Leaf!"); - var a = document.createElement('a'); - a.setAttribute('href', "/{{group_name_tag}}/topic_details/"+d.id+""); - // a.setAttribute('target', '_blank'); - document.body.appendChild(a); - a.click(); - a.remove(); - // location.href = "/{{group_name_tag}}/topic_details/"+d.id+""; - // $('#collaps_topic_details').foundation('reveal', 'open'); - } - } - update(d); - } - - $("#theme-drag-zoom-container").removeClass("hide"); + // {% endif %} + // } + // }); + + // function plotCollapsibleTree (treeData) { + // $(".themes").html(""); - // calling function plotDragZoomTree defined in theme_drag_zoom_d3tree.html - plotDragZoomTree(treeData); - } + // var margin = {top: 20, right: 40, bottom: 20, left: 40}, + // width = Math.max($(".themes").width(), 960) - margin.right - margin.left, + // height = Math.max($(".themes").height(), 800) - margin.top - margin.bottom; + + // var i = 0, + // duration = 750, + // root; + + // var tree = d3.layout.tree() + // .size([height, width]); + + // var diagonal = d3.svg.diagonal() + // .projection(function(d) { return [d.y, d.x]; }); + + // var svg = d3.select(".themes").append("svg") + // .attr("width", width + margin.right + margin.left) + // .attr("height", height + margin.top + margin.bottom) + // .append("g") + // .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); + + // {% if node %} + + // root = treeData; + // root.x0 = height / 2; // the point from where it starts it's animation. + // root.y0 = 0; + + // function collapse(d) { + // if (d.children) { + // d._children = d.children; + // d._children.forEach(collapse); + // d.children = null; + // } + // } + + // root.children.forEach(collapse); + // update(root); + // // }); + // {% endif %} + + // // d3.select(self.frameElement).style("height", "800px"); + + // function update(source) { + + // // Compute the new tree layout. + // var nodes = tree.nodes(root).reverse(), + // links = tree.links(nodes); + + // // Normalize for fixed-depth. + // nodes.forEach(function(d) { d.y = d.depth * 150;}); + + // // Update the nodes + // var node = svg.selectAll("g.node") + // .data(nodes, function(d) { return d.id || (d.id = ++i); }); + + // // Enter any new nodes at the parent's previous position. + // var nodeEnter = node.enter().append("g") + // .attr("class", "node") + // .attr("transform", function(d) { return "translate(" + source.y0 + "," + source.x0 + ")"; }) + // .attr("title", function(d) { return d.name; }) + // .on("click", click); + + // nodeEnter.append("circle") + // .attr("r", 1e-6) + // .style("fill", function(d) { return d._children ? "#10c1cb" : "#fff"; }); + + // nodeEnter.append("text") + // .attr("x", function(d) { return d.children || d._children ? -10 : 10; }) + // .attr("dy", "0.35em") + // .attr("text-anchor", function(d) { return d.children || d._children ? "end" : "start"; }) + // .text(function(d) { return d.name; }) + // .style("fill-opacity", 1e-6); + + // // Transition nodes to their new position. + // var nodeUpdate = node.transition() + // .duration(duration) + // .attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; }); + + // nodeUpdate.select("circle") + // .attr("r", 6.5) + // .style("fill", function(d) { return d._children ? "#10c1cb" : "#fff"; }); + + // nodeUpdate.select("text") + // .style("fill-opacity", 1); + + // // Transition exiting nodes to the parent's new position. + // var nodeExit = node.exit().transition() + // .duration(duration) + // .attr("transform", function(d) { return "translate(" + source.y + "," + source.x + ")"; }) + // .remove(); + + // nodeExit.select("circle") + // .attr("r", 1e-6); + + // nodeExit.select("text") + // .style("fill-opacity", 1e-6); + + // // Update the links + // var link = svg.selectAll("path.link") + // .data(links, function(d) { return d.target.id; }); + + // // Enter any new links at the parent's previous position. + // link.enter().insert("path", "g") + // .attr("class", "link") + // .attr("d", function(d) { + // var o = {x: source.x0, y: source.y0}; + // return diagonal({source: o, target: o}); + // }); + + // // Transition links to their new position. + // link.transition() + // .duration(duration) + // .attr("d", diagonal); + + // // Transition exiting nodes to the parent's new position. + // link.exit().transition() + // .duration(duration) + // .attr("d", function(d) { + // var o = {x: source.x, y: source.y}; + // return diagonal({source: o, target: o}); + // }) + // .remove(); + + // // Stash the old positions for transition. + // nodes.forEach(function(d) { + // d.x0 = d.x; + // d.y0 = d.y; + // }); + // } + + // // Toggle children on click. + // function click(d) { + // if (d.children) { + // d._children = d.children; + // d.children = null; + // // console.log("non-leaf 1"); + // } + // else { + // if(d._children){ + // d.children = d._children; + // d._children = null; + // // console.log("non-leaf 2"); + // } + // else if (d.node_type == "Topic"){ + // // console.log("Leaf!"); + // var a = document.createElement('a'); + // a.setAttribute('href', "/{{group_name_tag}}/topic_details/"+d.id+""); + // // a.setAttribute('target', '_blank'); + // document.body.appendChild(a); + // a.click(); + // a.remove(); + // // location.href = "/{{group_name_tag}}/topic_details/"+d.id+""; + // // $('#collaps_topic_details').foundation('reveal', 'open'); + // } + // } + // update(d); + // } + + // $("#theme-drag-zoom-container").removeClass("hide"); + + // // calling function plotDragZoomTree defined in theme_drag_zoom_d3tree.html + // plotDragZoomTree(treeData); + // } // ---END of D3 collapsible tree diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/theme_drag_zoom_d3tree.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/theme_drag_zoom_d3tree.html index 847bb78..3710cda 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/theme_drag_zoom_d3tree.html +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/theme_drag_zoom_d3tree.html @@ -1,23 +1,8 @@ -<div id="theme-drag-zoom-container" class="hide"> - - <a href="#" data-reveal-id="theme-drag-zoom-tree">Show graph with zoom and drag functionality</a> - - <div id="theme-drag-zoom-tree" class="reveal-modal xlarge" data-reveal> - <a class="close-reveal-modal">×</a> - </div> - -</div> - <script type="text/javascript"> - - // treeData = "" - // $.getJSON("{% url 'get_tree_hierarchy' group_id node.pk %}?collapsible=true", function(data){ treeData = data;}); - - // d3.json("{% url 'get_tree_hierarchy' group_id node.pk %}?collapsible=true", function(error, treeData) { function plotDragZoomTree(treeData) { - $("#theme-drag-zoom-tree").html(""); + // $("#theme-drag-zoom-tree").html(""); // Calculate total nodes, max label length var totalNodes = 0; @@ -38,7 +23,7 @@ // size of the diagram var viewerHeight = $(window).height() * 0.80; - var viewerWidth = $(document).width() * 0.90; + var viewerWidth = $(document).width() * 0.80; var tree = d3.layout.tree() @@ -165,6 +150,8 @@ .attr("width", viewerWidth) .attr("height", viewerHeight) .attr("class", "overlay") + .attr("version", "1.0") + .attr("xmlns", "http://www.w3.org/2000/svg") .call(zoomListener); // // Define the drag listeners for drag/drop behaviour of nodes. @@ -277,6 +264,25 @@ d._children = null; } } + + function getHierarchyIds(d) { + hierarchyIdsArr = [d.id]; + + while(d.parent) + { + hierarchyIdsArr.push(d.parent.id); + d = d.parent; + } + // currently treeData doesn't hold top-theme _id, + // so by default it's 1 in that place. Replace 1 with top theme's _id: + hierarchyIdsArr.pop(hierarchyIdsArr.indexOf(1)); + // hierarchyIdsArr.push("{{node.pk}}"); + + hierarchyIdsArr.reverse(); + // console.log(hierarchyIdsArr) + + return hierarchyIdsArr + } var overCircle = function(d) { selectedNode = d; @@ -322,7 +328,7 @@ scale = zoomListener.scale(); x = -source.y0; y = -source.x0; - x = x * scale + viewerWidth / 2; + x = x * scale + viewerWidth / 4; y = y * scale + viewerHeight / 2; d3.select('#theme-drag-zoom-tree g').transition() .duration(duration) @@ -344,13 +350,47 @@ } // Toggle children on click. - - function click(d) { - if (d3.event.defaultPrevented) return; // click suppressed - d = toggleChildren(d); - update(d); - centerNode(d); - } + + // Toggle children on click. + function click(d) { + if (d.children) { + d._children = d.children; + d.children = null; + console.log("non-leaf 1"); + } + else { + if(d._children){ + d.children = d._children; + d._children = null; + console.log("non-leaf 2"); + } + else if (d.node_type == "Topic"){ + console.log("Leaf!"); + + hierarchyIdsArr = getHierarchyIds(d); + + // alert("dddddd"); + // var a = document.createElement('a'); + // a.setAttribute('href', "/{{group_name_tag}}/topic_details/"+d.id+""); + // // a.setAttribute('target', '_blank'); + // document.body.appendChild(a); + // a.click(); + // a.remove(); + location.href = "/{{group_name_tag}}/topic_details/" + d.id + + "?nav_li=" + hierarchyIdsArr.toString() + ""; + // location.href = "/{{group_name_tag}}/topic_details/"+d.id+""; + // $('#collaps_topic_details').foundation('reveal', 'open'); + } + } + update(d); + } + + // function click(d) { + // if (d3.event.defaultPrevented) return; // click suppressed + // d = toggleChildren(d); + // update(d); + // centerNode(d); + // } function update(source) { // Compute the new height, function counts total children of root node and sets tree height accordingly. @@ -397,14 +437,18 @@ .attr("transform", function(d) { return "translate(" + source.y0 + "," + source.x0 + ")"; }) + .attr("data-coll-node-id", function(d) {return d.id || (d.id = ++i); }) + .style("cursor", "pointer") .on('click', click); - + nodeEnter.append("circle") .attr('class', 'nodeCircle') .attr("r", 0) .style("fill", function(d) { return d._children ? "lightsteelblue" : "#fff"; - }); + }) + .style("stroke-width", "1.5px") + .style("stroke", "steelblue"); nodeEnter.append("text") .attr("x", function(d) { @@ -418,21 +462,23 @@ .text(function(d) { return d.name; }) - .style("fill-opacity", 0); + .style("fill-opacity", 0) + .style("font-family", "sans-serif") + .style("font-size", "10px"); // phantom node to give us mouseover in a radius around it - nodeEnter.append("circle") - .attr('class', 'ghostCircle') - .attr("r", 30) - .attr("opacity", 0.2) // change this to zero to hide the target area - .style("fill", "red") - .attr('pointer-events', 'mouseover') - .on("mouseover", function(node) { - overCircle(node); - }) - .on("mouseout", function(node) { - outCircle(node); - }); + // nodeEnter.append("circle") + // .attr('class', 'ghostCircle') + // .attr("r", 30) + // .attr("opacity", 0.2) // change this to zero to hide the target area + // // .style("fill", "red") + // .attr('pointer-events', 'mouseover') + // .on("mouseover", function(node) { + // overCircle(node); + // }) + // .on("mouseout", function(node) { + // outCircle(node); + // }); // Update the text to reflect whether node has children or not. node.select('text') @@ -496,7 +542,10 @@ source: o, target: o }); - }); + }) + .style("stroke", "#ccc") + .style("stroke-width", "1.5px") + .style("fill", "none"); // Transition links to their new position. link.transition() @@ -530,12 +579,82 @@ // Define the root root = treeData; + aaa = root; root.x0 = viewerHeight / 2; root.y0 = 0; // Layout the tree initially and center on the root node. + // getData(root); root.children.forEach(collapse); update(root); centerNode(root); + + // recursive function needed to get data for {{selected}} node + // result = "" + // function getData (d) { + + // console.log("{{selected}} : " + d.name + " : " + d.id); + // if(d.id == "{{selected}}") + // { + // console.log("======================================================"); + // result = d + // } + + // if(d.children) + // { + // console.log(d.children) + // d.children.forEach(function(i){ + // res = getData(i); + // if (res) + // { + // return res + // } + // }) + // } + // else if(d._children) + // { + // console.log(d._children) + // d._children.forEach(function(i){ + // res = getData(i); + // if (res) + // { + // return res + // } + // }) + // } + // } + // console.log(getData(root)) } +// alert("{{selected}}"); +//called with every property and it's value + + + // selected = document.querySelector('[data-coll-node-id="{{selected}}"]'); + // selectedNodeData = d3.select(selected).data(); + // d = selectedNodeData[0]; + // hierarchyIdsArr = getHierarchyIds(d); + // console.log(hierarchyIdsArr); + + // while(d && d.parent) + // { + // console.log("11") + // click(d) + // d = d.parent; + // } + // function expandHierarchy(d) { + // console.log(d) + + // } + + // expandHierarchy(selectedNodeData[0]); + + function downloadCollapsibleGraph(filename) + { + var blob = new Blob([$("#theme-drag-zoom-tree").html()], {type: "image/svg+xml"}); + filename = filename.replace(/\ /g, '-'); + filename += "-Collapsible-Graph.svg"; + saveAs(blob, filename); + } + + </script> diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/registration/logout.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/registration/logout.html index 269f8f9..43f2eaa 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/registration/logout.html +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/registration/logout.html @@ -10,6 +10,9 @@ <div class="small-12 medium-10 large-10 columns end text-center"> <h3>{% trans "You have sucessfully logged out." %}</h3> <h5>{% trans "Thank you for visiting our website. Please return often to take advantage of this platform." %}</h5> + + <!-- after logout, show some upcoming ProgramEvents --> + </div> </div> </div> diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templatetags/ndf_tags.py b/gnowsys-ndf/gnowsys_ndf/ndf/templatetags/ndf_tags.py index 29f1c99..7c83db5 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templatetags/ndf_tags.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templatetags/ndf_tags.py @@ -5,6 +5,7 @@ from collections import OrderedDict from time import time import json import ox +import multiprocessing as mp ''' -- imports from installed packages -- ''' from django.contrib.auth.models import User @@ -125,6 +126,12 @@ def get_group_agency_types(): @get_execution_time @register.assignment_tag +def get_licence(): + return GSTUDIO_LICENCE + + +@get_execution_time +@register.assignment_tag def get_agency_type_of_group(group_id): ''' Getting agency_type value of the group. @@ -772,11 +779,10 @@ def thread_reply_count( oid ): global_thread_latest_reply["content_org"] = each.content_org global_thread_latest_reply["last_update"] = each.last_update global_thread_latest_reply["user"] = User.objects.get(pk=each.created_by).username - else: - if global_thread_latest_reply["last_update"] < each.last_update: - global_thread_latest_reply["content_org"] = each.content_org - global_thread_latest_reply["last_update"] = each.last_update - global_thread_latest_reply["user"] = User.objects.get(pk=each.created_by).username + elif global_thread_latest_reply["last_update"] < each.last_update: + global_thread_latest_reply["content_org"] = each.content_org + global_thread_latest_reply["last_update"] = each.last_update + global_thread_latest_reply["user"] = User.objects.get(pk=each.created_by).username thread_reply_count(each._id) @@ -1206,10 +1212,10 @@ def get_prior_node(node_id): if topic_GST._id in obj.member_of: if obj.prior_node: - for each in obj.prior_node: - node = node_collection.one({'_id': ObjectId(each) }) - prior.append(( node._id , node.name )) - + # for each in obj.prior_node: +# node = node_collection.one({'_id': ObjectId(each) }) + # prior.append(( node._id , node.name )) + prior=[(node_collection.one({'_id': ObjectId(each) })._id,node_collection.one({'_id': ObjectId(each) }).name) for each in obj.prior_node] return prior return prior @@ -2107,8 +2113,10 @@ def get_source_id(obj_id): @get_execution_time def get_translation_relation(obj_id, translation_list = [], r_list = []): get_translation_rt = node_collection.one({'$and':[{'_type':'RelationType'},{'name':u"translation_of"}]}) + r_list_append_temp=r_list.append #a temp. variable which stores the lookup for append method + translation_list_append_temp=translation_list.append#a temp. variable which stores the lookup if obj_id not in r_list: - r_list.append(obj_id) + r_list_append_temp(obj_id) node_sub_rt = triple_collection.find({'$and':[{'_type':"GRelation"},{'relation_type.$id':get_translation_rt._id},{'subject':obj_id}]}) node_rightsub_rt = triple_collection.find({'$and':[{'_type':"GRelation"},{'relation_type.$id':get_translation_rt._id},{'right_subject':obj_id}]}) @@ -2117,20 +2125,20 @@ def get_translation_relation(obj_id, translation_list = [], r_list = []): for each in list(node_sub_rt): right_subject = node_collection.one({'_id':each.right_subject}) if right_subject._id not in r_list: - r_list.append(right_subject._id) + r_list_append_temp(right_subject._id) if list(node_rightsub_rt): node_rightsub_rt.rewind() for each in list(node_rightsub_rt): right_subject = node_collection.one({'_id':each.subject}) if right_subject._id not in r_list: - r_list.append(right_subject._id) + r_list_append_temp(right_subject._id) if r_list: r_list.remove(obj_id) for each in r_list: dic={} node = node_collection.one({'_id':each}) dic[node._id]=node.language - translation_list.append(dic) + translation_list_append_temp(dic) get_translation_relation(each,translation_list, r_list) return translation_list diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/urls/user.py b/gnowsys-ndf/gnowsys_ndf/ndf/urls/user.py index 103025a..a916345 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/urls/user.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/urls/user.py @@ -8,4 +8,3 @@ urlpatterns = patterns('gnowsys_ndf.ndf.views.userDashboard', url(r'^useractivity', 'user_activity', name='user_activity'), url(r'^user_preference/(?P<auth_id>[\w-]+)$','user_preferences',name='user_preferences'), ) - diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py index 9ef16e0..cda0f41 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/ajax_views.py @@ -7,7 +7,7 @@ import time import ast import json import math -import multiprocessing +import multiprocessing ''' -- imports from installed packages -- ''' from django.http import HttpResponseRedirect @@ -637,7 +637,7 @@ def get_topic_contents(request, group_id): def get_collection_list(collection_list, node): inner_list = [] error_list = [] - + inner_list_append_temp=inner_list.append #a temp. variable which stores the lookup for append method if node.collection_set: for each in node.collection_set: col_obj = node_collection.one({'_id': ObjectId(each)}) @@ -651,9 +651,9 @@ def get_collection_list(collection_list, node): inner_sub_list = get_collection_list(inner_sub_list, col_obj) if inner_sub_list: - inner_list.append(inner_sub_list[0]) + inner_list_append_temp(inner_sub_list[0]) else: - inner_list.append(inner_sub_dict) + inner_list_append_temp(inner_sub_dict) cl.update({'children': inner_list }) else: @@ -723,7 +723,7 @@ def get_tree_hierarchy(request, group_id, node_id): def get_inner_collection(collection_list, node): inner_list = [] error_list = [] - + inner_list_append_temp=inner_list.append #a temp. variable which stores the lookup for append method if node.collection_set: for each in node.collection_set: col_obj = node_collection.one({'_id': ObjectId(each)}) @@ -736,9 +736,9 @@ def get_inner_collection(collection_list, node): inner_sub_list = get_inner_collection(inner_sub_list, col_obj) if inner_sub_list: - inner_list.append(inner_sub_list[0]) + inner_list_append_temp(inner_sub_list[0]) else: - inner_list.append(inner_sub_dict) + inner_list_append_temp(inner_sub_dict) cl.update({'children': inner_list }) else: @@ -750,27 +750,43 @@ def get_inner_collection(collection_list, node): else: return collection_list + @get_execution_time def get_collection(request, group_id, node_id): node = node_collection.one({'_id':ObjectId(node_id)}) # print "\nnode: ",node.name,"\n" collection_list = [] - - if node: - if node.collection_set: - for each in node.collection_set: - obj = node_collection.one({'_id': ObjectId(each) }) - if obj: - node_type = node_collection.one({'_id': ObjectId(obj.member_of[0])}).name - collection_list.append({'name': obj.name, 'id': obj.pk,'node_type': node_type}) - collection_list = get_inner_collection(collection_list, obj) - - + collection_list_append_temp=collection_list.append + + # def a(p,q,r): +# collection_list.append({'name': p, 'id': q,'node_type': r}) + #this empty list will have the Process objects as its elements + processes=[] + #Function used by Processes implemented below + def multi_(lst): + for each in lst: + obj = node_collection.one({'_id': ObjectId(each) }) + if obj: + node_type = node_collection.one({'_id': ObjectId(obj.member_of[0])}).name + collection_list_append_temp({'name':obj.name,'id':obj.pk,'node_type':node_type}) + collection_list = get_inner_collection(collection_list, obj) + #collection_list.append({'name':obj.name,'id':obj.pk,'node_type':node_type}) + + + if node and node.collection_set: + t=len(node.collection_set) + x=multiprocessing.cpu_count()#returns no of cores in the cpu + n2=t/x#divides the list into those many parts + #Process object is created.The list after being partioned is also given as an argument. + for i in range(x): + processes.append(multiprocessing.Process(target=multi_,args=(node.collection_set[i*n2:(i+1)*n2],))) + for i in range(x): + processes[i].start()#each Process started + for i in range(x): + processes[i].join()#each Process converges data = collection_list return HttpResponse(json.dumps(data)) -# ###End of manipulating nodes collection#### - @get_execution_time def add_sub_themes(request, group_id): if request.is_ajax() and request.method == "POST": @@ -1374,9 +1390,9 @@ def graph_nodes(request, group_id): node_metadata ='{"screen_name":"' + page_node.name + '", "title":"' + page_node.name + '", "_id":"'+ str(page_node._id) +'", "refType":"GSystem"}, ' node_relations = '' exception_items = [ - "name", "content", "_id", "login_required", "attribute_set", + "name", "content", "_id", "login_required", "attribute_set", "relation_set", "member_of", "status", "comment_enabled", "start_publication", - "_type", "contributors", "created_by", "modified_by", "last_update", "url", "featured", "relation_set", + "_type", "contributors", "created_by", "modified_by", "last_update", "url", "featured", "relation_set", "access_policy", "created_at", "group_set", "type_of", "content_org", "author_set", "fs_file_ids", "file_size", "mime_type", "location", "language", "property_order", "rating", "apps_list", "annotations", "instance of" @@ -3068,9 +3084,8 @@ def get_districts(request, group_id): }).sort('name', 1) if cur_districts.count(): - for d in cur_districts: - districts.append([str(d.subject), d.name.split(" -- ")[0]]) - + #loop replaced by a list comprehension + districts=[[str(d.subject), d.name.split(" -- ")[0]] for d in cur_districts] else: error_message = "No districts found" raise Exception(error_message) @@ -5402,6 +5417,9 @@ def page_scroll(request,group_id,page): page='1' if int(page) != int(tot_page) and int(page) != int(1): page=int(page)+1 + # temp. variables which stores the lookup for append method + user_activity_append_temp=user_activity.append + files_list_append_temp=files_list.append for each in (paged_resources.page(int(page))).object_list: if each.created_by == each.modified_by : if each.last_update == each.created_at: @@ -5412,9 +5430,9 @@ def page_scroll(request,group_id,page): activity = 'created' if each._type == 'Group': - user_activity.append(each) + user_activity_append_temp(each) each.update({'activity':activity}) - files_list.append(each) + files_list_append_temp(each) else: page=0 diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/course.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/course.py index 72e30ae..02a7f36 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/views/course.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/course.py @@ -98,7 +98,7 @@ def course(request, group_id, course_id=None): return render_to_response("ndf/course.html", {'title': title, - 'app_id': app_id, + 'app_id': app_id, 'course_gst': GST_COURSE, 'app_set_id': app_set_id, 'searching': True, 'course_coll': course_coll, 'groupid': group_id, 'group_id': group_id, diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/e-book.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/e-book.py index cef517a..1384560 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/views/e-book.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/e-book.py @@ -45,5 +45,6 @@ def ebook_listing(request, group_id, page_no=1): # context_instance=RequestContext(request) ) return render_to_response("ndf/ebook.html", - {"all_ebooks": all_ebooks, "group_id": group_id, "groupid": group_id}, + {"all_ebooks": all_ebooks, "ebook_gst": ebook_gst, + "group_id": group_id, "groupid": group_id}, context_instance = RequestContext(request)) diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/e-library.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/e-library.py index 56ffac3..5048302 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/views/e-library.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/e-library.py @@ -100,6 +100,7 @@ def resource_list(request, group_id, app_id=None, page_no=1): educationaluse_stats = {} + if files: eu_list = [] # count @@ -119,7 +120,6 @@ def resource_list(request, group_id, app_id=None, page_no=1): # print educationaluse_stats result_paginated_cur = files result_pages = paginator.Paginator(result_paginated_cur, page_no, no_of_objs_pp) - datavisual.append({"name":"Doc", "count": educationaluse_stats.get("Documents", 0)}) datavisual.append({"name":"Image","count": educationaluse_stats.get("Images", 0)}) datavisual.append({"name":"Video","count": educationaluse_stats.get("Videos", 0)}) @@ -130,7 +130,7 @@ def resource_list(request, group_id, app_id=None, page_no=1): return render_to_response("ndf/resource_list.html", {'title': title, - 'appId':app._id, + 'appId':app._id, "app_gst": app, # 'already_uploaded': already_uploaded,'shelf_list': shelf_list,'shelves': shelves, 'files': files, "detail_urlname": "file_detail", 'ebook_pages': educationaluse_stats.get("eBooks", 0), diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/file.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/file.py index 0ca7ece..b1c5d70 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/views/file.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/file.py @@ -7,10 +7,12 @@ import mimetypes import os import tempfile # import re +import ast import ox import pandora_client import threading -from PIL import Image, ImageDraw # install PIL example:pip install PIL + +from PIL import Image, ImageDraw from StringIO import StringIO ''' -- imports from installed packages -- ''' @@ -24,25 +26,24 @@ from django.core.files.storage import get_valid_filename from django.core.files.move import file_move_safe from django.core.files.temp import gettempdir from django.core.files.uploadedfile import UploadedFile # django file handler -# from django.contrib.auth.models import User +from django.contrib.auth.models import User +from django.contrib.sites.models import Site + from mongokit import paginator + from gnowsys_ndf.settings import GSTUDIO_SITE_VIDEO, EXTRA_LANG_INFO, GAPPS, MEDIA_ROOT, WETUBE_USERNAME, WETUBE_PASSWORD +from gnowsys_ndf.ndf.views.notify import set_notif_val from gnowsys_ndf.ndf.org2any import org2html -from gnowsys_ndf.ndf.views.methods import get_node_metadata, get_page, get_node_common_fields, set_all_urls,get_execution_time -from gnowsys_ndf.ndf.views.methods import get_group_name_id -from gnowsys_ndf.ndf.models import Node, GSystemType, File, GRelation, STATUS_CHOICES, Triple +from gnowsys_ndf.ndf.models import Node, GSystemType, File, GRelation, STATUS_CHOICES, Triple, node_collection, triple_collection, gridfs_collection +from gnowsys_ndf.ndf.views.methods import get_node_metadata, get_node_common_fields, create_gattribute, get_page, get_execution_time,set_all_urls,get_group_name_id # , get_page try: from bson import ObjectId except ImportError: # old pymongo from pymongo.objectid import ObjectId - from gnowsys_ndf.settings import GSTUDIO_SITE_VIDEO, MEDIA_ROOT, WETUBE_USERNAME, WETUBE_PASSWORD # , EXTRA_LANG_INFO, GAPPS -from gnowsys_ndf.ndf.models import node_collection, triple_collection, gridfs_collection -# from gnowsys_ndf.ndf.models import Node, GSystemType, File, GRelation, STATUS_CHOICES, Triple from gnowsys_ndf.ndf.org2any import org2html -from gnowsys_ndf.ndf.views.methods import get_node_metadata, get_node_common_fields, set_all_urls # , get_page -from gnowsys_ndf.ndf.views.methods import create_gattribute +from gnowsys_ndf.ndf.views.methods import get_node_metadata, get_node_common_fields, set_all_urls ,create_gattribute from gnowsys_ndf.ndf.views.moderation import create_moderator_task, get_moderator_group_set ############################################ @@ -51,16 +52,15 @@ GST_FILE = node_collection.one({'_type':'GSystemType', 'name': 'File'}) GST_IMAGE = node_collection.one({'_type':'GSystemType', 'name': 'Image'}) GST_VIDEO = node_collection.one({'_type':'GSystemType', 'name': 'Video'}) pandora_video_st = node_collection.one({'_type':'GSystemType', 'name':'Pandora_video'}) -app=GST_FILE - +app = GST_FILE -lock=threading.Lock() +lock = threading.Lock() count = 0 @get_execution_time def file(request, group_id, file_id=None, page_no=1): """ - * Renders a list of all 'Files' available within the database. + Renders a list of all 'Files' available within the database. """ ins_objectid = ObjectId() is_video = request.GET.get('is_video', "") @@ -84,7 +84,6 @@ def file(request, group_id, file_id=None, page_no=1): shelves = [] shelf_list = {} auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) }) - # if auth: # has_shelf_RT = node_collection.one({'_type': 'RelationType', 'name': u'has_shelf' }) # dbref_has_shelf = has_shelf_RT.get_dbref() @@ -278,7 +277,7 @@ def file(request, group_id, file_id=None, page_no=1): already_uploaded = request.GET.getlist('var', "") return render_to_response("ndf/file.html", {'title': title, - 'appId':app._id, + 'appId':app._id, "app_gst": app, 'searching': True, 'query': search_field, 'already_uploaded': already_uploaded,'shelf_list': shelf_list,'shelves': shelves, 'files': files, 'docCollection': docCollection, 'imageCollection': imageCollection, @@ -374,7 +373,7 @@ def file(request, group_id, file_id=None, page_no=1): datavisual = json.dumps(datavisual) return render_to_response("ndf/file.html", {'title': title, - 'appId':app._id, + 'appId':app._id, "app_gst": app, 'already_uploaded': already_uploaded,'shelf_list': shelf_list,'shelves': shelves, # 'sourceid':source_id_set, 'file_pages': file_pages, 'image_pages': images_pc.count(), @@ -656,7 +655,8 @@ def uploadDoc(request, group_id): if request.method == "GET": page_url = request.GET.get("next", "") - template = "ndf/UploadDoc.html" + # template = "ndf/UploadDoc.html" + template = "ndf/Uploader_Form.html" if page_url: variable = RequestContext(request, {'page_url': page_url,'groupid':group_id,'group_id':group_id}) else: @@ -671,19 +671,6 @@ def submitDoc(request, group_id): """ submit files for saving into gridfs and creating object """ - # ins_objectid = ObjectId() - # 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 : - # # print group_id - # pass try: group_id = ObjectId(group_id) @@ -691,6 +678,8 @@ def submitDoc(request, group_id): group_name, group_id = get_group_name_id(group_id) alreadyUploadedFiles = [] + #a temp. variable which stores the lookup for append method + alreadyUploadedFiles_append_temp=alreadyUploadedFiles.append str1 = '' img_type="" topic_file = "" @@ -708,25 +697,47 @@ def submitDoc(request, group_id): content_org = request.POST.get('content_org', '') access_policy = request.POST.get("login-mode", '') # To add access policy(public or private) to file object tags = request.POST.get('tags', "") + license = request.POST.get("License", "") + source = request.POST.get("Source", "") + Audience = request.POST.get("audience", "") + fileType = request.POST.get("FileType", "") + subject = request.POST.get("Subject", "") + level = request.POST.get("Level", "") + Based_url = request.POST.get("based_url", "") + map_geojson_data = request.POST.get('map-geojson-data') + + if map_geojson_data: + map_geojson_data = map_geojson_data + "," + map_geojson_data = list(ast.literal_eval(map_geojson_data)) + else: + map_geojson_data = [] + i = 1 for index, each in enumerate(request.FILES.getlist("doc[]", "")): if mtitle: if index == 0: - f, is_video = save_file(each, mtitle, userid, group_id, content_org, tags, img_type, language, usrname, access_policy, oid=True) + # f, is_video = save_file(each, mtitle, userid, group_id, content_org, tags, img_type, language, usrname, access_policy, oid=True) + + f, is_video = save_file(each, mtitle, userid, group_id, content_org, tags, img_type, language, usrname, access_policy, license, source, Audience, fileType, subject, level, Based_url, request, map_geojson_data, oid=True) + else: title = mtitle + "_" + str(i) #increament title - f, is_video = save_file(each, title, userid, group_id, content_org, tags, img_type, language, usrname, access_policy, oid=True) + f, is_video = save_file(each, title, userid, group_id, content_org, tags, img_type, language, usrname, access_policy, license, source, Audience, fileType, subject, level, Based_url, request, map_geojson_data, oid=True) i = i + 1 else: title = each.name - f, is_video = save_file(each,title,userid,group_id, content_org, tags, img_type, language, usrname, access_policy) + + # f, is_video = save_file(each,title,userid,group_id, content_org, tags, img_type, language, usrname, access_policy) # print "f: ", f # if not obj_id_instance.is_valid(f): # check if file is already uploaded file + # if isinstance(f, list): + f = save_file(each,title,userid,group_id, content_org, tags, img_type, language, usrname, access_policy, license, source, Audience, fileType, subject, level, Based_url, request, map_geojson_data, oid=True) + if isinstance(f, list): - alreadyUploadedFiles.append(f) + alreadyUploadedFiles_append_temp(f) title = mtitle # str1 = alreadyUploadedFiles @@ -775,7 +786,7 @@ def submitDoc(request, group_id): first_object = '' @get_execution_time -def save_file(files,title, userid, group_id, content_org, tags, img_type = None, language = None, usrname = None, access_policy=None, **kwargs): +def save_file(files,title, userid, group_id, content_org, tags, img_type = None, language = None, usrname = None, access_policy=None, license=None, source=None, Audience=None, fileType=None, subject=None, level=None, Based_url=None, request=None, map_geojson_data=[], **kwargs): """ this will create file object and save files in gridfs collection """ @@ -853,6 +864,15 @@ def save_file(files,title, userid, group_id, content_org, tags, img_type = None, 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) + # Commented bellow code to avoid redundancy (this will be removed once testing done) + # if group_object._id not in fileobj.group_set: + # 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}]}) + # if user_group_object: + # 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 fileobj.url = set_all_urls(fileobj.member_of) @@ -867,8 +887,45 @@ def save_file(files,title, userid, group_id, content_org, tags, img_type = None, if not type(tags) is list: tags = [unicode(t.strip()) for t in tags.split(",") if t != ""] fileobj.tags = tags + + # new fields added + fileobj.license = unicode(license) + + fileobj.location = map_geojson_data + + fileobj.save() + if source: + # create gattribute for file with source value + source_AT = node_collection.one({'_type':'AttributeType','name':'source'}) + src = create_gattribute(fileobj._id, source_AT, source) + + if Audience: + # create gattribute for file with Audience value + audience_AT = node_collection.one({'_type':'AttributeType','name':'audience'}) + aud = create_gattribute(fileobj._id, audience_AT, Audience) + + if fileType: + # create gattribute for file with 'educationaluse' value + educationaluse_AT = node_collection.one({'_type':'AttributeType', 'name': 'educationaluse'}) + FType = create_gattribute(fileobj._id, educationaluse_AT, fileType) + + if subject: + # create gattribute for file with 'educationaluse' value + subject_AT = node_collection.one({'_type':'AttributeType', 'name': 'educationalsubject'}) + sub = create_gattribute(fileobj._id, subject_AT, subject) + + if level: + # create gattribute for file with 'educationaluse' value + educationallevel_AT = node_collection.one({'_type':'AttributeType', 'name': 'educationallevel'}) + edu_level = create_gattribute(fileobj._id, educationallevel_AT, level) + + if Based_url: + # create gattribute for file with 'educationaluse' value + basedonurl_AT = node_collection.one({'_type':'AttributeType', 'name': 'basedonurl'}) + basedUrl = create_gattribute(fileobj._id, basedonurl_AT, Based_url) + 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}}) @@ -955,11 +1012,13 @@ def save_file(files,title, userid, group_id, content_org, tags, img_type = None, 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}}) count = count + 1 - # print "----- fileobj._id", fileobj._id + return fileobj._id, is_video + except Exception as e: print "Some Exception:", files.name, "Execption:", e + @get_execution_time def getFileSize(File): """ @@ -975,6 +1034,8 @@ def getFileSize(File): except Exception as e: print "Unabe to calucalate size",e return 0,'bytes' + + @get_execution_time def convert_image_thumbnail(files): """ @@ -988,6 +1049,8 @@ def convert_image_thumbnail(files): img.save(thumb_io, "JPEG") thumb_io.seek(0) return thumb_io + + @get_execution_time def convert_pdf_thumbnail(files,_id): ''' @@ -1003,6 +1066,7 @@ def convert_pdf_thumbnail(files,_id): thumb_pdf = open("/tmp/"+filename+"/"+filename+"-thumbnail.png", 'r') return thumb_pdf + @get_execution_time def convert_mid_size_image(files, **kwargs): """ @@ -1036,7 +1100,6 @@ def convert_mid_size_image(files, **kwargs): mid_size_img.seek(0) return mid_size_img - def convertVideo(files, userid, fileobj, filename): @@ -1098,6 +1161,7 @@ def convertVideo(files, userid, fileobj, filename): node_collection.find_and_modify({'_id':fileobj._id},{'$push':{'fs_file_ids':tobjectid}}) + @get_execution_time def GetDoc(request, group_id): ins_objectid = ObjectId() @@ -1118,6 +1182,7 @@ def GetDoc(request, group_id): variable = RequestContext(request, {'filecollection':files,'groupid':group_id,'group_id':group_id}) return render_to_response(template, variable) + @get_execution_time def file_search(request, group_id): ins_objectid = ObjectId() @@ -1139,6 +1204,7 @@ def file_search(request, group_id): variable = RequestContext(request, {'file_collection':file_search, 'view_name':'file_search','groupid':group_id,'group_id':group_id}) return render_to_response(template, variable) + @login_required @get_execution_time def delete_file(request, group_id, _id): @@ -1171,6 +1237,7 @@ def delete_file(request, group_id, _id): print "Exception:", e return HttpResponseRedirect(pageurl) + @get_execution_time def file_detail(request, group_id, _id): """Depending upon mime-type of the node, this view returns respective display-view. @@ -1245,16 +1312,19 @@ def file_detail(request, group_id, _id): if auth: has_shelf_RT = node_collection.one({'_type': 'RelationType', 'name': u'has_shelf' }) shelf = triple_collection.find({'_type': 'GRelation', 'subject': ObjectId(auth._id), 'relation_type.$id': has_shelf_RT._id }) - + #a temp. variable which stores the lookup for append method + shelves_append_temp=shelves.append if shelf: for each in shelf: shelf_name = node_collection.one({'_id': ObjectId(each.right_subject)}) - shelves.append(shelf_name) + shelves_append_temp(shelf_name) - shelf_list[shelf_name.name] = [] + shelf_list[shelf_name.name] = [] + #a temp. variable which stores the lookup for append method + shelf_list_shelfname_append_temp=shelf_list[shelf_name.name].append for ID in shelf_name.collection_set: shelf_item = node_collection.one({'_id': ObjectId(ID) }) - shelf_list[shelf_name.name].append(shelf_item.name) + shelf_list_shelfname_append_temp(shelf_item.name) else: shelves = [] @@ -1272,6 +1342,8 @@ def file_detail(request, group_id, _id): }, context_instance = RequestContext(request) ) + + @get_execution_time def getFileThumbnail(request, group_id, _id): """Returns thumbnail of respective file @@ -1282,10 +1354,8 @@ def getFileThumbnail(request, group_id, _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) + elif auth: + group_id = str(auth._id) else: pass @@ -1294,8 +1364,11 @@ def getFileThumbnail(request, group_id, _id): if file_node is not None: if file_node.fs_file_ids: # getting latest uploaded pic's _id - file_fs = file_node.fs_file_ids[2] + file_fs = "" + if len(file_node.fs_file_ids) > 1: + file_fs = file_node.fs_file_ids[2] + if (file_node.fs.files.exists(file_fs)): if len(file_node.fs_file_ids) > 0: @@ -1366,6 +1439,8 @@ def readDoc(request, _id, group_id, file_name=""): return HttpResponse("") else: return HttpResponse("") + + @get_execution_time def file_edit(request,group_id,_id): ins_objectid = ObjectId() diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/group.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/group.py index 97a6915..7f0106c 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/views/group.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/group.py @@ -1165,8 +1165,8 @@ def group(request, group_id, app_id=None, agency_type=None): }).sort('last_update', -1) if cur_groups_user.count(): - for group in cur_groups_user: - group_nodes.append(group) + #loop replaced by a list comprehension + group_nodes=[group for group in cur_groups_user] group_count = cur_groups_user.count() @@ -1184,14 +1184,13 @@ def group(request, group_id, app_id=None, agency_type=None): }).sort('last_update', -1) if cur_public.count(): - for group in cur_public: - group_nodes.append(group) - + #loop replaced by a list comprehension + group_nodes=[group for group in cur_public] group_count = cur_public.count() return render_to_response("ndf/group.html", {'title': title, - 'appId':app._id, + 'appId':app._id, 'app_gst': group_gst, 'searching': True, 'query': search_field, 'group_nodes': group_nodes, 'group_nodes_count': group_count, 'groupid':group_id, 'group_id':group_id @@ -1241,7 +1240,7 @@ def group(request, group_id, app_id=None, agency_type=None): return render_to_response("ndf/group.html", {'group_nodes': group_nodes, - 'appId':app._id, + 'appId':app._id, 'app_gst': group_gst, 'group_nodes_count': group_count, 'groupid': group_id, 'group_id': group_id }, context_instance=RequestContext(request)) @@ -1399,14 +1398,18 @@ def group_dashboard(request, group_id=None): shelf_list = {} if shelf: + #a temp. variable which stores the lookup for append method + shelves_append_temp=shelves.append for each in shelf: shelf_name = node_collection.one({'_id': ObjectId(each.right_subject)}) - shelves.append(shelf_name) + shelves_append_temp(shelf_name) shelf_list[shelf_name.name] = [] + #a temp. variable which stores the lookup for append method + shelf_lst_shelfname_append=shelf_list[shelf_name.name].append for ID in shelf_name.collection_set: shelf_item = node_collection.one({'_id': ObjectId(ID) }) - shelf_list[shelf_name.name].append(shelf_item.name) + shelf_lst_shelfname_append(shelf_item.name) else: shelves = [] @@ -1436,7 +1439,7 @@ def group_dashboard(request, group_id=None): return render_to_response([alternate_template,default_template] ,{'node': group_obj, 'groupid':group_id, 'group_id':group_id, 'user':request.user, 'shelf_list': shelf_list, - 'appId':app._id, + 'appId':app._id, 'app_gst': group_gst, 'annotations' : annotations, 'shelves': shelves, 'prof_pic_obj': profile_pic_image },context_instance=RequestContext(request) @@ -1615,7 +1618,8 @@ def switch_group(request,group_id,node_id): resource_exists = False resource_exists_in_grps = [] response_dict = {'success': False, 'message': ""} - + #a temp. variable which stores the lookup for append method + resource_exists_in_grps_append_temp=resource_exists_in_grps.append new_grps_list_distinct = [ObjectId(item) for item in new_grps_list if ObjectId(item) not in existing_grps] if new_grps_list_distinct: for each_new_grp in new_grps_list_distinct: @@ -1623,7 +1627,7 @@ def switch_group(request,group_id,node_id): grp = node_collection.find({'name': node.name, "group_set": ObjectId(each_new_grp), "member_of":ObjectId(node.member_of[0])}) if grp.count() > 0: resource_exists = True - resource_exists_in_grps.append(unicode(each_new_grp)) + resource_exists_in_grps_append_temp(unicode(each_new_grp)) response_dict["resource_exists_in_grps"] = resource_exists_in_grps @@ -1649,11 +1653,15 @@ def switch_group(request,group_id,node_id): data_list = [] user_id = request.user.id all_user_groups = [] - for each in get_all_user_groups(): - all_user_groups.append(each.name) + # for each in get_all_user_groups(): + # all_user_groups.append(each.name) + #loop replaced by a list comprehension + all_user_groups=[each.name for each in get_all_user_groups()] st = node_collection.find({'$and': [{'_type': 'Group'}, {'author_set': {'$in':[user_id]}},{'name':{'$nin':all_user_groups}}]}) - for each in node.group_set: - coll_obj_list.append(node_collection.one({'_id': each})) + # for each in node.group_set: + # coll_obj_list.append(node_collection.one({'_id': each})) + #loop replaced by a list comprehension + coll_obj_list=[node_collection.one({'_id': each}) for each in node.group_set ] data_list = set_drawer_widget(st, coll_obj_list) return HttpResponse(json.dumps(data_list)) diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/methods.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/methods.py index 2f983e2..d125264 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/views/methods.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/methods.py @@ -34,11 +34,11 @@ import ast import string import json import locale +import multiprocessing as mp from datetime import datetime, timedelta, date # import csv # from collections import Counter from collections import OrderedDict - col = db[Benchmark.collection_name] history_manager = HistoryManager() @@ -227,12 +227,28 @@ def get_gapps(default_gapp_listing=False, already_selected_gapps=[]): # Then append their names in list of GApps to be excluded if already_selected_gapps: gapps_list_remove = gapps_list.remove - for each_gapp in already_selected_gapps: + #Function used by Processes implemented below + def multi_(lst): + for each_gapp in lst: gapp_name = each_gapp["name"] if gapp_name in gapps_list: gapps_list_remove(gapp_name) - + #this empty list will have the Process objects as its elements + processes=[] + n1=len(already_selected_gapps) + lst1=already_selected_gapps + #returns no of cores in the cpu + x=mp.cpu_count() + #divides the list into those many parts + n2=n1/x + #Process object is created.The list after being partioned is also given as an argument. + for i in range(x): + processes.append(mp.Process(target=multi_,args=(lst1[i*n2:(i+1)*n2],))) + for i in range(x): + processes[i].start() #each Process started + for i in range(x): + processes[i].join() #each Process converges # Find all GAPPs meta_type = node_collection.one({ "_type": "MetaType", "name": META_TYPE[0] @@ -488,6 +504,10 @@ def get_drawers(group_id, nid=None, nlist=[], page_no=1, checked=None, **kwargs) if each._id not in nlist: dict1[each._id] = each + #loop replaced by a list comprehension + dict2=[node_collection.one({'_id': oid}) for oid in nlist] + + for oid in nlist: obj = node_collection.one({'_id': oid}) dict2.append(obj) @@ -501,10 +521,15 @@ def get_drawers(group_id, nid=None, nlist=[], page_no=1, checked=None, **kwargs) if each._id != nid: if each._id not in nlist: dict1[each._id] = each + #loop replaced by a list comprehension + dict2=[node_collection.one({'_id': oid}) for oid in nlist] - for oid in nlist: + + for oid in nlist: obj = node_collection.one({'_id': oid}) dict2.append(obj) + + dict_drawer['1'] = dict1 dict_drawer['2'] = dict2 @@ -746,7 +771,6 @@ def get_node_common_fields(request, node, group_id, node_type, coll_set=None): node.tags = tags_list is_changed = True - # Build collection, prior node, teaches and assesses lists if check_collection: changed = build_collection(node, check_collection, right_drawer_list, checked) @@ -813,11 +837,12 @@ def build_collection(node, check_collection, right_drawer_list, checked): if node.prior_node != right_drawer_list: i = 0 node.prior_node=[] + node_prior_node_append_temp=node.prior_node.append #a temp. variable which stores the lookup for append method while (i < len(right_drawer_list)): node_id = ObjectId(right_drawer_list[i]) node_obj = node_collection.one({"_id": node_id}) if node_obj: - node.prior_node.append(node_id) + node_prior_node_append_temp(node_id) i = i+1 # print "\n Changed: prior_node" @@ -838,14 +863,16 @@ def build_collection(node, check_collection, right_drawer_list, checked): i = 0 node.collection_set = [] # checking if each _id in collection_list is valid or not + nlist_append_temp=nlist.append #a temp. variable which stores the lookup for append method + node_collection_set_append_temp=node.collection_set.append #a temp. variable which stores the lookup for append method while (i < len(right_drawer_list)): node_id = ObjectId(right_drawer_list[i]) node_obj = node_collection.one({"_id": node_id}) if node_obj: if node_id not in nlist: - nlist.append(node_id) + nlist_append_temp(node_id) else: - node.collection_set.append(node_id) + node_collection_set_append_temp(node_id) # After adding it to collection_set also make the 'node' as prior node for added collection element node_collection.collection.update({'_id': ObjectId(node_id), 'prior_node': {'$nin':[node._id]} },{'$push': {'prior_node': ObjectId(node._id)}}) @@ -853,7 +880,7 @@ def build_collection(node, check_collection, right_drawer_list, checked): for each in nlist: if each not in node.collection_set: - node.collection_set.append(each) + node_collection_set_append_temp(each) node.status = u"PUBLISHED" node.save() # After adding it to collection_set also make the 'node' as prior node for added collection element @@ -1030,7 +1057,7 @@ def build_collection(node, check_collection, right_drawer_list, checked): else: return False - +""" @get_execution_time def get_versioned_page(node): rcs = RCS() @@ -1048,7 +1075,7 @@ def get_versioned_page(node): if line.find('status')!=-1: up_ind=line.find('status') if line.find(('PUBLISHED'),up_ind) !=-1: - rev_no=rev_no.split()[0] + rev_no=rev_no.split()[0] node=history_manager.get_version_document(node,rev_no) proc1.kill() return (node,rev_no) @@ -1056,7 +1083,33 @@ def get_versioned_page(node): node=history_manager.get_version_document(node,'1.1') proc1.kill() return(node,'1.1') +""" +@get_execution_time +def get_versioned_page(node): + rcs = RCS() + fp = history_manager.get_file_path(node) + cmd= 'rlog %s' % \ + (fp) + rev_no ="" + proc1=subprocess.Popen(cmd,shell=True, + stdout=subprocess.PIPE) + for line in iter(proc1.stdout.readline,b''): + if line.find('revision')!=-1 and line.find('selected') == -1: + rev_no=string.split(line,'revision') + rev_no=rev_no[1].strip( '\t\n\r') + rev_no=rev_no.split()[0] + if line.find('status')!=-1: + up_ind=line.find('status') + if line.find(('PUBLISHED'),up_ind) !=-1: + rev_no=rev_no.split()[0] + node=history_manager.get_version_document(node,rev_no) + proc1.kill() + return (node,rev_no) + if rev_no == '1.1': + node=history_manager.get_version_document(node,'1.1') + proc1.kill() + return(node,'1.1') @get_execution_time @@ -1191,8 +1244,8 @@ def tag_info(request, group_id, tagname=None): cur = node_collection.find({'tags': {'$regex': tagname, '$options': "i"}, 'group_set':ObjectId(group_id) }) - for every in cur: - search_result.append(every) + #loop replaced by a list comprehension + search_result=[every for every in cur] # Autheticate user can see all public files elif request.user.is_authenticated(): @@ -1214,8 +1267,8 @@ def tag_info(request, group_id, tagname=None): {'created_by': userid}, ] }) - for every in cur: - search_result.append(every) + #loop replaced by a list comprehension + search_result=[every for every in cur] else: # Unauthenticated user can see all public files. group_node = node_collection.one({'_id': ObjectId(group_id)}) @@ -1226,8 +1279,8 @@ def tag_info(request, group_id, tagname=None): 'status': u'PUBLISHED' } ) - for every in cur: - search_result.append(every) + #loop replaced by a list comprehension + search_result=[every for every in cur] if search_result: total = len(search_result) @@ -1457,18 +1510,22 @@ def get_widget_built_up_data(at_rt_objectid_or_attr_name_list, node, type_of_set """ if not isinstance(at_rt_objectid_or_attr_name_list, list): at_rt_objectid_or_attr_name_list = [at_rt_objectid_or_attr_name_list] - + #a temp. variable which stores the lookup for append method + type_of_set_append_temp=type_of_set.append if not type_of_set: node["property_order"] = [] + #a temp. variable which stores the lookup for append method + node_property_order_append_temp=node["property_order"].append gst_nodes = node_collection.find({'_type': "GSystemType", '_id': {'$in': node["member_of"]}}, {'type_of': 1, 'property_order': 1}) for gst in gst_nodes: for type_of in gst["type_of"]: if type_of not in type_of_set: - type_of_set.append(type_of) + type_of_set_append_temp(type_of) for po in gst["property_order"]: if po not in node["property_order"]: - node["property_order"].append(po) + node_property_order_append_temp(po) + BASE_FIELD_METADATA = { 'name': {'name': "name", '_type': "BaseField", 'altnames': "Name", 'required': True}, @@ -1480,6 +1537,8 @@ def get_widget_built_up_data(at_rt_objectid_or_attr_name_list, node, type_of_set } widget_data_list = [] + #a temp. variable which stores the lookup for append method + widget_data_list_append_temp=widget_data_list.append for at_rt_objectid_or_attr_name in at_rt_objectid_or_attr_name_list: if type(at_rt_objectid_or_attr_name) == ObjectId: #ObjectId.is_valid(at_rt_objectid_or_attr_name): # For attribute-field(s) and/or relation-field(s) @@ -1539,7 +1598,7 @@ def get_widget_built_up_data(at_rt_objectid_or_attr_name_list, node, type_of_set data_type = node.structure[field.name] value = node[field.name] - widget_data_list.append({ '_type': field._type, # It's only use on details-view template; overridden in ndf_tags html_widget() + widget_data_list_append_temp({ '_type': field._type, # It's only use on details-view template; overridden in ndf_tags html_widget() '_id': field._id, 'data_type': data_type, 'name': field.name, 'altnames': altnames, @@ -1550,7 +1609,7 @@ def get_widget_built_up_data(at_rt_objectid_or_attr_name_list, node, type_of_set # For node's base-field(s) # widget_data_list.append([node['member_of'], BASE_FIELD_METADATA[at_rt_objectid_or_attr_name], node[at_rt_objectid_or_attr_name]]) - widget_data_list.append({ '_type': BASE_FIELD_METADATA[at_rt_objectid_or_attr_name]['_type'], + widget_data_list_append_temp({ '_type': BASE_FIELD_METADATA[at_rt_objectid_or_attr_name]['_type'], 'data_type': node.structure[at_rt_objectid_or_attr_name], 'name': at_rt_objectid_or_attr_name, 'altnames': BASE_FIELD_METADATA[at_rt_objectid_or_attr_name]['altnames'], 'value': node[at_rt_objectid_or_attr_name], @@ -1578,21 +1637,25 @@ def get_property_order_with_value(node): demo["property_order"] = [] type_of_set = [] + #temp. variables which stores the lookup for append method + type_of_set_append_temp=type_of_set.append + demo_prop_append_temp=demo["property_order"].append gst_nodes = node_collection.find({'_type': "GSystemType", '_id': {'$in': demo["member_of"]}}, {'type_of': 1, 'property_order': 1}) for gst in gst_nodes: for type_of in gst["type_of"]: if type_of not in type_of_set: - type_of_set.append(type_of) + type_of_set_append_temp(type_of) for po in gst["property_order"]: if po not in demo["property_order"]: - demo["property_order"].append(po) + demo_prop_append_temp(po) demo.get_neighbourhood(node["member_of"]) - + #a temp. variable which stores the lookup for append method + new_property_order_append_temp=new_property_order.append for tab_name, list_field_id_or_name in demo['property_order']: list_field_set = get_widget_built_up_data(list_field_id_or_name, demo, type_of_set) - new_property_order.append([tab_name, list_field_set]) + new_property_order_append_temp([tab_name, list_field_set]) demo["property_order"] = new_property_order @@ -1603,9 +1666,11 @@ def get_property_order_with_value(node): if type_of_nodes.count(): demo["property_order"] = [] + #a temp. variable which stores the lookup for append method + demo_prop_append_temp=demo["property_order"].append for to in type_of_nodes: for po in to["property_order"]: - demo["property_order"].append(po) + demo_prop_append_temp(po) node_collection.collection.update({'_id': demo._id}, {'$set': {'property_order': demo["property_order"]}}, upsert=False, multi=False) diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/mis.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/mis.py index 3b4e149..ebf9708 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/views/mis.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/mis.py @@ -3,6 +3,7 @@ import os import ast # from datetime import datetime import datetime +import multiprocessing as mp ''' -- imports from installed packages -- ''' from django.http import HttpResponseRedirect @@ -96,8 +97,13 @@ def mis_detail(request, group_id, app_id=None, app_set_id=None, app_set_instance agency_type = auth.agency_type agency_type_node = node_collection.one({'_type': "GSystemType", 'name': agency_type}, {'collection_set': 1}) if agency_type_node: - for eachset in agency_type_node.collection_set: - app_collection_set.append(node_collection.one({"_id": eachset}, {'_id': 1, 'name': 1, 'type_of': 1})) + #b=app_collection_set.append + #for eachset in agency_type_node.collection_set: + # b(a({"_id": eachset}, {'_id': 1, 'name': 1, 'type_of': 1})) + + # loop replaced by a list comprehension + app_collection_set=[node_collection.one({"_id": eachset}, {'_id': 1, 'name': 1, 'type_of': 1}) for eachset in agency_type_node.collection_set] + # for eachset in app.collection_set: # app_collection_set.append(node_collection.one({"_id":eachset}, {'_id': 1, 'name': 1, 'type_of': 1})) @@ -196,18 +202,24 @@ def mis_detail(request, group_id, app_id=None, app_set_id=None, app_set_instance systemtype_relationtype_set = [] system = node_collection.find_one({"_id":ObjectId(app_set_instance_id)}) systemtype = node_collection.find_one({"_id":ObjectId(app_set_id)}) - for each in systemtype.attribute_type_set: - systemtype_attributetype_set.append({"type":each.name,"type_id":str(each._id),"value":each.data_type}) - for each in systemtype.relation_type_set: - systemtype_relationtype_set.append({"rt_name":each.name,"type_id":str(each._id)}) - + #for each in systemtype.attribute_type_set: + # systemtype_attributetype_set.append({"type":each.name,"type_id":str(each._id),"value":each.data_type}) + #loop replaced by a list comprehension + systemtype_attributetype_set=[{"type":each.name,"type_id":str(each._id),"value":each.data_type} for each in systemtype.attribute_type_set] + #for each in systemtype.relation_type_set: + # systemtype_relationtype_set.append({"rt_name":each.name,"type_id":str(each._id)}) + #loop replaced by a list comprehension + systemtype_relationtype_set=[{"rt_name":each.name,"type_id":str(each._id)} for each in systemtype.relation_type_set] + #temp. variables which stores the lookup for append method + atlist_append_temp=atlist.append + rtlist_append_temp=rtlist.append for eachatset in systemtype_attributetype_set : for eachattribute in triple_collection.find({"_type":"GAttribute", "subject":system._id, "attribute_type.$id":ObjectId(eachatset["type_id"])}): - atlist.append({"type":eachatset["type"],"type_id":eachatset["type_id"],"value":eachattribute.object_value}) + atlist_append_temp({"type":eachatset["type"],"type_id":eachatset["type_id"],"value":eachattribute.object_value}) for eachrtset in systemtype_relationtype_set : for eachrelation in triple_collection.find({"_type":"GRelation", "subject":system._id, "relation_type.$id":ObjectId(eachrtset["type_id"])}): right_subject = node_collection.find_one({"_id":ObjectId(eachrelation.right_subject)}) - rtlist.append({"type":eachrtset["rt_name"],"type_id":eachrtset["type_id"],"value_name": right_subject.name,"value_id":str(right_subject._id)}) + rtlist_append_temp({"type":eachrtset["rt_name"],"type_id":eachrtset["type_id"],"value_name": right_subject.name,"value_id":str(right_subject._id)}) # To support consistent view @@ -215,10 +227,10 @@ def mis_detail(request, group_id, app_id=None, app_set_id=None, app_set_instance system.get_neighbourhood(systemtype._id) # array of dict for events --------------------- - + #a temp. variable which stores the lookup for append method + events_arr_append_temp=events_arr.append # if system.has_key('organiser_of_event') and len(system.organiser_of_event): # gives list of events if 'organiser_of_event' in system and len(system.organiser_of_event): # gives list of events - for event in system.organiser_of_event: event.get_neighbourhood(event.member_of) @@ -236,7 +248,7 @@ def mis_detail(request, group_id, app_id=None, app_set_id=None, app_set_instance dt = event.end_time.strftime('%m/%d/%Y %H:%M') tempdict['end'] = dt tempdict['id'] = str(event._id) - events_arr.append(tempdict) + events_arr_append_temp(tempdict) # elif system.has_key('event_organised_by'): # gives list of colleges/host of events elif 'event_organised_by' in system: # gives list of colleges/host of events @@ -257,24 +269,27 @@ def mis_detail(request, group_id, app_id=None, app_set_id=None, app_set_instance tempdict['end'] = dt tempdict['id'] = str(host._id) - events_arr.append(tempdict) + events_arr_append_temp(tempdict) # print json.dumps(events_arr) # END --- array of dict for events --------------------- - + #a temp. variable which stores the lookup for append method + property_display_order_append_temp=property_display_order.append for tab_name, fields_order in property_order: display_fields = [] + #a temp. variable which stores the lookup for append method + display_fields_append_temp=display_fields.append for field, altname in fields_order: if system.structure[field] == bool: - display_fields.append((altname, ("Yes" if system[field] else "No"))) + display_fields_append_temp((altname, ("Yes" if system[field] else "No"))) elif not system[field]: - display_fields.append((altname, system[field])) + display_fields_append_temp((altname, system[field])) continue elif system.structure[field] == datetime.datetime: - display_fields.append((altname, system[field].date())) + display_fields_append_temp((altname, system[field].date())) elif type(system.structure[field]) == list: if system[field]: @@ -282,19 +297,20 @@ def mis_detail(request, group_id, app_id=None, app_set_id=None, app_set_instance name_list = [] for right_sub_dict in system[field]: name_list.append(right_sub_dict.name) - display_fields.append((altname, ", ".join(name_list))) + display_fields_append_temp((altname, ", ".join(name_list))) elif system.structure[field][0] == datetime.datetime: date_list = [] - for dt in system[field]: - date_list.append(dt.strftime("%d/%m/%Y")) - display_fields.append((altname, ", ".join(date_list))) + #for dt in system[field]: + # date_list.append(dt.strftime("%d/%m/%Y")) + date_list=[dt.strftime("%d/%m/%Y") for dt in system[field]] + display_fields_append_temp((altname, ", ".join(date_list))) else: - display_fields.append((altname, ", ".join(system[field]))) + display_fields_append_temp((altname, ", ".join(system[field]))) else: - display_fields.append((altname, system[field])) + display_fields_append_temp((altname, system[field])) - property_display_order.append((tab_name, display_fields)) + property_display_order_append_temp((tab_name, display_fields)) # End of code @@ -396,9 +412,11 @@ def mis_create_edit(request, group_id, app_id, app_set_id=None, app_set_instance agency_type = auth.agency_type agency_type_node = node_collection.one({'_type': "GSystemType", 'name': agency_type}, {'collection_set': 1}) if agency_type_node: - for eachset in agency_type_node.collection_set: - app_collection_set.append(node_collection.one({"_id": eachset}, {'_id': 1, 'name': 1, 'type_of': 1})) + # for eachset in agency_type_node.collection_set: + # app_collection_set.append(node_collection.one({"_id": eachset}, {'_id': 1, 'name': 1, 'type_of': 1})) + #loop replaced by a list comprehension + app_collection_set=[node_collection.one({"_id": eachset}, {'_id': 1, 'name': 1, 'type_of': 1}) for eachset in agency_type_node.collection_set] # for eachset in app.collection_set: # app_collection_set.append(node_collection.one({"_id":eachset}, {'_id': 1, 'name': 1, 'type_of': 1})) # app_set = node_collection.find_one({"_id":eachset}) @@ -434,16 +452,22 @@ def mis_create_edit(request, group_id, app_id, app_set_id=None, app_set_instance systemtype = node_collection.find_one({"_id":ObjectId(app_set_id)}) systemtype_name = systemtype.name title = systemtype_name + " - new" - for each in systemtype.attribute_type_set: - systemtype_attributetype_set.append({"type":each.name,"type_id":str(each._id),"value":each.data_type, 'sub_values': each.complex_data_type, 'altnames': each.altnames}) + # for each in systemtype.attribute_type_set: + # systemtype_attributetype_set.append({"type":each.name,"type_id":str(each._id),"value":each.data_type, 'sub_values': each.complex_data_type, 'altnames': each.altnames}) + + #loop replaced by a list comprehension + systemtype_attributetype_set=[{"type":each.name,"type_id":str(each._id),"value":each.data_type, 'sub_values': each.complex_data_type, 'altnames': each.altnames} for each in systemtype.attribute_type_set] + #a temp. variable which stores the lookup for append method + sys_type_relation_set_append= systemtype_relationtype_set.append for eachrt in systemtype.relation_type_set: # object_type = [ {"name":rtot.name, "id":str(rtot._id)} for rtot in node_collection.find({'member_of': {'$all': [ node_collection.find_one({"_id":eachrt.object_type[0]})._id]}}) ] object_type_cur = node_collection.find({'member_of': {'$in': eachrt.object_type}}) object_type = [] - for each in object_type_cur: - object_type.append({"name":each.name, "id":str(each._id)}) - systemtype_relationtype_set.append({"rt_name": eachrt.name, "type_id": str(eachrt._id), "object_type": object_type}) + # for each in object_type_cur: + # object_type.append({"name":each.name, "id":str(each._id)}) + object_type=[{"name":each.name, "id":str(each._id)} for each in object_type_cur] + sys_type_relation_set_append({"rt_name": eachrt.name, "type_id": str(eachrt._id), "object_type": object_type}) request_at_dict = {} request_rt_dict = {} @@ -455,28 +479,60 @@ def mis_create_edit(request, group_id, app_id, app_set_id=None, app_set_instance node_id = node_collection.one({'name':each,'_type':'GSystemType'})._id if node_id in app.type_of: File = 'True' - + if app_set_instance_id : # at and rt set editing instance - system = node_collection.find_one({"_id":ObjectId(app_set_instance_id)}) - for eachatset in systemtype_attributetype_set : - eachattribute = triple_collection.find_one({"_type":"GAttribute", "subject":system._id, "attribute_type.$id":ObjectId(eachatset["type_id"])}) - if eachattribute : - eachatset['database_value'] = eachattribute.object_value - eachatset['database_id'] = str(eachattribute._id) - else : - eachatset['database_value'] = "" - eachatset['database_id'] = "" - for eachrtset in systemtype_relationtype_set : - eachrelation = triple_collection.find_one({"_type":"GRelation", "subject":system._id, "relation_type.$id":ObjectId(eachrtset["type_id"])}) - if eachrelation: - right_subject = node_collection.find_one({"_id":ObjectId(eachrelation.right_subject)}) - eachrtset['database_id'] = str(eachrelation._id) - eachrtset["database_value"] = right_subject.name - eachrtset["database_value_id"] = str(right_subject._id) - else : - eachrtset['database_id'] = "" - eachrtset["database_value"] = "" - eachrtset["database_value_id"] = "" + system = node_collection.find_one({"_id":ObjectId(app_set_instance_id)}) + #Function used by Processes implemented below + def multi_(lst): + for eachatset in lst: + eachattribute=triple_collection.find_one({"_type":"GAttribute", "subject":system._id, "attribute_type.$id":ObjectId(eachatset["type_id"])}) + if eachattribute : + eachatset['database_value'] = eachattribute.object_value + eachatset['database_id'] = str(eachattribute._id) + else : + eachatset['database_value'] = "" + eachatset['database_id'] = "" + #this empty list will have the Process objects as its elements + processes=[] + #returns no of cores in the cpu + x=mp.cpu_count() + n1=len(systemtype_attributetype_set) + #divides the list into those many parts + n2=n1/x + #Process object is created.The list after being partioned is also given as an argument. + for i in range(x): + processes.append(mp.Process(target=multi_,args=(systemtype_attributetype_set[i*n2:(i+1)*n2],))) + for i in range(x): + processes[i].start()#each Process started + for i in range(x): + processes[i].join()#each Process converges + + #Function used by Processes implemented below + def multi_2(lst): + for eachrtset in lst: + eachrelation = triple_collection.find_one({"_type":"GRelation", "subject":system._id, "relation_type.$id":ObjectId(eachrtset["type_id"])}) + if eachrelation: + right_subject = node_collection.find_one({"_id":ObjectId(eachrelation.right_subject)}) + eachrtset['database_id'] = str(eachrelation._id) + eachrtset["database_value"] = right_subject.name + eachrtset["database_value_id"] = str(right_subject._id) + else : + eachrtset['database_id'] = "" + eachrtset["database_value"] = "" + eachrtset["database_value_id"] = "" + #this empty list will have the Process objects as its elements + processes2=[] + n1=len(systemtype_relationtype_set) + #divides the list into those many parts + n2=n1/x + #Process object is created.The list after being partioned is also given as an argument. + for i in range(x): + processes2.append(mp.Process(target=multi_2,args=(systemtype_relationtype_set[i*n2:(i+1)*n2],))) + for i in range(x): + processes2[i].start()#each Process started + for i in range(x): + processes2[i].join()#each Process converges + tags = ",".join(system.tags) content_org = system.content_org @@ -495,13 +551,40 @@ def mis_create_edit(request, group_id, app_id, app_set_id=None, app_set_instance map_geojson_data = request.POST.get('map-geojson-data') # getting markers user_last_visited_location = request.POST.get('last_visited_location') # getting last visited location by user file1 = request.FILES.get('file', '') - - for each in systemtype_attributetype_set: - if request.POST.get(each["type_id"],"") : - request_at_dict[each["type_id"]] = request.POST.get(each["type_id"],"") - for eachrtset in systemtype_relationtype_set: - if request.POST.get(eachrtset["type_id"],""): - request_rt_dict[eachrtset["type_id"]] = request.POST.get(eachrtset["type_id"],"") + #Function used by Processes implemented below + def multi_3(lst): + for each in lst: + if request.POST.get(each["type_id"],"") : + request_at_dict[each["type_id"]] = request.POST.get(each["type_id"],"") + #this empty list will have the Process objects as its elements + processes3=[] + n1=len(systemtype_attributetype_set) + #divides the list into those many parts + n2=n1/x + #Process object is created.The list after being partioned is also given as an argument. + for i in range(x): + processes3.append(mp.Process(target=multi_3,args=(systemtype_attributetype_set[i*n2:(i+1)*n2],))) + for i in range(x): + processes3[i].start()#each Process started + for i in range(x): + processes3[i].join()#each Process converges + #Function used by Processes implemented below + def multi_4(lst): + for eachrtset in lst: + if request.POST.get(eachrtset["type_id"],""): + request_rt_dict[eachrtset["type_id"]] = request.POST.get(eachrtset["type_id"],"") + #this empty list will have the Process objects as its elements + processes4=[] + n1=len(systemtype_relationtype_set) + #divides the list into those many parts + n2=n1/x + #Process object is created.The list after being partioned is also given as an argument. + for i in range(x): + processes4.append(mp.Process(target=multi_4,args=(systemtype_relationtype_set[i*n2:(i+1)*n2],))) + for i in range(x): + processes4[i].start()#each Process started + for i in range(x): + processes4[i].join() #each Process converges if File == 'True': if file1: @@ -565,15 +648,26 @@ def mis_create_edit(request, group_id, app_id, app_set_id=None, app_set_instance newgsystem.save() if not app_set_instance_id: - for key, value in request_at_dict.items(): - attributetype_key = node_collection.find_one({"_id":ObjectId(key)}) - ga_node = create_gattribute(newgsystem._id, attributetype_key, value) - # newattribute = triple_collection.collection.GAttribute() - # newattribute.subject = newgsystem._id - # newattribute.attribute_type = attributetype_key - # newattribute.object_value = value - # newattribute.save() - for key, value in request_rt_dict.items(): + #Function used by Processes implemented below + def multi_5(lst): + for key,value in lst: + attributetype_key = node_collection.find_one({"_id":ObjectId(key)}) + ga_node = create_gattribute(newgsystem._id, attributetype_key, value) + #this empty list will have the Process objects as its elements + processes5=[] + lst11=request_at_dict.items() + n1=len(lst11) + #divides the list into those many parts + n2=n1/x + #Process object is created.The list after being partioned is also given as an argument. + for i in range(x): + processes5.append(mp.Process(target=multi_5,args=(lst11[i*n2:(i+1)*n2],))) + for i in range(x): + processes5[i].start()#each Process started + for i in range(x): + processes5[i].join()#each Process converges + """ + for key, value in request_rt_dict.items(): if key: relationtype_key = node_collection.find_one({"_id": ObjectId(key)}) if value: @@ -584,9 +678,33 @@ def mis_create_edit(request, group_id, app_id, app_set_id=None, app_set_instance # newrelation.relation_type = relationtype_key # newrelation.right_subject = right_subject._id # newrelation.save() + """ + def multi_6(lst):#Function used by Processes implemented below + for key,value in lst: + if key: + relationtype_key = node_collection.find_one({"_id": ObjectId(key)}) + if value: + right_subject = node_collection.find_one({"_id": ObjectId(value)}) + gr_node = create_grelation(newgsystem._id, relationtype_key, right_subject._id) + + #this empty list will have the Process objects as its elements + processes6=[] + lst12=request_rt_dict.items() + n1=len(lst12) + #divides the list into those many parts + n2=n1/x + #Process object is created.The list after being partioned is also given as an argument. + for i in range(x): + processes6.append(mp.Process(target=multi_6,args=(lst12[i*n2:(i+1)*n2],))) + for i in range(x): + processes6[i].start()#each Process started + for i in range(x): + processes6[i].join()#each Process converges + if app_set_instance_id: # editing instance + """ for each in systemtype_attributetype_set: if each["database_id"]: attribute_instance = triple_collection.find_one({"_id": ObjectId(each['database_id'])}) @@ -602,7 +720,38 @@ def mis_create_edit(request, group_id, app_id, app_set_id=None, app_set_instance # newattribute.object_value = request.POST.get(each["type_id"],"") # newattribute.save() ga_node = create_gattribute(newgsystem._id, attributetype_key, request.POST.get(each["type_id"],"")) - + """ + def multi_7(lst):#Function used by Processes implemented below + for each in lst: + if each["database_id"]: + attribute_instance = triple_collection.find_one({"_id": ObjectId(each['database_id'])}) + attribute_instance.object_value = request.POST.get(each["database_id"],"") + # attribute_instance.save() + ga_node = create_gattribute(attribute_instance.subject, attribute_instance.attribute_type, attribute_instance.object_value) + else: + if request.POST.get(each["type_id"], ""): + attributetype_key = node_collection.find_one({"_id":ObjectId(each["type_id"])}) + # newattribute = triple_collection.collection.GAttribute() + # newattribute.subject = newgsystem._id + # newattribute.attribute_type = attributetype_key + # newattribute.object_value = request.POST.get(each["type_id"],"") + # newattribute.save() + ga_node = create_gattribute(newgsystem._id, attributetype_key, request.POST.get(each["type_id"],"")) + #this empty list will have the Process objects as its elements + processes7=[] + n1=len(systemtype_attributetype_set) + #divides the list into those many parts + n2=n1/x + #Process object is created.The list after being partioned is also given as an argument. + for i in range(x): + processes7.append(mp.Process(target=multi_7,args=(systemtype_attributetype_set[i*n2:(i+1)*n2],))) + for i in range(x): + processes7[i].start()#each Process started + for i in range(x): + processes7[i].join()#each Process converges + + + """ for eachrt in systemtype_relationtype_set: if eachrt["database_id"]: relation_instance = triple_collection.find_one({"_id":ObjectId(eachrt['database_id'])}) @@ -619,7 +768,32 @@ def mis_create_edit(request, group_id, app_id, app_set_id=None, app_set_instance # newrelation.relation_type = relationtype_key # newrelation.right_subject = right_subject._id # newrelation.save() - + """ + def multi_8(lst):#Function used by Processes implemented below + for eachrt in lst: + if eachrt["database_id"]: + relation_instance = triple_collection.find_one({"_id":ObjectId(eachrt['database_id'])}) + relation_instance.right_subject = ObjectId(request.POST.get(eachrt["database_id"],"")) + # relation_instance.save() + gr_node = create_grelation(relation_instance.subject, relation_instance.relation_type, relation_instance.right_subject) + else : + if request.POST.get(eachrt["type_id"],""): + relationtype_key = node_collection.find_one({"_id":ObjectId(eachrt["type_id"])}) + right_subject = node_collection.find_one({"_id":ObjectId(request.POST.get(eachrt["type_id"],""))}) + gr_node = create_grelation(newgsystem._id, relationtype_key, right_subject._id) + + #this empty list will have the Process objects as its elements + processes8=[] + n1=len(systemtype_relationtype_set) + #divides the list into those many parts + n2=n1/x + #Process object is created.The list after being partioned is also given as an argument. + for i in range(x): + processes8.append(mp.Process(target=multi_4,args=(systemtype_relationtype_set[i*n2:(i+1)*n2],))) + for i in range(x): + processes8[i].start()#each Process started + for i in range(x): + processes8[i].join() #each Process converges return HttpResponseRedirect(reverse(app_name.lower()+":"+template_prefix+'_app_detail', kwargs={'group_id': group_id, "app_id":app_id, "app_set_id":app_set_id})) template = "ndf/"+template_prefix+"_create_edit.html" diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/page.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/page.py index f88df0d..b4d711a 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/views/page.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/page.py @@ -1,6 +1,7 @@ ''' -- imports from python libraries -- ''' # import os -- Keep such imports here import json +import multiprocessing as mp from difflib import HtmlDiff ''' -- imports from installed packages -- ''' @@ -82,7 +83,7 @@ def page(request, group_id, app_id=None): # Code for user shelf shelves = [] shelf_list = {} - auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) }) + auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) }) # if auth: # has_shelf_RT = node_collection.one({'_type': 'RelationType', 'name': u'has_shelf' }) @@ -175,10 +176,11 @@ def page(request, group_id, app_id=None): if node is None: node = node_collection.find({'member_of':ObjectId(app_id)}) - + #a temp. variable which stores the lookup for append method + content_append_temp=content.append for nodes in node: node,ver=get_versioned_page(nodes) - content.append(node) + content_append_temp(node) # rcs content ends here @@ -293,8 +295,10 @@ def create_edit_page(request, group_id, node_id=None): available_nodes = node_collection.find({'_type': u'GSystem', 'member_of': ObjectId(gst_page._id),'group_set': ObjectId(group_id) }) nodes_list = [] - for each in available_nodes: - nodes_list.append(str((each.name).strip().lower())) + # for each in available_nodes: + # nodes_list.append(str((each.name).strip().lower())) + #loop replaced by a list comprehension + node_list=[str((each.name).strip().lower()) for each in available_nodes] if node_id: page_node = node_collection.one({'_type': u'GSystem', '_id': ObjectId(node_id)}) @@ -415,11 +419,9 @@ def translate_node(request,group_id,node_id=None): content = data node_details=[] for k,v in content.items(): - - node_name = content['name'] - node_content_org=content['content_org'] - node_tags=content['tags'] - + node_name = content['name'] + node_content_org=content['content_org'] + node_tags=content['tags'] return render_to_response("ndf/translation_page.html", {'content': content, 'appId':app._id, @@ -430,7 +432,7 @@ def translate_node(request,group_id,node_id=None): }, context_instance = RequestContext(request) - ) + ) @get_execution_time diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/partner.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/partner.py index 8e6389f..1d5a60b 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/views/partner.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/partner.py @@ -30,6 +30,7 @@ from gnowsys_ndf.ndf.views.notify import set_notif_val # ###################################################################################################################################### gst_group = node_collection.one({"_type": "GSystemType", 'name': GAPPS[2]}) +partner_group_gst = node_collection.one({"_type": "GSystemType", 'name': u'PartnerGroup'}) get_all_usergroups=get_all_user_groups() at_apps_list=node_collection.one({'$and':[{'_type':'AttributeType'},{'name':'apps_list'}]}) ins_objectid = ObjectId() @@ -175,7 +176,7 @@ def partner_list(request, group_id): # print GSTUDIO_NROER_MENU return render_to_response("ndf/partner_list.html", {'group_nodes': collection_set, "groups_category": groups_category, - 'groupid': group_id, 'group_id': group_id + 'groupid': group_id, 'group_id': group_id, "app_gst": partner_group_gst, }, context_instance=RequestContext(request)) @@ -200,10 +201,17 @@ def nroer_groups(request, group_id, groups_category): 'name': {'$nin': ["home"], '$in': groups_names_list}, 'group_type': "PUBLIC" })#.sort('last_update', -1) - + + if groups_category == "Partners": + app_gst = node_collection.one({'_type': 'GSystemType', 'name': 'PartnerGroup'}) + + elif groups_category == "Groups": + app_gst = gst_group + + # print "=============", app_gst group_nodes_count = group_nodes.count() if group_nodes else 0 return render_to_response("ndf/partner.html", {'group_nodes': group_nodes, "groups_category": groups_category, - 'group_nodes_count': group_nodes_count, + 'group_nodes_count': group_nodes_count, 'app_gst': app_gst, 'groupid': group_id, 'group_id': group_id }, context_instance=RequestContext(request)) diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/person.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/person.py index aecff15..a2adc0e 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/views/person.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/person.py @@ -44,7 +44,7 @@ def person_detail(request, group_id, app_id=None, app_set_id=None, app_set_insta if group_ins: group_id = str(group_ins._id) else : - auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) }) + # auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) }) if auth : group_id = str(auth._id) else : @@ -86,8 +86,11 @@ def person_detail(request, group_id, app_id=None, app_set_id=None, app_set_insta agency_type = auth.agency_type agency_type_node = node_collection.one({'_type': "GSystemType", 'name': agency_type}, {'collection_set': 1}) if agency_type_node: - for eachset in agency_type_node.collection_set: - app_collection_set.append(node_collection.one({"_id": eachset}, {'_id': 1, 'name': 1, 'type_of': 1})) + # for eachset in agency_type_node.collection_set: + # app_collection_set.append(node_collection.one({"_id": eachset}, {'_id': 1, 'name': 1, 'type_of': 1})) + #loop replaced by a list comprehension + app_collection_set=[node_collection.one({"_id": eachset}, {'_id': 1, 'name': 1, 'type_of': 1}) for eachset in agency_type_node.collection_set] + if app_set_id: person_gst = node_collection.one({'_type': "GSystemType", '_id': ObjectId(app_set_id)})#, {'name': 1, 'type_of': 1}) @@ -115,8 +118,10 @@ def person_detail(request, group_id, app_id=None, app_set_id=None, app_set_insta ] widget_for = get_widget_built_up_data(widget_for, person_gs) - for each in univ_cur: - univ_list.append(each) +# for each in univ_cur: +# univ_list.append(each) + #loop replaced by a list comprehension + univ_list=[each for each in univ_cur] elif title == "Program Officer" or title == "Voluntary Teacher": diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/search_views.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/search_views.py index fec66be..7de4169 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/views/search_views.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/search_views.py @@ -17,6 +17,7 @@ import string import datetime import itertools import nltk +import multiprocessing as mp from gnowsys_ndf.ndf.models import node_collection, triple_collection from gnowsys_ndf.ndf.models import * @@ -257,7 +258,9 @@ def results_search(request, group_id, return_only_dict = None): For each matching GSystem, see if the GSystem has already been added to the list of ids and add if not added. result is added only if belongs to the list of public groups """ - + #temp. variables which stores the lookup for append method + all_ids_append_temp=all_ids.append + search_results_ex_name_append_temp=search_results_ex['name'].append for j in exact_match: j.name=(j.name).replace('"',"'") if j._id not in all_ids: @@ -265,8 +268,8 @@ def results_search(request, group_id, return_only_dict = None): #for gr in public_groups: # if gr in grps: j = addType(j) - search_results_ex['name'].append(j) - all_ids.append(j['_id']) + search_results_ex_name_append_temp(j) + all_ids_append_temp(j['_id']) # SORTS THE SEARCH RESULTS BY SIMILARITY WITH THE SEARCH QUERY #search_results_ex['name'] = sort_names_by_similarity(search_results_ex['name'], search_str_user) @@ -274,7 +277,8 @@ def results_search(request, group_id, return_only_dict = None): split_stem_match = [] # will hold all the split stem match results len_stemmed = len(search_str_stemmed) c = 0 # GEN. COUNTER - + #a temp. variable which stores the lookup for append method + split_stem_match_append_temp=split_stem_match.append while c < len_stemmed: word = search_str_stemmed[c] temp="" @@ -293,13 +297,15 @@ def results_search(request, group_id, return_only_dict = None): {'$or':[{"access_policy":{"$in":Access_policy}},{'created_by':request.user.id}]}, {"name":{"$regex":str(word), "$options":"i"}}] }, {"name":1, "_id":1, "member_of":1, "created_by":1, "last_update":1, "group_set":1, "url":1}).sort('last_update',-1) - split_stem_match.append(temp) + split_stem_match_append_temp(temp) c += 1 """ For each matching GSystem, see if the GSystem has already been returned in search results and add if not already added. Result is added only if belongs to the list of public groups and has public access policy """ + #a temp. variable which stores the lookup for append method + search_results_st_name_append=search_results_st['name'].append for j in split_stem_match: c = 0 for k in j: @@ -313,8 +319,8 @@ def results_search(request, group_id, return_only_dict = None): # check that the GSystem should belong to at least one public group k = addType(k) # adds the link and datetime to the - search_results_st['name'].append(k) - all_ids.append(k['_id'])#append to the list of all ids of GSYstems in the results + search_results_st_name_append(k) + all_ids_append_temp(k['_id'])#append to the list of all ids of GSYstems in the results c += 1 # SORTS THE SEARCH RESULTS BY SIMILARITY WITH THE SEARCH QUERY @@ -340,6 +346,9 @@ def results_search(request, group_id, return_only_dict = None): {"group_set":ObjectId(group_id)}, {"tags":search_str_user}]}, {"name":1, "_id":1, "member_of":1, "created_by":1, "last_update":1, "group_set":1, "url":1}).sort('last_update',-1) + # temp. variables which stores the lookup for append method + all_ids_append_temp=all_ids.append + search_results_ex_tags_append_temp=search_results_ex['tags'].append for j in exact_match: j.name=(j.name).replace('"',"'") if j._id not in all_ids: @@ -348,8 +357,8 @@ def results_search(request, group_id, return_only_dict = None): #for gr in public_groups: # if gr in grps: j = addType(j) - search_results_ex['tags'].append(j) - all_ids.append(j['_id']) + search_results_ex_tags_append_temp(j) + all_ids_append_temp(j['_id']) #search_results_ex['tags'] = sort_names_by_similarity(search_results_ex['tags'], search_str_user) @@ -358,7 +367,8 @@ def results_search(request, group_id, return_only_dict = None): split_stem_match = [] c = 0 # GEN. COUNTER len_stemmed = len(search_str_stemmed) - + #a temp. variable which stores the lookup for append method + split_stem_match_append_temp=split_stem_match.append while c < len_stemmed: word = search_str_stemmed[c] if user_reqd != -1: @@ -375,7 +385,7 @@ def results_search(request, group_id, return_only_dict = None): {"group_set":ObjectId(group_id)}]}, {"name":1, "_id":1, "member_of":1, "created_by":1, "last_update":1, "group_set":1, "url":1}).sort('last_update',-1) - split_stem_match.append(temp) + split_stem_match_append_temp(temp) c += 1 #search_results_st['tags'] = sort_names_by_similarity(search_results_st['tags'], search_str_user) @@ -383,6 +393,8 @@ def results_search(request, group_id, return_only_dict = None): For each matching GSystem, see if the GSystem has already been returned in search results and add if not already added. Result is added only if belongs to the list of public groups and has public access policy """ + #a temp. variable which stores the lookup for append method + search_results_st_tags_append=search_results_st['tags'].append for j in split_stem_match: c = 0 for k in j: @@ -392,8 +404,8 @@ def results_search(request, group_id, return_only_dict = None): #for gr in public_groups: # if gr in grps: k = addType(k) - search_results_st['tags'].append(k) - all_ids.append(k['_id']) + search_results_st_tags_append(k) + all_ids_append_temp(k['_id']) c += 1 """ @@ -405,7 +417,8 @@ def results_search(request, group_id, return_only_dict = None): content_docs = [] content_match_pairs = [] # STORES A DICTIONARY OF MATCHING DOCUMENTS AND NO_OF_WORDS THAT MATCH SEARCH QUERY sorted_content_match_pairs = [] # STORES THE ABOVE DICTIONARY IN A SORTED MANNER - + #a temp. variable which stores the lookup for append method + content_match_pairs_append_temp=content_match_pairs.append if (search_by_contents == True): # FETCH ALL THE GSYSTEMS THAT HAVE BEEN MAP REDUCED. all_Reduced_documents = node_collection.find({"required_for": reduced_doc_requirement}, {"content": 1, "_id": 0, "orignal_id": 1}) @@ -418,10 +431,9 @@ def results_search(request, group_id, return_only_dict = None): for word in search_str_stemmed: if word in content.keys():# IF THE WORD EXISTS IN THE CURRENT DOCUMENT match_count += content[word] # ADD IT TO THE MATCHES COUNT - if match_count > 0: all_ids.append(singleDoc.orignal_id) - content_match_pairs.append({'doc_id':singleDoc.orignal_id, 'matches':match_count}) + content_match_pairs_append_temp({'doc_id':singleDoc.orignal_id, 'matches':match_count}) match_counts = [] # KEEPS A SORTED LIST OF COUNT OF MATCHES IN RESULT DOCUMENTS for pair in content_match_pairs: @@ -430,7 +442,8 @@ def results_search(request, group_id, return_only_dict = None): c += 1 match_counts.insert(c, pair['matches']) sorted_content_match_pairs.insert(c, pair) # SORTED INSERT (INCREASING ORDER) - + #a temp. variable which stores the lookup for append method + search_results_st_content_append_temp=search_results_st['content'].append for docId in sorted_content_match_pairs: doc = node_collection.find_one({"_id":docId['doc_id'], "access_policy":Access_policy}, {"name":1, "_id":1, "member_of":1, "created_by":1, "last_update":1, "group_set":1, "url":1}) try: @@ -447,9 +460,9 @@ def results_search(request, group_id, return_only_dict = None): if ObjectId(group_id) in grps: if user_reqd != -1: if User.objects.get(username=doc['created_by']).pk == user_reqd: - search_results_st['content'].append(doc) + search_results_st_content_append_temp(doc) else: - search_results_st['content'].append(doc) + search_results_st_content_append_temp(doc) except: pass #search_results = json.dumps(search_results, cls=Encoder) diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/topics.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/topics.py index 2344f1f..77a0737 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/views/topics.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/topics.py @@ -91,6 +91,7 @@ def themes(request, group_id, app_id=None, app_set_id=None): nodes = "" unfold_tree = request.GET.get('unfold','') selected = request.GET.get('selected','') + tree = request.GET.get('tree','collapsible') unfold = "false" # topics_GST = node_collection.find_one({'_type': 'GSystemType', 'name': 'Topics'}) @@ -129,8 +130,8 @@ def themes(request, group_id, app_id=None, app_set_id=None): # nodes_dict = node_collection.find({'member_of': {'$all': [theme_GST._id]},'group_set':{'$all': [ObjectId(group_id)]}}) return render_to_response("ndf/theme.html", - {'theme_GST_id':theme_GST._id, 'themes_cards': themes_cards, - 'group_id': group_id,'groupid': group_id,'node': node,'shelf_list': shelf_list,'shelves': shelves, + {'theme_GST_id':theme_GST._id, 'theme_GST':theme_GST, 'themes_cards': themes_cards, 'theme_GST':theme_GST, + 'group_id': group_id,'groupid': group_id,'node': node,'shelf_list': shelf_list,'shelves': shelves, 'tree': tree, 'nodes':nodes_dict,'app_id': app_id,'app_name': appName,"selected": selected, 'title': title,'themes_list_items': themes_list_items, 'themes_hierarchy': themes_hierarchy, 'unfold': unfold, @@ -667,7 +668,7 @@ def theme_topic_create_edit(request, group_id, app_set_id=None): ) return render_to_response("ndf/theme.html", - {'group_id': group_id,'groupid': group_id, 'drawer': drawer, 'themes_cards': themes_cards, + {'group_id': group_id,'groupid': group_id, 'drawer': drawer, 'themes_cards': themes_cards, 'theme_GST':theme_GST, 'theme_GST':theme_GST, 'shelf_list': shelf_list,'shelves': shelves, 'create_edit': create_edit, 'themes_hierarchy': themes_hierarchy,'app_id': app_id,'appId':app._id, 'nodes_list': nodes_list,'title': title,'node': node, 'parent_nodes_collection': parent_nodes_collection, @@ -724,7 +725,8 @@ def topic_detail_view(request, group_id, app_Id=None): nav_l=request.GET.get('nav_li','') breadcrumbs_list = [] nav_li = "" - + #a temp. variable which stores the lookup for append method + breadcrumbs_list_append_temp=breadcrumbs_list.append if nav_l: nav_li = nav_l nav_l = str(nav_l).split(",") @@ -739,9 +741,9 @@ def topic_detail_view(request, group_id, app_Id=None): if each_obj.prior_node: theme_obj = node_collection.one({'_id': ObjectId(each_obj.prior_node[0] ) }) theme_id = theme_obj._id - breadcrumbs_list.append( (str(theme_obj._id), theme_obj.name) ) + breadcrumbs_list_append_temp( (str(theme_obj._id), theme_obj.name) ) - breadcrumbs_list.append( (str(each_obj._id), each_obj.name) ) + breadcrumbs_list_append_temp( (str(each_obj._id), each_obj.name) ) @@ -752,6 +754,8 @@ def topic_detail_view(request, group_id, app_Id=None): ###shelf### shelves = [] + #a temp. variable which stores the lookup for append method + shelves_append_temp=shelves.append shelf_list = {} auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) }) @@ -763,12 +767,14 @@ def topic_detail_view(request, group_id, app_Id=None): if shelf: for each in shelf: shelf_name = node_collection.one({'_id': ObjectId(each.right_subject)}) - shelves.append(shelf_name) + shelves_append_temp(shelf_name) shelf_list[shelf_name.name] = [] + #a temp. variable which stores the lookup for append method + shelf_list_shlefname_append_temp=shelf_list[shelf_name.name].append for ID in shelf_name.collection_set: shelf_item = node_collection.one({'_id': ObjectId(ID) }) - shelf_list[shelf_name.name].append(shelf_item.name) + shelf_list_shlefname_append_temp(shelf_item.name) else: shelves = [] diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/userDashboard.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/userDashboard.py index c93f572..c64cac9 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/views/userDashboard.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/userDashboard.py @@ -64,7 +64,7 @@ def userpref(request,group_id): @login_required @get_execution_time def uDashboard(request, group_id): - usrid = int(group_id) + usrid = int(group_id) auth = node_collection.one({'_type': "Author", 'created_by': usrid}) group_id = auth._id # Fetching user group of current user & then reassigning group_id with it's corresponding ObjectId value @@ -150,37 +150,37 @@ def uDashboard(request, group_id): user_activity = [] page_gst = node_collection.one({'_type': "GSystemType", 'name': 'Page'}) - page_cur = node_collection.find({'member_of': {'$all': [page_gst._id]}, + page_cur = node_collection.find ({'member_of': {'$all': [page_gst._id]}, 'created_by': int(usrid), "status": {"$nin": ["HIDDEN"]}}) - file_cur = node_collection.find({'_type': u"File", 'created_by': int(usrid), + file_cur = node_collection.find ({'_type': u"File", 'created_by': int(usrid), "status": {"$nin": ["HIDDEN"]}}) forum_gst = node_collection.one({"_type": "GSystemType", "name": "Forum"}) - forum_count = node_collection.find({"_type": "GSystem", + forum_count = node_collection.find ({"_type": "GSystem", "member_of": forum_gst._id, 'created_by': int(usrid), "status": {"$nin": ["HIDDEN"]}}) quiz_gst = node_collection.one({"_type": "GSystemType", "name": "Quiz"}) - quiz_count = node_collection.find({"_type": "GSystem", + quiz_count = node_collection.find ({"_type": "GSystem", "member_of": quiz_gst._id, 'created_by': int(usrid), "status": {"$nin": ["HIDDEN"]}}) thread_gst = node_collection.one({"_type": "GSystemType", "name": "Twist"}) - thread_count = node_collection.find({"_type": "GSystem", + thread_count =node_collection.find ({"_type": "GSystem", "member_of": thread_gst._id, 'created_by': int(usrid), "status": {"$nin": ["HIDDEN"]}}) reply_gst = node_collection.one({"_type": "GSystemType", "name": "Reply"}) - reply_count = node_collection.find({"_type": "GSystem", + reply_count = node_collection.find ({"_type": "GSystem", "member_of": reply_gst._id, 'created_by': int(usrid), "status": {"$nin": ["HIDDEN"]}}) task_cur = "" if current_user: if int(current_user) == int(usrid): - task_cur = node_collection.find( + task_cur = node_collection.find ( {'member_of': task_gst._id, 'attribute_set.Status': {'$in': ["New", "In Progress"]}, 'attribute_set.Assignee':usrid} ).sort('last_update', -1).limit(10) dashboard_count.update({'Task': task_cur.count()}) - group_cur = node_collection.find( + group_cur = node_collection.find ( {'_type': "Group", 'name': {'$nin': ["home", auth.name]},"access_policy":{"$in":Access_policy}, '$or': [{'group_admin': int(usrid)}, {'author_set': int(usrid)}]}).sort('last_update', -1).limit(10) @@ -189,7 +189,7 @@ def uDashboard(request, group_id): # user activity gives all the activities of the users activity = "" - activity_user = node_collection.find( + activity_user = node_collection.find ( {'$and': [{'$or': [{'_type': 'GSystem'}, {'_type': 'group'}, {'_type': 'File'}]}, {"access_policy": {"$in": Access_policy}},{'status':{'$in':[u"DRAFT",u"PUBLISHED"]}}, {'member_of': {'$nin': [exclued_from_public]}}, @@ -199,10 +199,13 @@ def uDashboard(request, group_id): a_user = [] dashboard_count.update({'activity': activity_user.count()}) - for i in activity_user: - if i._type != 'Batch' or i._type != 'Course' or i._type != 'Module': - a_user.append(i) - + #for i in activity_user: + # if i._type != 'Batch' or i._type != 'Course' or i._type != 'Module': + # a_user.append(i) + #loop replaced by a list comprehension + a_user=[i for i in activity_user if (i._type != 'Batch' or i._type != 'Course' or i._type != 'Module')] + #a temp. variable which stores the lookup for append method + user_activity_append_temp=user_activity.append for each in a_user: if each.created_by == each.modified_by: if each.last_update == each.created_at: @@ -213,10 +216,10 @@ def uDashboard(request, group_id): activity = 'created' if each._type == 'Group': - user_activity.append(each) + user_activity_append_temp(each) else: member_of = node_collection.find_one({"_id": each.member_of[0]}) - user_activity.append(each) + user_activity_append_temp(each) ''' notification_list=[] @@ -240,11 +243,13 @@ def uDashboard(request, group_id): task_cur gives the task asigned to users ''' - obj = node_collection.find( + obj = node_collection.find ( {'_type': {'$in': [u"GSystem", u"File"]}, 'contributors': int(usrid), 'group_set': {'$all': [ObjectId(group_id)]}} ) collab_drawer = [] + #a temp. variable which stores the lookup for append method + collab_drawer_append_temp=collab_drawer.append """ To populate collaborators according to their latest modification of particular resource: @@ -252,7 +257,7 @@ def uDashboard(request, group_id): for each in obj.sort('last_update', -1): for val in each.contributors: name = User.objects.get(pk=val).username - collab_drawer.append({'usrname': name, 'Id': val, + collab_drawer_append_temp({'usrname': name, 'Id': val, 'resource': each.name}) shelves = [] @@ -305,7 +310,6 @@ def uDashboard(request, group_id): context_instance=RequestContext(request) ) - @get_execution_time def user_preferences(request,group_id,auth_id): try: @@ -350,6 +354,7 @@ def user_preferences(request,group_id,auth_id): except Exception as e: print "Exception in userpreference view "+str(e) return HttpResponse("Failure") + @get_execution_time def user_template_view(request,group_id): auth_group = None diff --git a/gnowsys-ndf/gnowsys_ndf/settings.py b/gnowsys-ndf/gnowsys_ndf/settings.py index 083c469..6147e4d 100644 --- a/gnowsys-ndf/gnowsys_ndf/settings.py +++ b/gnowsys-ndf/gnowsys_ndf/settings.py @@ -632,6 +632,8 @@ GSTUDIO_GROUP_MODERATION_LEVEL = 1 # allowed moderation levels GSTUDIO_ALLOWED_GROUP_MODERATION_LEVELS = [1, 2, 3] +GSTUDIO_LICENCE = ["CC BY-SA", "CC BY", "CC BY-NC-SA", "CC BY-NC-ND", "CC BY-ND", "PUBLIC-DOMAIN", "FDL (FREE DOCUMENTATION LICENSE)", "OTHERS"] + try: from local_settings import * # print "Local settings applied" |