diff options
author | SaiEswarEpuri <saieswar36@gmail.com> | 2015-06-22 19:53:36 +0530 |
---|---|---|
committer | SaiEswarEpuri <saieswar36@gmail.com> | 2015-06-22 19:53:36 +0530 |
commit | c6b302c095c496dbb15e646ad992168ce919ae05 (patch) | |
tree | 4a5d30028f283e2d9d4aae68b3e4c73f4b162701 /gnowsys-ndf | |
parent | cc7ad3ea3250dc632add965a50df62ba366d9e1e (diff) | |
parent | 75183a74a922066c63a518dac856fe3b2df2a37a (diff) | |
download | gnowsys-c6b302c095c496dbb15e646ad992168ce919ae05.tar.gz |
Merge branch 'mongokit' of https://github.com/gnowledge/gstudio into mongokit
Diffstat (limited to 'gnowsys-ndf')
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/models.py | 8 | ||||
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/all_under_moderation_status.html | 25 | ||||
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/create_group.html | 596 | ||||
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/node_ajax_view.html | 40 | ||||
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/templatetags/ndf_tags.py | 28 | ||||
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/urls/group.py | 5 | ||||
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/views/group.py | 1014 | ||||
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/views/methods.py | 19 | ||||
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/views/moderation.py | 15 | ||||
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/settings.py | 3 |
10 files changed, 1094 insertions, 659 deletions
diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/models.py b/gnowsys-ndf/gnowsys_ndf/ndf/models.py index c48fb98..37b8894 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/models.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/models.py @@ -55,15 +55,15 @@ NODE_TYPE_CHOICES = ( ) TYPES_OF_GROUP = ( - ('ANONYMOUS'), ('PUBLIC'), - ('PRIVATE') + ('PRIVATE'), + ('ANONYMOUS') ) EDIT_POLICY = ( - ('NON_EDITABLE'), + ('EDITABLE_NON_MODERATED'), ('EDITABLE_MODERATED'), - ('EDITABLE_NON_MODERATED') + ('NON_EDITABLE') ) SUBSCRIPTION_POLICY = ( diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/all_under_moderation_status.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/all_under_moderation_status.html index ba9851b..e6bc756 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/all_under_moderation_status.html +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/all_under_moderation_status.html @@ -10,9 +10,32 @@ {% block style %} {% endblock %} + +{% block meta_content %} + <h3>{% trans "Underlying Moderation Groups:" %}</h3> + <br/> + <ul class="no-bullet"> + {% for each_group in group_hierarchy_obj_list %} + {% if not forloop.first %} + <li {% if each_group.pk == current_mod_group_obj.pk %} class="current-group" {% endif %} > + <a class="button expand tiny" href="{% url 'groupchange' each_group.pk %}"> + {{each_group.altnames}} + </a> + </li> + {% endif %} + {% endfor %} + </ul> + +{% endblock %} + + {% block body_content %} - <h4>Following resources are under moderation</h4> + {% if files.count > 0 %} + <h4>Following ({{files.count}}) resource/s are under moderation:</h4> + {% else %} + <h4>Currently, no resources are under moderation in this group</h4> + {% endif %} <div class="tabs-content gallery"> diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/create_group.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/create_group.html index a6a4fb1..fe1e335 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/create_group.html +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/create_group.html @@ -3,7 +3,13 @@ {% load ndf_tags %} {% load cache %} -{% block title %} Create New Group {% endblock %} +{% block title %} {% trans title|capfirst %} {% endblock %} + +<!-- +by keeping future perspective of one template for create/edit of group, +this template is modified. So for the fields in the template it supports - +- both create and edit of those fields. + --> {% block meta_content %} {% blocktrans %} @@ -17,81 +23,144 @@ {% endblock %} -{% block body_content %} +{% block body_content %} - <h2 class="text-center"><small>{% trans "Create New Group" %}</small></h2> + <h2 class="text-center"> + <small> + {% if node %} Edit | {{node.name}} + {% else %} {% trans "Create New Group" %} + {% endif %} + </small> + </h2> <br/> - <form id="create_group" class="" method="post" action="{% url 'create_group' group_id %}" data-abide> + <form id="create_group" class="" method="post" + {% if node %} action="{% url 'edit_group' group_id %}" + {% else %} action="{% url 'create_group' group_id %}" + {% endif %} + data-abide> {% csrf_token %} + <!-- node_id, name --> + {% if node %} + <input type="hidden" name="node_id" value="{{node.pk}}"> + <input type="hidden" name="name" value="{{node.name}}"> + {% endif %} + <!-- name --> <div class="row"> - <div class="small-4 columns"> - <label for="right-label" class="right inline">{% trans "Group Name" %}</label> - </div> - <div class="small-4 small-pull-4 columns"> - <input type="text" name="groupname" id="group_name" required placeholder="{% trans 'Enter the unique group name' %}"> - <label id="message" style="display:none; color:red"></label> - <small class="error">Group Name is required and it must be a string.</small> + <div class="small-12 medium-6 medium-centered columns"> + <div class="row"> + + <div class="small-4 columns"> + <label for="right-label" class="inline">{% trans "Group Name" %}</label> + </div> + + <div class="small-8 columns"> + <input type="text" name="name" id="group_name" required placeholder="{% trans 'Enter the unique group name' %}" {% if node %}disabled=disabled title="Group name can not be changed" {% endif %} value="{{node.name}}"> + <label id="message" style="display:none; color:red"></label> + <small class="error">Group Name is required and it must be a string.</small> + </div> + + </div> </div> </div> - <!-- altname --> + <!-- altnames --> <div class="row"> - <div class="small-4 columns"> - <label for="right-label" class="right inline">{% trans "Alternate Group Name" %}</label> - </div> - <div class="small-4 small-pull-4 columns"> - <input type="text" name="alt_groupname" id="alt_group_name" placeholder="{% trans 'Provide display/alternate group name' %}"> + <div class="small-12 medium-6 medium-centered columns"> + <div class="row"> + + <div class="small-4 columns"> + <label for="right-label" class="inline">{% trans "Alternate Group Name" %}</label> + </div> + + <div class="small-8 columns"> + <input type="text" name="altnames" id="alt_group_name" placeholder="{% trans 'Provide display/alternate group name' %}" value="{{node.altnames}}"> + </div> + </div> + </div> </div> <br/> - <!-- type --> + <!-- group_type --> <div class="row"> - <div class="small-4 columns"> - <label for="right-label" class="right inline">{% trans "Group Type" %}</label> - </div> - <div class="small-4 small-pull-4 columns"> - <select name="group_type" class="gtype"> - <option id="PUBLIC">{% trans "PUBLIC" %}</option> - <option id="PRIVATE">{% trans "PRIVATE" %}</option> - <option id="ANONYMOUS">{% trans "ANONYMOUS" %}</option> - </select> - <small class="error">Please select group type.</small> + <div class="small-12 medium-6 medium-centered columns"> + <div class="row"> + + <div class="small-4 columns"> + <label for="right-label" class="inline">{% trans "Group Type" %}</label> + </div> + + <div class="small-8 columns"> + <!-- getting "TYPES_OF_GROUP" defined in models.py --> + {% get_possible_group_type_values as poss_gr_type %} + <select name="group_type" class="gtype"> + {% for each_gtype in poss_gr_type %} + <option {% if each_gtype == node.group_type %}selected=selected{% endif %}> + {{each_gtype}} + </option> + {% endfor %} + </select> + <small class="error">Please select group type.</small> + </div> + + </div> </div> </div> <!-- editing policy --> <div class="row"> - <div class="small-4 columns"> - <label for="right-label" class="right inline">{% trans "Group Editing Policy" %}</label> - </div> - <div class="small-4 small-pull-4 columns"> - <select name="edit_policy" id="editp"> - <option id="EDITABLE_NON_MODERATED">{% trans "EDITABLE_NON_MODERATED" %}</option> - <option id="EDITABLE_MODERATED">{% trans "EDITABLE_MODERATED" %}</option> - <option id="NON_EDITABLE">{% trans "NON_EDITABLE" %}</option> - </select> - <small class="error">Please select group editing policy.</small> + <div class="small-12 medium-6 medium-centered columns"> + <div class="row"> + + <div class="small-4 columns"> + <label for="right-label" class="inline">{% trans "Group Editing Policy" %}</label> + </div> + + <div class="small-8 columns"> + <!-- getting "EDIT_POLICY" defined in models.py --> + {% get_possible_edit_policy_values as poss_edit_policy %} + <select name="edit_policy" id="editp"> + {% for each_gr_edit_policy in poss_edit_policy %} + <option {% if each_gr_edit_policy == node.edit_policy %}selected=selected{% endif %}> + {{each_gr_edit_policy}} + </option> + {% endfor %} + </select> + <small class="error">Please select group editing policy.</small> + </div> + </div> </div> </div> - + <!-- moderation level --> - <div class="row hide" id="moderation-level"> - <div class="small-4 columns"> - <label for="right-label" class="right inline">{% trans "Level of moderation" %}</label> - </div> - <div class="small-4 small-pull-4 columns"> - <select name="moderation_level"> - <option value="0">{% trans "--- Select Level ---" %}</option> - <option value="1">{% trans "One Level" %}</option> - <option value="2">{% trans "Two Level" %}</option> - <option value="3">{% trans "Three Level" %}</option> - </select> - <small class="error">{% trans "Please select group editing policy." %}</small> + <div class="row {% if node.edit_policy != 'EDITABLE_MODERATED' %}hide{% endif%}" id="moderation-level"> + <div class="small-12 medium-6 medium-centered columns"> + <div class="row"> + + <div class="small-4 columns"> + <label for="right-label" class="inline">{% trans "Level of moderation" %}</label> + </div> + + <div class="small-8 columns"> + <select name="moderation_level"> + <!-- EDITABLE_MODERATED group cannot have moderation_level to 0 --> + <option value="1">--- {% trans "Select Level" %} ---</option> + {% get_allowed_moderation_levels as mod_levels %} + {% for each_level in mod_levels %} + <option value="{{each_level}}" + {% if each_level == node.moderation_level %}selected=selected{% endif %}> + {{each_level}} + </option> + {% endfor %} + </select> + <small class="error">{% trans "Please select moderation level." %}</small> + </div> + + </div> </div> </div> @@ -101,58 +170,86 @@ <!-- subscription policy --> <div class="row"> - <div class="small-4 columns"> - <label for="right-label" class="right inline">{% trans "Group Subscription Policy" %}</label> - </div> - <div class="small-4 small-pull-4 columns"> - <select name="subscription" class="subscptn" disabled="disabled"> - <option id="OPEN">{% trans "OPEN" %}</option> - <option id="BY_REQUEST">{% trans "BY_REQUEST" %}</option> - <option id="BY_INVITATION">{% trans "BY_INVITATION" %}</option> - </select> - <small class="error">Please select subscription policy.</small> + <div class="small-12 medium-6 medium-centered columns"> + <div class="row"> + + <div class="small-4 columns"> + <label for="right-label" class="inline">{% trans "Group Subscription Policy" %}</label> + </div> + + <div class="small-8 columns"> + <select name="subscription" class="subscptn" disabled="disabled"> + <option id="OPEN">{% trans "OPEN" %}</option> + <option id="BY_REQUEST">{% trans "BY_REQUEST" %}</option> + <option id="BY_INVITATION">{% trans "BY_INVITATION" %}</option> + </select> + <small class="error">Please select subscription policy.</small> + </div> + + </div> </div> </div> <!-- member visibility --> <div class="row"> - <div class="small-4 columns"> - <label for="right-label" class="right inline">{% trans "Group Member Visibility" %}</label> - </div> - <div class="small-4 small-pull-4 columns"> - <select name="disclosure_policy" class="mem" disabled="disabled"> - <option id="DISCLOSED_TO_MEM">{% trans "DISCLOSED_TO_MEM" %}</option> - <option id="NOT_DISCLOSED_TO_MEM">{% trans "NOT_DISCLOSED_TO_MEM" %}</option> - </select> - <small class="error">Please select group member visibility.</small> + <div class="small-12 medium-6 medium-centered columns"> + <div class="row"> + + <div class="small-4 columns"> + <label for="right-label" class="inline">{% trans "Group Member Visibility" %}</label> + </div> + + <div class="small-8 columns"> + <select name="disclosure_policy" class="mem" disabled="disabled"> + <option id="DISCLOSED_TO_MEM">{% trans "DISCLOSED_TO_MEM" %}</option> + <option id="NOT_DISCLOSED_TO_MEM">{% trans "NOT_DISCLOSED_TO_MEM" %}</option> + </select> + <small class="error">Please select group member visibility.</small> + </div> + + </div> </div> </div> <!-- Group Encryption policy --> <div class="row"> - <div class="small-4 columns"> - <label for="right-label" class="right inline">{% trans "Group Encryption policy" %}</label> - </div> - <div class="small-4 small-pull-4 columns"> - <select name="encryption_policy" class="encr" disabled="disabled"> - <option id="NOT_ENCRYPTED">{% trans "NOT_ENCRYPTED" %}</option> - <option id="ENCRYPTED">{% trans "ENCRYPTED" %}</option> - </select> - <small class="error">Please select group encryption policy.</small> + <div class="small-12 medium-6 medium-centered columns"> + <div class="row"> + + <div class="small-4 columns"> + <label for="right-label" class="inline">{% trans "Group Encryption policy" %}</label> + </div> + + <div class="small-8 columns"> + <select name="encryption_policy" class="encr" disabled="disabled"> + <option id="NOT_ENCRYPTED">{% trans "NOT_ENCRYPTED" %}</option> + <option id="ENCRYPTED">{% trans "ENCRYPTED" %}</option> + </select> + <small class="error">Please select group encryption policy.</small> + </div> + + </div> </div> </div> <!-- Group Existance visibility --> <div class="row"> - <div class="small-4 columns"> - <label for="right-label" class="right inline">{% trans "Group Existance visibility" %}</label> - </div> - <div class="small-4 small-pull-4 columns"> - <select name="visibility_policy" class="visibility_policy" disabled="disabled"> - <option id="ANNOUNCED">{% trans "ANNOUNCED" %}</option> - <option id="NOT_ANNOUNCED">{% trans "NOT_ANNOUNCED" %}</option> - </select> - <small class="error">Please select group visibility policy.</small> + <div class="small-12 medium-6 medium-centered columns"> + <div class="row"> + + <div class="small-4 columns"> + <label for="right-label" class="inline">{% trans "Group Existance visibility" %}</label> + </div> + + <div class="small-8 columns"> + <select name="visibility_policy" class="visibility_policy" disabled="disabled"> + <option id="ANNOUNCED">{% trans "ANNOUNCED" %}</option> + <option id="NOT_ANNOUNCED">{% trans "NOT_ANNOUNCED" %}</option> + </select> + <small class="error">Please select group visibility policy.</small> + </div> + + </div> </div> </div> {% endcomment %} @@ -161,25 +258,56 @@ <!-- agency type --> <div class="row"> - <div class="small-4 columns"> - <label for="right-label" class="right inline">{% trans "Group Agency Types" %}</label> - </div> - {% get_group_agency_types as agency_types %} - <div class="small-4 small-pull-4 columns"> - <select name="agency_type" class="agencygrp"> - {% for each in agency_types %} - <option id="{{each}}">{{each}}</option> - {% endfor %} - </select> - <small class="error">Please select group agency type.</small> + <div class="small-12 medium-6 medium-centered columns"> + <div class="row"> + <div class="small-4 columns"> + <label for="right-label" class="inline">{% trans "Group Agency Types" %}</label> + </div> + + {% get_group_agency_types as agency_types %} + <div class="small-8 columns"> + <select name="agency_type" class="agencygrp"> + {% for each_agency_type in agency_types %} + <option {% if each_agency_type == node.agency_type %}selected=selected{% endif %}> + {{each_agency_type}} + </option> + {% endfor %} + </select> + <small class="error">Please select group agency type.</small> + </div> + + </div> </div> </div> + + <!-- description --> + + <!-- <div class="small-12 medium-6 medium-centered columns"> --> + <dl class="accordion row" title="Click to Add/Edit Description" data-accordion> + <dd class="accordion-navigation small-12 medium-6 medium-centered columns"> + + <a href="#content_org"> + <label for="right-label" class=""> + {% if node.content_org %}Edit{% else %}Add{% endif %} {% trans "Description" %} + </label> + </a> + + <div id="content_org" class="content"> + {% include "ndf/add_editor.html" with var_name="content_org" var_placeholder="Enter the content here" var_value=node.content_org|default_if_none:"" node_id=node.pk %} + </div> + + </dd> + </dl> <br/> <div class="row"> - <div class="small-6 small-push-2 columns"> - <input type="submit" value="Create Group" id="grpsubmit" class="button expand"> + <div class="small-12 medium-6 medium-centered columns"> + {% if node %} + <input type="submit" value="Save Changes" id="group-submit" class="button expand"> + {% else %} + <input type="submit" value="Create Group" id="group-submit" class="button expand"> + {% endif %} </div> </div> @@ -241,269 +369,3 @@ // </script> {% endblock %} - - - - - -<!-- ================== following is commented old template structure ================== --> - - - - - -{% comment %} - -{% cache 300 create_group request.LANGUAGE_CODE %} -{% block title %} Create a new group {% endblock %} - -{% block meta_content %} - {% blocktrans %} - <h3>Types of Groups</h3> - <h5>Open Groups</h5> - <p class="subheader">Open groups are ideal for projects that require a high level of collaboration and participation. Any metastudio user can join this group without prior approval</p> - <h5>Closed Groups</h5> - <p class="subheader">Closed groups are ideal for projects that require restricted access to content and documents. Users can only join after their membership request is approved or have been invited.</p> - {% endblocktrans %} -{% endblock %} - -{% block related_content %} - {% if groups %} - <b>{% trans " Existing Groups:" %}</b> - - {% get_existing_groups_excluding_username as groups%} - {% for items in groups %} - <br>{{items.name|truncatechars:25}} - {% endfor %} - {% endif %} -{% endblock %} -{% endcache %} - -{% block body_content %} - - <h2>{% trans "Create a new user group" %}</h2> - - <form id="create_group" class="row" method="post" action="{% url 'create_group' group_id %}"> - {% csrf_token %} - {% cache 3600 create_group request.LANGUAGE_CODE %} - <div class="small-12 columns" style='display:table; border:1px; border-spacing:10px; '> - <div style='display:table-row;' > - <div style='display:table-cell;'> - <font size="3">{% trans "Name of the Group" %}</font> - </div> - <div style='display:table-cell;'> - <input type="text" id="group_name" name="groupname" placeholder="Enter Group Name"> - <label id="message" style="display:none; color:red"></label> - <!-- <div id="message" style="display:none; color:red"></div> --> - </div> - - <div style='display:table-cell;'> - <font size="3" >{% trans "Group Type" %}</font> - </div> - <div style='display:table-cell;'> - <select name="group_type" class="gtype"> - <option id="PUBLIC">{% trans "PUBLIC" %}</option> - <option id="PRIVATE">{% trans "PRIVATE" %}</option> - <option id="ANONYMOUS">{% trans "ANONYMOUS" %}</option> - </select> - </div> - </div> - - <div style='display:table-row;'> - <div style='display:table-cell;'> - <font size="3" >Group Editing policy</font> - </div> - <div style='display:table-cell;'> - <select name="edit_policy" class="editp"> - <option id="EDITABLE_NON_MODERATED">{% trans "EDITABLE_NON_MODERATED" %}</option> - <option id="EDITABLE_MODERATED">{% trans "EDITABLE_MODERATED" %}</option> - <option id="NON_EDITABLE">{% trans "NON_EDITABLE" %}</option> - </select> - </div> - <div style='display:table-cell;'> - <font size="3" >Group Subscription policy</font> - </div> - <div style='display:table-cell;'> - <select name="subscription_policy" class="subscptn" disabled="disabled"> - <option id="OPEN">{% trans "OPEN" %}</option> - <option id="BY_REQUEST">{% trans "BY_REQUEST" %}</option> - <option id="BY_INVITATION">{% trans "BY_INVITATION" %}</option> - </select> - </div> - </div> - - <div style='display:table-row;'> - <div style='display:table-cell;'> - <font size="3" >{% trans "Group Agency Types" %}</font> - </div> - {% get_group_agency_types as agency_types %} - <div style='display:table-cell;'> - <select name="agency_type" class="agencygrp"> - {% for each in agency_types %} - <option id="{{each}}">{{each}}</option> - {% endfor %} - </select> - </div> - - <div style='display:table-cell;'> - <font size="3">{% trans "Group Member Visibility" %}</font> - </div> - <div style='display:table-cell;'> - <select name="member" class="mem" disabled="disabled"> - <option id="DISCLOSED_TO_MEM">{% trans "DISCLOSED_TO_MEM" %}</option> - <option id="NOT_DISCLOSED_TO_MEM">{% trans "NOT_DISCLOSED_TO_MEM" %}</option> - </select> - </div> - </div> - - <div style='display:table-row;'> - <div style='display:table-cell;'> - <font size="3" >{% trans "Group Encryption policy" %}</font> - </div> - <div style='display:table-cell;'> - <select name="encryption" class="encr" disabled="disabled"> - <option id="NOT_ENCRYPTED">{% trans "NOT_ENCRYPTED" %}</option> - <option id="ENCRYPTED">{% trans "ENCRYPTED" %}</option> - </select> - </div> - - <div style='display:table-cell;'> - <font size="3" >{% trans "Group Existance visibility" %}</font> - </div> - <div style='display:table-cell;'> - <select name="existance" class="existance" disabled="disabled"> - <option id="ANNOUNCED">{% trans "ANNOUNCED" %}</option> - <option id="NOT_ANNOUNCED">{% trans "NOT_ANNOUNCED" %}</option> - </select> - </div> - </div> - <div style='display:table-row;'> - <div style='display:table-cell;' colspan='2' align="middle"> - <!-- <input type="button" id="savegrp" value="Create Group" class="button" onClick="check_values()"> - <input type="submit" id="grpsubmit" value="Create Group" class="button" style="visibility:hidden" > --> - <input type="submit" value="Create Group" id="grpsubmit" class="button"> - </div> - </div> - <!-- <input type="hidden" id="nodes_list" value="{{nodes_list}}"> --> - </div> - {% endcache %} - </form> - -{% endblock %} - - -{% block head %} -<script type="text/javascript"> - /* - function check_group_name() - { - var gname=$("#group_name").val(); - $.ajax({ - url: '/home/group/check_group/', - data: {gname:gname}, - success: function(data){ - if (data=="success"){ - alert("group already exists"); - $("#group_name").val(""); - $("#group_name").focus(); - } - } - }); //end_ajax - } - - function check_values() - { - check_group_name(); - var gpname = $("#group_name").val(); - if (gpname == "") - { - alert("Group name can not be empty") - $("#group_name").focus(); - } - else - { - $("#grpsubmit").trigger("click"); - } - } - */ - - $(document).ready(function() - { - /* - $("#group_name").change(function(){ - var name = $("#group_name").val().trim(); - var nodes = $("#nodes_list").val(); - if (nodes.indexOf(name) > 0) - { - $("#message").css("display", "block"); - $("#message").html("Name '"+ name +"' already exist .. Please choose another name"); - $("#group_name").val(""); - } - else - { - $("#message").css("display", "none"); - } - }); - */ - - // New Form: Conditional Display - $(".login-mode").change(function(){ - /* Hide other options if anonymous login is allowed */ - $("#closed-group").slideToggle(); - }); - - $("#member-mode").slideToggle(); - $("[name='join-mode']").change(function(){ - /* Hide invitation options if open membership */ - $("#member-mode").slideToggle(); - }); - - $("[name='edit-mode']").change(function(){ - /* Hide moderation options if editing is disabled */ - $("#moderate-mode").slideToggle(); - }); - - // $("#group_name").focusout(function(){ - // check_group_name(); - // }); //end_focusout - }); //end_document_ready - -</script> -{% endblock %} - -{% block script %} - - $("#node_search_form").parent().hide(); - - // method to provide autocomplete/intellisence of forum names - - $("#create_group").submit(function(event){ - var name = $("#group_name").val().trim().toLowerCase(); - var nodes = {{nodes_list|safe}} - var val_chk = name.search(/mod$/gi) - $("#message").css("display", "none"); - if (name != "") - { - if(val_chk == -1){ - if (nodes.indexOf(name) >= 0) - { - $("#message").css("display", "block"); - $("#message").text("Group '"+ name +"' already exist. Please choose another name"); - event.preventDefault(); - } - } - else if (val_chk != -1){ - $("#message").css("display", "block"); - $("#message").text("Name cannot include 'Mod'."); - event.preventDefault(); - } - } - else if (name == ""){ - $("#message").css("display", "block"); - $("#message").text("Group name cannot be empty."); - event.preventDefault(); - } - }); - -{% endblock %} -{% endcomment %}
\ No newline at end of file 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 13e8bd3..b4f9413 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 @@ -325,7 +325,8 @@ ul#navigation li a.last { </small></h4> {% endif %} - <h1><span itemprop="{{schema.1.name}}" class='node'>{{node.altnames|default_if_none:node.name}}</span> + <h1><span itemprop="{{schema.1.name}}" class='node'> + {% if node.altnames %}{{node.altnames}}{% else %}{{node.name}}{% endif %}</span> {% if node %} {% get_publish_policy request groupid node as group_policy %} {% if group_policy == "allow" %} @@ -1280,7 +1281,8 @@ ul#navigation li a.last { <div class="medium-6 columns"> {% edit_policy groupid node request.user as status %} - {% if user.is_authenticated and status == "allow" and user_access == "allow" %} + + {% if user.is_authenticated and status == "allow" and user_access == "allow" and "Group" in group_object.member_of_names_list %} {% get_edit_url node.pk as edit_url %} {% check_group node as is_group %} @@ -1295,11 +1297,13 @@ ul#navigation li a.last { <a href="{% url edit_url group_id node %}" class="tiny round button edit"><i class="fi-pencil"></i> {% trans "Edit" %}</a> {% endif %} {% endif %} + </div> <div class="medium-6 columns"> <!-- This button publishes the drafted resource --> - {% if node %} + + {% if node and "Group" in group_object.member_of_names_list %} {% get_publish_policy request groupid node as group_policy %} {% if group_policy == "allow" %} @@ -1331,6 +1335,8 @@ ul#navigation li a.last { </div> <div class="medium-7 columns"> + + {% get_create_url node.pk as create_url %} {% if is_group %} @@ -1373,18 +1379,19 @@ ul#navigation li a.last { {% endif %} {% endif %} {% endif %} + + {% endif %} </div> <div class ="rows"> - {% if user.is_authenticated %} + + {% if user.is_authenticated and "Group" in group_object.member_of_names_list%} <div class= "medium-12 columns" > <a href = "{% url 'node_version' groupid node.pk %}" class="tiny round button" > <label style = 'width:8%;'> History </label> </a> </div> {% endif %} </div> - {% endif %} - {% if node %} {% check_group node as is_group %} {% if is_group %} @@ -1392,7 +1399,7 @@ ul#navigation li a.last { {% get_group_policy node request.user as policy %} {% get_prior_post_node group_id as groupname %} - {% if group_object.edit_policy == 'EDITABLE_MODERATED' and "Group" in group_object.member_of_names_list %} + {% if "Group" in group_object.member_of_names_list %} <input type="hidden" id="groupname" value="{{node}}"> {% if user.is_authenticated %} {% if user_access == "allow" %} @@ -1450,13 +1457,17 @@ ul#navigation li a.last { {% ifequal group_object.edit_policy "EDITABLE_MODERATED" %} {% if request.user.id in group_object.group_admin or request.user.is_superuser or request.user.id == group_object.created_by %} - <a class="tiny expand button" href="{% url 'moderation' group_name_tag %}"> - Moderate Resources - </a> + {% if 'ModeratingGroup' in group_object.member_of_names_list %} + <a class="tiny expand button" href="{% url 'moderation' group_name_tag %}"> + Moderate Resources + </a> + {% endif %} - <a class="tiny expand button" href="{% url 'all_under_moderation' group_id %}"> - Moderation Status - </a> + {% if 'Group' in group_object.member_of_names_list %} + <a class="tiny expand button" href="{% url 'all_under_moderation' group_id %}"> + Moderation Status + </a> + {% endif %} {% endif %} {% endifequal %} @@ -1502,7 +1513,6 @@ ul#navigation li a.last { </li> --> - {% ifnotequal group_object.edit_policy "EDITABLE_MODERATED" %} <br/> <div class="label-list"> <b>{% trans "Tags" %}</b><br/> @@ -1516,6 +1526,8 @@ ul#navigation li a.last { {% endif %} </div> + + {% ifnotequal group_object.edit_policy "EDITABLE_MODERATED" %} {% if "File" in node.member_of_names_list or "Page" in node.member_of_names_list %} <div> diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templatetags/ndf_tags.py b/gnowsys-ndf/gnowsys_ndf/ndf/templatetags/ndf_tags.py index 27272d0..8be58d3 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templatetags/ndf_tags.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templatetags/ndf_tags.py @@ -1514,6 +1514,34 @@ def get_group_type(group_id, user): except Exception as e: raise Http404(e) + +@get_execution_time +@register.assignment_tag +def get_possible_group_type_values(): + ''' + Returns TYPES_OF_GROUP defined in models.py + ''' + return TYPES_OF_GROUP + + +@get_execution_time +@register.assignment_tag +def get_possible_edit_policy_values(): + ''' + Returns EDIT_POLICY defined in models.py + ''' + return EDIT_POLICY + + +@get_execution_time +@register.assignment_tag +def get_allowed_moderation_levels(): + ''' + Returns GSTUDIO_ALLOWED_GROUP_MODERATION_LEVELS from settings. + ''' + return GSTUDIO_ALLOWED_GROUP_MODERATION_LEVELS + + @get_execution_time @register.assignment_tag def check_accounts_url(url_path): diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/urls/group.py b/gnowsys-ndf/gnowsys_ndf/ndf/urls/group.py index fe7803a..0b82cc3 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/urls/group.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/urls/group.py @@ -1,11 +1,12 @@ from django.conf.urls import patterns, url +from gnowsys_ndf.ndf.views.group import GroupCreateEditHandler urlpatterns = patterns('gnowsys_ndf.ndf.views.group', url(r'^[/]$', 'group', name='group'), url(r'^/(?P<app_id>[\w-]+)$', 'group', name='group'), - url(r'^/create_group/', 'create_group', name='create_group'), + url(r'^/create_group/', GroupCreateEditHandler.as_view(), {'action': 'create'}, name='create_group'), + url(r'^/edit_group/', GroupCreateEditHandler.as_view(), {'action': 'edit'}, name='edit_group'), url(r'^/group_publish/(?P<node>[\w-]+)$', 'publish_group', name='publish_group'), - url(r'^/edit_group/', 'edit_group', name='edit_group'), url(r'^/switch_group/(?P<node_id>[\w-]+)$', 'switch_group', name='switch_group'), url(r'^/app_selection/', 'app_selection', name='app_selection'), url(r'^/create_sub_group/', 'create_sub_group', name='create_sub_group'), diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/group.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/group.py index e246b22..bc5a8c6 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/views/group.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/group.py @@ -9,6 +9,7 @@ from django.core.urlresolvers import reverse from django.shortcuts import render_to_response # , render from django.template import RequestContext # from django.template.defaultfilters import slugify +from django.utils.decorators import method_decorator from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User from django.views.generic import View @@ -26,11 +27,19 @@ from gnowsys_ndf.ndf.models import node_collection, triple_collection from gnowsys_ndf.ndf.views.ajax_views import set_drawer_widget from gnowsys_ndf.ndf.templatetags.ndf_tags import get_all_user_groups # get_existing_groups from gnowsys_ndf.ndf.views.methods import * +from gnowsys_ndf.ndf.org2any import org2html # ###################################################################################################################################### gst_group = node_collection.one({"_type": "GSystemType", 'name': u"Group"}) app = gst_group + +group_gst = node_collection.one({'_type': 'GSystemType', 'name': u'Group'}) +moderating_group_gst = node_collection.one({'_type': 'GSystemType', 'name': u'ModeratingGroup'}) + +file_gst = node_collection.one({'_type': 'GSystemType', 'name': 'File'}) +page_gst = node_collection.one({'_type': 'GSystemType', 'name': 'Page'}) +task_gst = node_collection.one({'_type': 'GSystemType', 'name': 'Task'}) # ###################################################################################################################################### # V I E W S D E F I N E D F O R G A P P -- ' G R O U P ' @@ -44,20 +53,23 @@ class CreateGroup(object): def __init__(self, request): super(CreateGroup, self).__init__() self.request = request + self.moderated_groups_member_of = ['ProgramEventGroup',\ + 'CourseEventGroup', 'PartnerGroup', 'ModeratingGroup'] def is_group_exists(self, arg_group_name): ''' - checks if group with the given name exists. - Returns True: If group exists. + Checks if group with the given name exists. + Returns Bool. + - True: If group exists. + - False: If group doesn't exists. ''' - name = arg_group_name - group = node_collection.find_one({ - '_type': 'Group', - 'name': unicode(name) - }) + + group = node_collection.find_one({'_type': 'Group', 'name': unicode(arg_group_name)}) + if group: return True + else: return False @@ -65,24 +77,31 @@ class CreateGroup(object): def get_group_fields(self, group_name, **kwargs): ''' function to fill the empty group object with values supplied. - group information may be sent either from "request" or from "kwargs". + - group name is must and it's first argument. + - group information may be sent either from "request" or from "kwargs". # If arg is kwargs, provide following dict as kwargs arg to this function. group_fields = { - 'group_altnames': '', 'group_type': '', 'edit_policy': '', - 'agency_type': '', 'moderation_level': '' + 'altnames': '', 'group_type': '', 'edit_policy': '', + 'agency_type': '', 'moderation_level': '', + ...., ... } + # call in following way class_instance_var.get_group_fields(group_name, **group_fields) + (NOTE: use ** before dict variables, in above case it's group_fields so it's: **group_fields) ''' # getting the data into variables name = group_name - if kwargs.get('group_altnames', ''): - altnames = kwargs.get('group_altnames', name) + # to check if existing group is getting edited + node_id = kwargs.get('node_id', None) + + if kwargs.get('altnames', ''): + altnames = kwargs.get('altnames', name) else: - altnames = self.request.POST.get('alt_groupname', "").strip() + altnames = self.request.POST.get('altnames', name).strip() if kwargs.get('group_type', ''): group_type = kwargs.get('group_type', '') @@ -124,6 +143,11 @@ class CreateGroup(object): else: agency_type = self.request.POST.get('agency_type', 'Other') + if kwargs.get('content_org', ''): + content_org = kwargs.get('content_org', '') + else: + content_org = self.request.POST.get('content_org', '') + # whenever we are passing int: 0, condition gets false # therefor casting to str if str(kwargs.get('moderation_level', '')): @@ -131,15 +155,26 @@ class CreateGroup(object): else: moderation_level = self.request.POST.get('moderation_level', '-1') - # instantiated empty group object - group_obj = node_collection.collection.Group() + if node_id: + # Existing group: if node_id exists means group already exists. + # So fetch that group and use same object to override the fields. + group_obj = node_collection.one({'_id': ObjectId(node_id)}) + else: + # New group: instantiate empty group object + group_obj = node_collection.collection.Group() - # filling the values with variables in empty group object + # filling the values with variables in group object: group_obj.name = unicode(name) group_obj.altnames = unicode(altnames) - group_obj.member_of.append(gst_group._id) - group_obj.type_of.append(gst_group._id) + + # while doing append operation make sure to-be-append is not in the list + if gst_group._id not in group_obj.member_of: + group_obj.member_of.append(gst_group._id) + + if gst_group._id not in group_obj.type_of: + group_obj.type_of.append(gst_group._id) + # user related fields: user_id = int(self.request.user.id) group_obj.created_by = user_id group_obj.modified_by = user_id @@ -150,6 +185,7 @@ class CreateGroup(object): if user_id not in group_obj.group_admin: group_obj.group_admin.append(user_id) + # group specific fields: group_obj.group_type = group_type group_obj.access_policy = access_policy group_obj.edit_policy = edit_policy @@ -159,13 +195,24 @@ class CreateGroup(object): group_obj.encryption_policy = encryption_policy group_obj.agency_type = agency_type + # org-content + if group_obj.content_org != content_org: + group_obj.content_org = content_org + + # Required to link temporary files with the current user who is: + usrname = self.request.user.username + filename = slugify(name) + "-" + slugify(usrname) + "-" + ObjectId().__str__() + group_obj.content = org2html(content_org, file_prefix=filename) + is_changed = True + # decision for adding moderation_level if group_obj.edit_policy == "EDITABLE_MODERATED": group_obj.moderation_level = int(moderation_level) else: - group_obj.moderation_level = -1 + group_obj.moderation_level = -1 # non-moderated group. - group_obj.status == u"PUBLISHED" + # group's should not have draft stage. So publish them: + group_obj.status = u"PUBLISHED" # returning basic fields filled group object return group_obj @@ -176,12 +223,17 @@ class CreateGroup(object): def create_group(self, group_name, **kwargs): ''' Creates group with given args. - Returns tuple containing True/False, sub_group_object/error. + - Takes group name as compulsory argument. + - Returns tuple containing: (True/False, sub_group_object/error) ''' + node_id = kwargs.get('node_id', None) + # print "node_id : ", node_id + # checking if group exists with same name - if not self.is_group_exists(group_name): + if not self.is_group_exists(group_name) or node_id: + # print "group_name : ", group_name group_obj = self.get_group_fields(group_name, **kwargs) try: @@ -195,49 +247,68 @@ class CreateGroup(object): else: return False, 'Group with same name exists.' - # --- END --- create_group() ------ + # --- END --- create_group() --- def get_group_edit_policy(self, group_id): ''' Returns "edit_policy" of the group. + - Takes group_id as compulsory and only argument. + - Returns: either "edit_policy" or boolian "False". ''' + group_obj = node_collection.one({'_id': ObjectId(group_id)}) + if group_obj: return group_obj.edit_policy + else: return False # --- END --- get_group_edit_policy() ------ + def get_group_type(self, group_id): ''' Returns "group_type" of the group. + - Takes group_id as compulsory and only argument. + - Returns: either "group_type" or boolian "False". ''' + group_obj = node_collection.one({'_id': ObjectId(group_id)}) + if group_obj: return group_obj.group_type + else: return False # --- END --- get_group_type() ------ + def get_all_subgroups_obj_list(self, group_id): ''' Returns mongokit (find) cursor of sub-group documents. + - Takes group_id as compulsory and only argument. ''' + group_obj = node_collection.one({'_id': ObjectId(group_id)}) # check if group has post_node. Means it has sub-group/s if group_obj and group_obj.post_node: return node_collection.find({'_id': {'$in': group_obj.post_node} }) + else: return False # --- END --- get_all_subgroups_obj_list() ------ + def get_all_subgroups_member_of_list(self, group_id): ''' Returns list of names of "member_of" of sub-groups. + - Takes group_id as compulsory and only argument. ''' + sg_member_of_list = [] + # get all underlying groups all_sg = self.get_all_subgroups_obj_list(group_id) if all_sg: @@ -272,7 +343,8 @@ class CreateSubGroup(CreateGroup): # get basic fields filled group object group_obj = self.get_group_fields(sub_group_name, **kwargs) - if sg_member_of in ['ProgramEventGroup', 'CourseEventGroup', 'PartnerGroup', 'ModeratingGroup']: + # if sg_member_of in ['ProgramEventGroup', 'CourseEventGroup', 'PartnerGroup', 'ModeratingGroup']: + if sg_member_of in self.moderated_groups_member_of: # overriding member_of field of subgroup member_of_group = node_collection.one({'_type': u'GSystemType', 'name': unicode(sg_member_of)}) @@ -285,10 +357,11 @@ class CreateSubGroup(CreateGroup): else: # for normal sub-groups if not group_obj.group_type: + # if group_type is not specified take it from parent: group_obj.group_type = self.get_group_type(parent_group_id) - if not group_obj.edit_policy: - group_obj.edit_policy = self.get_group_edit_policy(parent_group_id) + # if not group_obj.edit_policy: + # group_obj.edit_policy = self.get_group_edit_policy(parent_group_id) # check if group object's prior_node has _id of parent group, otherwise add one. if ObjectId(parent_group_id) not in group_obj.prior_node: @@ -302,18 +375,12 @@ class CreateSubGroup(CreateGroup): Creates sub-group with given args. Returns tuple containing True/False, sub_group_object/error. ''' - # print "kwargs : ", kwargs try: parent_group_id = ObjectId(parent_group_id) except: parent_group_name, parent_group_id = get_group_name_id(group_id) - # except: # it's parent group's name (str). so dereference to get "_id" - # parent_group_obj = node_collection.one({"_type": {"$in": ["Group", "Author"] }, "name": unicode(parent_group_id)}) - # # checking if group_obj is valid - # if parent_group_obj: - # parent_group_id = parent_group_obj._id # checking feasible conditions to add this sub-group if not self.check_subgroup_feasibility(parent_group_id, sg_member_of): @@ -346,21 +413,25 @@ class CreateSubGroup(CreateGroup): - parent group's edit_policy - child group's member_of Returns True if it is OK to create sub-group with suplied fields. + Otherwise returns False. ''' if sg_member_of == 'Group': + # i.e: group is normal-sub-group. return True - elif sg_member_of in ['ProgramEventGroup', 'CourseEventGroup', 'PartnerGroup', 'ModeratingGroup']: + # elif sg_member_of in ['ProgramEventGroup', 'CourseEventGroup', 'PartnerGroup', 'ModeratingGroup']: + elif sg_member_of in self.moderated_groups_member_of: if self.get_group_edit_policy(parent_group_id) == 'EDITABLE_MODERATED': # if current sub-groups member_of is in parent's any one of the sub-group, - # means sub-group with current property exists in/for parent group. + # i.e: sub-group with current property exists in/for parent group. # And no sibling with these property can exists together (like normal sub-groups). if sg_member_of in self.get_all_subgroups_member_of_list(parent_group_id): return False else: return True + else: return False @@ -390,7 +461,7 @@ class CreateSubGroup(CreateGroup): def get_particular_member_of_subgroup(self, group_id, member_of): ''' - Returns sub-group having particular member_of. + Returns sub-group-object having supplied particular member_of. Else return False ''' member_of = node_collection.one({'_type': 'GSystemType', 'name': unicode(member_of)}) @@ -399,10 +470,11 @@ class CreateSubGroup(CreateGroup): '_type': 'Group', 'prior_node': {'$in': [ObjectId(group_id)]}, 'member_of': member_of._id - }) + }) if group_obj: return group_obj + else: return False @@ -419,40 +491,61 @@ class CreateModeratedGroup(CreateSubGroup): super(CreateSubGroup, self).__init__(request) self.request = request self.edit_policy = 'EDITABLE_MODERATED' + # maintaining dict of group types and their corresponding sub-groups altnames. + # referenced while creating new moderated sub-groups. self.altnames = { 'ModeratingGroup': [u'Clearing House', u'Curation House'], 'ProgramEventGroup': [], 'CourseEventGroup': [] } - def create_new_moderated_group(self, group_name, moderation_level=1, **kwargs): + + def create_edit_moderated_group(self, group_name, moderation_level=1, **kwargs): ''' - Creates top level group with given args. - Returns tuple containing True/False, sub_group_object/error. + Creates/Edits top level group as well as underlying sub-mod groups. + - Takes group_name as compulsory argument and optional kwargs. + - Returns tuple: (True/False, top_group_object/error) ''' - if not self.is_group_exists(group_name): + # retrieves node_id. means it's edit operation of existing group. + node_id = kwargs.get('node_id', None) + + # checking if group exists with same name + if not self.is_group_exists(group_name) or node_id: + # values will be taken from POST form fields - group_obj = self.get_group_fields(group_name) + group_obj = self.get_group_fields(group_name, node_id=node_id) try: group_obj.save() except Exception, e: # if any errors return tuple with False and error - print e + # print e return False, e - # self.add_subgroup_to_parents_postnode(parent_group_id, group_obj._id, sg_member_of) - parent_group_id = group_obj._id - for each_sg_iter in range(0, int(moderation_level)): - result = self.add_moderation_level(parent_group_id, 'ModeratingGroup') - # result is tuple of (bool, newly-created-sub-group-obj) - if result[0]: - parent_group_id = result[1]._id - else: - # if result is False, means sub-group is not created. - # In this case, there is no point to go ahead and create subsequent sub-group. - break + if node_id: + # i.e: Editing already existed group object. + # method modifies the underlying mod-sub-group structure and doesn't return anything. + self.check_reset_mod_group_hierarchy(top_group_obj=group_obj) + + else: + # i.e: New group is created and following code will create + # sub-mod-groups as per specified in the form. + parent_group_id = group_obj._id + + for each_sg_iter in range(0, int(moderation_level)): + + result = self.add_moderation_level(parent_group_id, 'ModeratingGroup') + + # result is tuple of (bool, newly-created-sub-group-obj) + if result[0]: + # overwritting parent's group_id with currently/newly-created group object + parent_group_id = result[1]._id + + else: + # if result is False, means sub-group is not created. + # In this case, there is no point to go ahead and create subsequent sub-group. + break return True, group_obj @@ -463,18 +556,23 @@ class CreateModeratedGroup(CreateSubGroup): def add_moderation_level(self, parent_group_id, sg_member_of, increment_mod_level=False): ''' Adds the moderation sub group to parent group. - - expects "_id/name" of parent and sub_group's "member_of". + - compulsory argument: + - "_id/name" of parent + - sub_group's "member_of": <str>. - increment_mod_level: If you want to add next moderation subgroup, despite of moderation_level is 0. In this case, if value is True, moderation_level of all top hierarchy groups will be updated by 1. ''' + # getting group object parent_group_object = get_group_name_id(parent_group_id, get_obj=True) # pg: parent group pg_name = parent_group_object.name pg_moderation_level = parent_group_object.moderation_level + # possible/next mod group name: + # sg: sub group sg_name = pg_name + unicode('_mod') # no need to check following here, because it's being checked at sub-group creation time. @@ -509,38 +607,49 @@ class CreateModeratedGroup(CreateSubGroup): sg_altnames = sg_name # create new sub-group and append it to parent group: - sub_group = self.create_subgroup(parent_group_id, sg_name, \ + sub_group_result_tuple = self.create_subgroup(parent_group_id, sg_name, \ sg_member_of, moderation_level=(pg_moderation_level-1), \ - group_altnames=sg_altnames) + altnames=sg_altnames) - return sub_group + return sub_group_result_tuple def increment_hierarchy_mod_level(self, group_id): ''' - Raises moderation_level by one of all the groups in the hierarchy. + Raises moderation_level by one of all the groups (right from top) in the hierarchy. + Takes group_id as compulsory argument. + Returns boolian True/False, depending on Success/Failure. ''' try: group_id = ObjectId(group_id) - except: group_name, group_id = get_group_name_id(group_id) + # firstly getting all the sub-group-object list result = self.get_all_group_hierarchy(group_id) if result[0]: + # get group's object's list into variables group_list = result[1] + # flag is_updated = False for each_group in group_list: + + # change flag to True is_updated = True + # adding +1 to existing moderation_level - each_group.moderation_level += 1 - each_group.save() + updated_moderation_level = each_group.moderation_level + 1 + + node_collection.collection.update({'_id': each_group._id}, + {'$set': {'moderation_level': updated_moderation_level } }, + upsert=False, multi=False ) if is_updated: return True + else: return False @@ -549,48 +658,101 @@ class CreateModeratedGroup(CreateSubGroup): return False - def get_all_group_hierarchy(self, group_id): + def get_all_group_hierarchy(self, group_id, top_group_obj=None, with_deleted=False): ''' - Provide _id of any of the group and get list of all groups. + Provide _id of any of the group in the hierarchy and get list of all groups. Order will be from top to bottom. + Arguments it takes: + - "group_id": Takes _id of any of the group among hierarchy + - "top_group_obj": Takes object of top group (optional). + To be used in certain conditions. + - "with_deleted": Takes boolian value. + If it's True - returns all the groups irrespective of: + post_node and status field whether it's deleted or not. + To be used catiously in certain conditions. e.g: [top_gr_obj, sub_gr_obj, sub_sub_gr_obj, ..., ...] NOTE: this function will return hierarchy of only groups with edit_policy: 'EDITABLE_MODERATED' ''' - top_group = self.get_top_group_of_hierarchy(group_id) + # It will be good to go through proper flow. + # Despite of either argument of top_group_obj is provided or not. + # That's why using following step: + result = self.get_top_group_of_hierarchy(group_id) - if top_group[0]: + if result[0]: # getting object of top group - top_group = top_group[1] + top_group = result[1] - else: # fail to get top group - return top_group + elif top_group_obj: + # if top group is in args and result if negative. + top_group = top_group_obj + else: + # fail to get top group + return result + + # starting list with top-group's object: all_sub_group_list = [top_group] + # taking top_group's object in group_obj. which will be used to start while loop group_obj = top_group - while group_obj and group_obj.post_node: + # loop till overwritten group_obj exists and + # if group_obj.post_node exists or with_deleted=True + while group_obj and (group_obj.post_node or with_deleted): + + # getting previous group objects name before it get's overwritten + temp_group_obj_name = group_obj.name + group_obj = self.get_particular_member_of_subgroup(group_obj._id, 'ModeratingGroup') + + # if in the case group_obj doesn't exists and with_deleted=True + if with_deleted and not group_obj: + + try: + temp_group_name = unicode(group_obj_name + '_mod') + except: + temp_group_name = unicode(temp_group_obj_name + '_mod') + + # firing named query here. with the rule of group names are unique and cannot be edited. + group_obj = node_collection.one({'_type': u'Group', + 'name': temp_group_name}) + + # required to break the while loop along with with_deleted=True + if not group_obj: + return True, all_sub_group_list + + # group object found with regular conditions if group_obj: + group_obj_name = group_obj.name all_sub_group_list.append(group_obj) + + # group object not found with regular conditions and arg: with_deleted=False (default val) else: - return False, [top_group] + # return partially-completed/incompleted (at least with top-group-obj) group hierarchy list. + return False, all_sub_group_list + # while loop completed. now return computed list return True, all_sub_group_list def get_top_group_of_hierarchy(self, group_id): ''' - getting top group object of hierarchy. - Returns mongokit object of top group. + For getting top group object of hierarchy. + Arguments: + - group_id: _id of any of the group in the hierarchy. + Returns top-group-object. ''' curr_group_obj = node_collection.one({'_id': ObjectId(group_id)}) # loop till there is no end of prior_node or till reaching at top group. while curr_group_obj and curr_group_obj.prior_node: + + # fetching object having curr_group_obj in it's prior_node: curr_group_obj = node_collection.one({'_id': curr_group_obj.prior_node[0]}) + # hierarchy does exists for 'EDITABLE_MODERATED' groups. + # if edit_policy of fetched group object is not 'EDITABLE_MODERATED' return false. if curr_group_obj.edit_policy != 'EDITABLE_MODERATED': return False, "One of the group: " + str(curr_group_obj._id) \ + " is not with edit_policy: EDITABLE_MODERATED." @@ -598,10 +760,338 @@ class CreateModeratedGroup(CreateSubGroup): # send overwritten/first curr_group_obj's "_id" return True, curr_group_obj + + def check_reset_mod_group_hierarchy(self, top_group_obj): + ''' + This is the method to reset/adjust all the group objects in the hierarchy, + right from top group to last group. + Method works-on/reset's/updates following fields of group object \ + according to top group object's fields: + - moderation_level + - post_node + - status + - altnames + - member_of + NOTE: "prior_node" is not updated or not taken into consideration. + can be used in future/in-some-cases. + Argument: + - top_group_obj: Top group's object + ''' + + # instantiate variable group_moderation_level. + # used for setting moderation_level of all groups + group_moderation_level = 0 + + # last sub-groups _id + last_sg_id = top_group_obj._id + + # getting all the group hierarchy irrespective of + # it's fields like post_node, moderation_level, status + result = self.get_all_group_hierarchy(top_group_obj._id, \ + top_group_obj=top_group_obj, with_deleted=True) + + if result[0]: + + # getting all the group objects hierarchy in the list: + all_sub_group_obj_list = result[1] + # Zero index of all_sub_group_obj_list is top-group. + + # print [g.name for g in all_sub_group_obj_list] + + top_group_moderation_level = top_group_obj.moderation_level + top_group_name = top_group_obj.name + + # overwritting group_moderation_level + group_moderation_level = top_group_moderation_level + + # checking moderation_level hierarchy lists of: + # - list created from iterating over all_sub_group_obj_list and + # - list created from range starts from top_group_obj's moderation_level till 0. + # if these both are same then there is no point in going ahead and do processing. + # bacause there is no changes in the underlying heirarchy. + # So return from here if both lists are equal. + # ml: moderation_level + if [ml.moderation_level for ml in all_sub_group_obj_list] == \ + [m for m in range(top_group_moderation_level, -1, -1)]: + # print "=== return" + return + + # looping through each group object of/in \ + # all_sub_group_obj_list with current iteration index: + for index, each_sg in enumerate(all_sub_group_obj_list): + # print "\n=== group_moderation_level : ", group_moderation_level + # print each_sg.moderation_level, "=== each_sg name : ", each_sg.name + + # getting immediate parent group of current iterated group w.r.t. all_sub_group_obj_list + # pg: parent group + pg_obj = all_sub_group_obj_list[index - 1] if (index > 0) else top_group_obj + pg_id = pg_obj._id + pg_name = pg_obj.name + + # even we need to update altnames field \ + # w.r.t. altnames dict (defined at class level variable) + try: + sg_altnames = self.altnames['ModeratingGroup'][index-1] \ + + u" of " + pg_name + except Exception, e: + # if not found in altnames dict (defined at class level variable) + sg_altnames = each_sg.name + + # do not update altnames field of top group w.r.t altnames dict and + # keep Group gst's id in member_of of top-group's object: + if each_sg._id == top_group_obj._id: + sg_altnames = each_sg.altnames + member_of_id = group_gst._id + else: + member_of_id = moderating_group_gst._id + + # print "=== altnames: ", sg_altnames + + if group_moderation_level > 0: + # print "=== level > 0", each_sg.name + + node_collection.collection.update({'_id': each_sg._id}, + {'$set': { + 'altnames': sg_altnames, + 'member_of': [member_of_id], + 'moderation_level': group_moderation_level, + 'status': u'PUBLISHED' + } + }, + upsert=False, multi=False ) + + # except top-group, add current group's _id in top group's post_node + if pg_id != each_sg._id: + self.add_subgroup_to_parents_postnode(pg_id, each_sg._id, 'ModeratingGroup') + + # one group/element of all_sub_group_obj_list is processed now \ + # decrement group_moderation_level by 1: + group_moderation_level -= 1 + + # update last_sg variables: + last_sg_id = each_sg._id + last_sg_moderation_level = each_sg.moderation_level + + elif group_moderation_level == 0: + # only difference in above level>0 and this level==0 is: + # last/leaf group-node (w.r.t. top_group_object.moderation_level) \ + # of hierarchy should not have post_node. + + # print "=== level == 0", each_sg.name + node_collection.collection.update({'_id': each_sg._id}, + {'$set': { + 'altnames': sg_altnames, + 'member_of': [member_of_id], + 'moderation_level': group_moderation_level, + 'status': u'PUBLISHED', + 'post_node': [] + } + }, + upsert=False, multi=False ) + + # except top-group, add current group's _id in top group's post_node + if pg_id != each_sg._id: + self.add_subgroup_to_parents_postnode(pg_id, each_sg._id, 'ModeratingGroup') + + # one group/element of all_sub_group_obj_list is processed now \ + # decrement group_moderation_level by 1: + group_moderation_level -= 1 + + # update last_sg variables: + last_sg_id = each_sg._id + last_sg_moderation_level = each_sg.moderation_level + + elif group_moderation_level < 0: + # Now these/this are/is already created underlying moderated group's in the hierarchy. + # We do need to update following fields of this group object: + # - moderation_level: -1 + # - status: u"DELETED" + # - member_of: [<_id of Group gst>] + # - post_node: [] + + # While doing above process, resources in these/this group need to be freed. + # So, fetching all the resources in this group and publishing them to top-group + + # print "=== level < 0", each_sg.name + + # getting all the resources (of type: File, Page, Task) under this group: + group_res_cur = node_collection.find({ + 'member_of': {'$in': [file_gst._id, page_gst._id, task_gst._id]}, + 'group_set': {'$in': [each_sg._id]} }) + + # iterating over each resource under this group: + for each_group_res in group_res_cur: + + group_set = each_group_res.group_set + + # removing current sub-groups _id from group_set: + if each_sg._id in group_set: + group_set.pop(group_set.index(each_sg._id)) + + # adding top-group's _id in group_set: + if top_group_obj._id not in group_set: + group_set.append(top_group_obj._id) + + each_group_res.group_set = group_set + each_group_res.status = u'PUBLISHED' + each_group_res.save() + + # updating current sub-group with above stated changes: + node_collection.collection.update({ + '_id': each_sg._id}, + {'$set': { + 'member_of': [group_gst._id], + 'status': u'DELETED', + 'moderation_level': -1, + 'post_node': [] + } + }, upsert=False, multi=False ) + + # updating last_sg variables + last_sg_id = each_sg._id + last_sg_moderation_level = each_sg.moderation_level + + # print "out of for === group_moderation_level", group_moderation_level + + # despite of above looping and iterations, group_moderation_level is > 0 \ + # i.e: new moderated sub-group/s need to be created. (moderation level of parent group has raised). + if group_moderation_level >= 0: + + # range(0, 0) will results: [] and range(0, 1) will results: [0] + # hence, group_moderation_level is need to be increased by 1 + for each_sg_iter in range(0, group_moderation_level+1): + + # print each_sg_iter, " === each_sg_iter", last_sg_id + result = self.add_moderation_level(last_sg_id, 'ModeratingGroup') + # result is tuple of (bool, newly-created-sub-group-obj) + + if result[0]: + last_sg_id = result[1]._id + # print " === new group created: ", result[0].name + + else: + # if result is False, means sub-group is not created. + # In this case, there is no point to go ahead and create subsequent sub-group. + break + # --- END of class CreateModeratedGroup --- # ----------------------------------------- +class GroupCreateEditHandler(View): + """ + Class to handle create/edit group requests. + This class should handle all the types ofgroup create/edit requests. + Currently it supports the functionality for following types of groups: + - Normal Groups + - Moderating Groups + - Pending: + -- Sub Groups + -- CourseEvent Group + -- ProgramEvent Group + """ + @method_decorator(login_required) + @method_decorator(get_execution_time) + def get(self, request, group_id, action): + """ + Catering GET request of group's create/edit. + Render's to create_group template. + """ + + try: + group_id = ObjectId(group_id) + except: + group_name, group_id = get_group_name_id(group_id) + + group_obj = None + nodes_list = [] + + if action == "edit": # to edit existing group + + group_obj = get_group_name_id(group_id, get_obj=True) + + # as group edit will not have provision to change name field. + # there is no need to send nodes_list while group edit. + + elif action == "create": # to create new group + + available_nodes = node_collection.find({'_type': u'Group'}, {'name': 1, '_id': 0}) + + # making list of group names (to check uniqueness of the group): + nodes_list = [str(g_obj.name.strip().lower()) for g_obj in available_nodes] + # print nodes_list + + # why following logic exists? Do we need so? + # if group_obj.status == u"DRAFT": + # group_obj, ver = get_page(request, group_obj) + # group_obj.get_neighbourhood(group_obj.member_of) + + title = action + ' Group' + + # In the case of need, we can simply replace: + # "ndf/create_group.html" with "ndf/edit_group.html" + return render_to_response("ndf/create_group.html", + { + 'node': group_obj, 'title': title, + 'nodes_list': nodes_list, + 'groupid': group_id, 'group_id': group_id + # 'appId':app._id, # 'is_auth_node':is_auth_node + }, context_instance=RequestContext(request)) + # --- END of get() --- + + @method_decorator(login_required) + @method_decorator(get_execution_time) + def post(self, request, group_id, action): + ''' + To handle post request of group form. + To save edited or newly-created group's data. + ''' + + # getting group's object: + group_obj = get_group_name_id(group_id, get_obj=True) + + # getting field values from form: + group_name = request.POST.get('name', '').strip() # hidden-form-field + node_id = request.POST.get('node_id', '').strip() # hidden-form-field + edit_policy = request.POST.get('edit_policy', '') + + # check if group's editing policy is already 'EDITABLE_MODERATED' or + # it was not and now it's changed to 'EDITABLE_MODERATED' or vice-versa. + if (edit_policy == "EDITABLE_MODERATED") or (group_obj.edit_policy == "EDITABLE_MODERATED"): + + moderation_level = request.POST.get('moderation_level', '') + # print "~~~~~~~ ", moderation_level + + # instantiate moderated group + mod_group = CreateModeratedGroup(request) + + # calling method to create new group + result = mod_group.create_edit_moderated_group(group_name, moderation_level, node_id=node_id) + + else: + + # instantiate moderated group + group = CreateGroup(request) + + # calling method to create new group + result = group.create_group(group_name, node_id=node_id) + + # print result[0], "\n=== result : ", result[1].name, "\n\n" + if result[0]: + # operation success: redirect to group-detail page + group_obj = result[1] + group_name = group_obj.name + url_name = 'groupchange' + + else: + # operation fail: redirect to group-listing + group_name = 'home' + url_name = 'group' + + return HttpResponseRedirect( reverse( url_name, kwargs={'group_id': group_name} ) ) + +# ===END of class EditGroup() === + @get_execution_time def group(request, group_id, app_id=None, agency_type=None): @@ -742,152 +1232,78 @@ def group(request, group_id, app_id=None, agency_type=None): }, context_instance=RequestContext(request)) +# @login_required +# @get_execution_time +# def create_group(request, group_id): -@login_required -@get_execution_time -def create_group(request,group_id): - - try: - group_id = ObjectId(group_id) - except: - group_name, group_id = get_group_name_id(group_id) - - # a = CreateSubGroup(request, "home", "moderated") - # print "======= ", a.is_group_exists("jhjh") - # print "--------- ", a.create_group(group_name="kjhk") - # print ".... ", a.get_group_edit_policy(group_id) - # print ".... ", a.get_subgroup_fields(group_id, "jhgjhg") - # print ".... ", a.get_group_edit_policy(group_id) - # try: - # print "--------" - # # print a.create_subgroup('home', "a-3", "Group") - # m = CreateModeratedGroup(request, request.POST.get('groupname', "").strip(), request.POST.get('group_type', "")) - # m.create_new_moderated_group(request.POST.get('groupname', "").strip(), moderation_level=2) - # print "--------", m - # except Exception, e: - # pass - +# try: +# group_id = ObjectId(group_id) +# except: +# group_name, group_id = get_group_name_id(group_id) - if request.method == "POST": +# if request.method == "POST": - # colg = node_collection.collection.Group() - cname = request.POST.get('groupname', "").strip() - edit_policy = request.POST.get('edit_policy', "") - group_type = request.POST.get('group_type', "") - moderation_level = request.POST.get('moderation_level', '1') +# cname = request.POST.get('name', "").strip() +# edit_policy = request.POST.get('edit_policy', "") +# group_type = request.POST.get('group_type', "") +# moderation_level = request.POST.get('moderation_level', '1') - if request.POST.get('edit_policy', "") == "EDITABLE_MODERATED": +# if request.POST.get('edit_policy', "") == "EDITABLE_MODERATED": - # instantiate moderated group - mod_group = CreateModeratedGroup(request) +# # instantiate moderated group +# mod_group = CreateModeratedGroup(request) - # calling method to create new group - result = mod_group.create_new_moderated_group(cname, moderation_level) +# # calling method to create new group +# result = mod_group.create_edit_moderated_group(cname, moderation_level) - else: +# else: - # instantiate moderated group - group = CreateGroup(request) +# # instantiate moderated group +# group = CreateGroup(request) - # calling method to create new group - result = group.create_group(cname) +# # calling method to create new group +# result = group.create_group(cname) - if result[0]: - colg = result[1] - - # colg.altnames = cname - # colg.altnames = request.POST.get('alt_groupname', "").strip() - # colg.name = unicode(cname) - # colg.member_of.append(gst_group._id) - # usrid = int(request.user.id) - - # colg.created_by = usrid - # if usrid not in colg.author_set: - # colg.author_set.append(usrid) - - # colg.modified_by = usrid - # if usrid not in colg.contributors: - # colg.contributors.append(usrid) - - # colg.group_type = request.POST.get('group_type', "") - # colg.edit_policy = request.POST.get('edit_policy', "") - # colg.subscription_policy = request.POST.get('subscription', "OPEN") - # colg.visibility_policy = request.POST.get('existance', 'ANNOUNCED') - # colg.disclosure_policy = request.POST.get('member', 'DISCLOSED_TO_MEM') - # colg.encryption_policy = request.POST.get('encryption', 'NOT_ENCRYPTED') - # colg.agency_type = request.POST.get('agency_type', "") - # if colg.edit_policy == "EDITABLE_MODERATED": - # colg.moderation_level = request.POST.get('moderation_level', '1') - # # colg.save() +# if result[0]: +# colg = result[1] - # if colg.edit_policy == "EDITABLE_MODERATED": - # Mod_colg = node_collection.collection.Group() - # Mod_colg.altnames = cname + "_mod" - # Mod_colg.name = cname + "Mod" - # Mod_colg.group_type = "PRIVATE" +# # auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) }) - # Mod_colg.created_by = usrid - # if usrid not in Mod_colg.author_set: - # Mod_colg.author_set.append(usrid) +# # has_shelf_RT = node_collection.one({'_type': 'RelationType', 'name': u'has_shelf' }) - # Mod_colg.modified_by = usrid - # if usrid not in Mod_colg.contributors: - # Mod_colg.contributors.append(usrid) - - # Mod_colg.prior_node.append(colg._id) - # Mod_colg.save() - - # colg.post_node.append(Mod_colg._id) - # # colg.save() - - # auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) }) - - # has_shelf_RT = node_collection.one({'_type': 'RelationType', 'name': u'has_shelf' }) - - shelves = [] - shelf_list = {} +# shelves = [] +# shelf_list = {} - # if auth: - # shelf = triple_collection.find({'_type': 'GRelation', 'subject': ObjectId(auth._id), 'relation_type.$id': has_shelf_RT._id }) - - # if shelf: - # for each in shelf: - # shelf_name = node_collection.one({'_id': ObjectId(each.right_subject)}) - # shelves.append(shelf_name) - - # shelf_list[shelf_name.name] = [] - # for ID in shelf_name.collection_set: - # shelf_item = node_collection.one({'_id': ObjectId(ID) }) - # shelf_list[shelf_name.name].append(shelf_item.name) +# # if auth: +# # shelf = triple_collection.find({'_type': 'GRelation', 'subject': ObjectId(auth._id), 'relation_type.$id': has_shelf_RT._id }) + +# # if shelf: +# # for each in shelf: +# # shelf_name = node_collection.one({'_id': ObjectId(each.right_subject)}) +# # shelves.append(shelf_name) + +# # shelf_list[shelf_name.name] = [] +# # for ID in shelf_name.collection_set: +# # shelf_item = node_collection.one({'_id': ObjectId(ID) }) +# # shelf_list[shelf_name.name].append(shelf_item.name) - # else: - # shelves = [] - - return render_to_response("ndf/groupdashboard.html", - {'groupobj': colg, 'appId': app._id, 'node': colg, - 'user': request.user, - 'groupid': colg._id, 'group_id': colg._id, - 'shelf_list': shelf_list,'shelves': shelves - },context_instance=RequestContext(request)) +# # else: +# # shelves = [] +# return render_to_response("ndf/groupdashboard.html", +# {'groupobj': colg, 'appId': app._id, 'node': colg, +# 'user': request.user, +# 'groupid': colg._id, 'group_id': colg._id, +# 'shelf_list': shelf_list,'shelves': shelves +# },context_instance=RequestContext(request)) - # for rendering empty form page: - available_nodes = node_collection.find({'_type': u'Group'}) - nodes_list = [] - for each in available_nodes: - nodes_list.append(str((each.name).strip().lower())) - return render_to_response("ndf/create_group.html", {'groupid': group_id, 'appId': app._id, 'group_id': group_id, 'nodes_list': nodes_list},RequestContext(request)) - -# @get_execution_time -#def home_dashboard(request): -# try: -# groupobj=node_collection.one({'$and':[{'_type':u'Group'},{'name':u'home'}]}) -# except Exception as e: -# groupobj="" -# pass -# print "frhome--",groupobj -# return render_to_response("ndf/groupdashboard.html",{'groupobj':groupobj,'user':request.user,'curgroup':groupobj},context_instance=RequestContext(request)) +# # for rendering empty form page: +# available_nodes = node_collection.find({'_type': u'Group'}) +# nodes_list = [] +# for each in available_nodes: +# nodes_list.append(str((each.name).strip().lower())) +# return render_to_response("ndf/create_group.html", {'groupid': group_id, 'appId': app._id, 'group_id': group_id, 'nodes_list': nodes_list},RequestContext(request)) @login_required @@ -1016,62 +1432,152 @@ def group_dashboard(request, group_id=None): ) -@login_required -@get_execution_time -def edit_group(request, group_id): - ins_objectid = ObjectId() - is_auth_node = False - 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) - is_auth_node = True - - else: - pass - page_node = node_collection.one({"_id": ObjectId(group_id)}) - title = gst_group.name - if request.method == "POST": - is_node_changed=get_node_common_fields(request, page_node, group_id, gst_group) +# @login_required +# @get_execution_time +# def edit_group(request, group_id): + +# # page_node = node_collection.one({"_id": ObjectId(group_id)}) +# # title = gst_group.name +# # if request.method == "POST": +# # is_node_changed=get_node_common_fields(request, page_node, group_id, gst_group) + +# # if page_node.access_policy == "PUBLIC": +# # page_node.group_type = "PUBLIC" + +# # if page_node.access_policy == "PRIVATE": +# # page_node.group_type = "PRIVATE" +# # page_node.save(is_changed=is_node_changed) +# # page_node.save() +# # group_id=page_node._id +# # page_node.get_neighbourhood(page_node.member_of) +# # return HttpResponseRedirect(reverse('groupchange', kwargs={'group_id':group_id})) + +# # else: +# # if page_node.status == u"DRAFT": +# # page_node, ver = get_page(request, page_node) +# # page_node.get_neighbourhood(page_node.member_of) + +# # available_nodes = node_collection.find({'_type': u'Group', 'member_of': ObjectId(gst_group._id) }) +# # nodes_list = [] +# # for each in available_nodes: +# # nodes_list.append(str((each.name).strip().lower())) + +# # return render_to_response("ndf/edit_group.html", +# # { 'node': page_node,'title':title, +# # 'appId':app._id, +# # 'groupid':group_id, +# # 'nodes_list': nodes_list, +# # 'group_id':group_id, +# # 'is_auth_node':is_auth_node +# # }, +# # context_instance=RequestContext(request) +# # ) - if page_node.access_policy == "PUBLIC": - page_node.group_type = "PUBLIC" - - if page_node.access_policy == "PRIVATE": - page_node.group_type = "PRIVATE" - page_node.save(is_changed=is_node_changed) - page_node.save() - group_id=page_node._id - page_node.get_neighbourhood(page_node.member_of) - return HttpResponseRedirect(reverse('groupchange', kwargs={'group_id':group_id})) - - else: - if page_node.status == u"DRAFT": - page_node, ver = get_page(request, page_node) - page_node.get_neighbourhood(page_node.member_of) - - available_nodes = node_collection.find({'_type': u'Group', 'member_of': ObjectId(gst_group._id) }) - nodes_list = [] - for each in available_nodes: - nodes_list.append(str((each.name).strip().lower())) - - return render_to_response("ndf/edit_group.html", - { 'node': page_node,'title':title, - 'appId':app._id, - 'groupid':group_id, - 'nodes_list': nodes_list, - 'group_id':group_id, - 'is_auth_node':is_auth_node - }, - context_instance=RequestContext(request) - ) +# group_obj = get_group_name_id(group_id, get_obj=True) + +# if request.method == "POST": +# is_node_changed = get_node_common_fields(request, group_obj, group_id, gst_group) +# # print "=== ", is_node_changed + +# if group_obj.access_policy == "PUBLIC": +# group_obj.group_type = "PUBLIC" + +# elif group_obj.access_policy == "PRIVATE": +# group_obj.group_type = "PRIVATE" + +# group_obj.save(is_changed=is_node_changed) + +# group_obj.get_neighbourhood(group_obj.member_of) + +# return HttpResponseRedirect(reverse('groupchange', kwargs={'group_id':group_obj._id})) + +# elif request.method == "GET": +# if group_obj.status == u"DRAFT": +# group_obj, ver = get_page(request, group_obj) +# group_obj.get_neighbourhood(group_obj.member_of) + +# available_nodes = node_collection.find({'_type': u'Group', '_id': {'$nin': [group_obj._id]}}, {'name': 1, '_id': 0}) +# nodes_list = [str(g_obj.name.strip().lower()) for g_obj in available_nodes] +# # print nodes_list + +# return render_to_response("ndf/create_group.html", +# { +# 'node': group_obj, +# 'title': 'Group', +# # 'appId':app._id, +# 'groupid':group_id, +# 'group_id':group_id, +# 'nodes_list': nodes_list, +# # 'is_auth_node':is_auth_node +# }, +# context_instance=RequestContext(request) +# ) + + +# class EditGroup(View): +# """ +# Class to handle create/edit group requests. +# """ + +# @method_decorator(login_required) +# @method_decorator(get_execution_time) +# def get(self, request, group_id): +# """ +# Catering GET request of rendering group create/edit form. +# """ + +# group_obj = get_group_name_id(group_id, get_obj=True) + +# if group_obj.status == u"DRAFT": +# group_obj, ver = get_page(request, group_obj) +# group_obj.get_neighbourhood(group_obj.member_of) + +# available_nodes = node_collection.find({'_type': u'Group','_id': {'$nin': [group_obj._id]}}, +# {'name': 1, '_id': 0}) +# nodes_list = [str(g_obj.name.strip().lower()) for g_obj in available_nodes] +# # print nodes_list + +# # if in the case we can replace "ndf/create_group.html" with "ndf/edit_group.html" +# return render_to_response("ndf/create_group.html", +# { +# 'node': group_obj, +# 'title': 'Group', # 'appId':app._id, +# 'groupid': group_id, 'group_id': group_id, +# 'nodes_list': nodes_list, +# # 'is_auth_node':is_auth_node +# }, +# context_instance=RequestContext(request) +# ) + +# @method_decorator(login_required) +# @method_decorator(get_execution_time) +# def post(self, request, group_id): +# ''' +# To handle post request of group form. +# To save edited or newly-created group's data. +# ''' +# group_obj = get_group_name_id(group_id, get_obj=True) + +# is_node_changed = get_node_common_fields(request, group_obj, group_id, gst_group) +# # print "=== ", is_node_changed + +# group_obj.group_type = unicode(request.POST.get("group_type", "")) +# group_obj.agency_type = unicode(request.POST.get("agency_type", "")) +# edit_policy = unicode(request.POST.get("edit_policy", "")) + +# is_node_changed = True +# group_obj.status = u"PUBLISHED" +# group_obj.save(is_changed=is_node_changed) + +# group_obj.get_neighbourhood(group_obj.member_of) + +# return HttpResponseRedirect(reverse('groupchange', kwargs={'group_id':group_obj._id})) + +# # ===END of class EditGroup() === + + @login_required @get_execution_time def app_selection(request, group_id): @@ -1294,7 +1800,7 @@ def create_sub_group(request,group_id): if request.method == "POST": colg = node_collection.collection.Group() Mod_colg=node_collection.collection.Group() - cname=request.POST.get('groupname', "") + cname=request.POST.get('name', "") colg.altnames=cname colg.name = unicode(cname) colg.member_of.append(gst_group._id) diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/methods.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/methods.py index ef7b35b..f5d3180 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/views/methods.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/methods.py @@ -765,16 +765,15 @@ def get_node_common_fields(request, node, group_id, node_type, coll_set=None): is_changed = True # org-content - if content_org: - if node.content_org != content_org: - node.content_org = content_org - - # Required to link temporary files with the current user who is - # modifying this document - usrname = request.user.username - filename = slugify(name) + "-" + slugify(usrname) + "-" + ObjectId().__str__() - node.content = org2html(content_org, file_prefix=filename) - is_changed = True + if node.content_org != content_org: + node.content_org = content_org + + # Required to link temporary files with the current user who is + # modifying this document + usrname = request.user.username + filename = slugify(name) + "-" + slugify(usrname) + "-" + ObjectId().__str__() + node.content = org2html(content_org, file_prefix=filename) + is_changed = True # visited_location in author class if node.location != map_geojson_data: diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/moderation.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/moderation.py index 4ddada2..615b1ce 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/views/moderation.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/moderation.py @@ -84,7 +84,7 @@ def moderation_status(request, group_id, node_id): is_under_moderation = False # print "is_under_moderation : ", is_under_moderation - print "=== ", current_mod_group_obj._id + # print "=== ", current_mod_group_obj._id return render_to_response('ndf/under_moderation.html', { 'group_id': group_id, 'groupid': group_id, 'node': node, 'title': 'Under Moderation Status', @@ -98,10 +98,11 @@ def all_under_moderation(request, group_id): group_obj = get_group_name_id(group_id, get_obj=True) if not group_obj.edit_policy == 'EDITABLE_MODERATED': - raise Http404(error_message) + raise Http404('Group is not EDITABLE_MODERATED') mod_group_instance = CreateModeratedGroup(request) group_hierarchy_result = mod_group_instance.get_all_group_hierarchy(group_obj._id) + group_hierarchy_obj_list = [] if group_hierarchy_result[0]: group_hierarchy_obj_list = group_hierarchy_result[1] @@ -116,8 +117,8 @@ def all_under_moderation(request, group_id): return render_to_response('ndf/all_under_moderation_status.html', { "group_id": group_id, "groupid": group_id, "title": "All Under Moderation Resources", - "files": all_resources, "detail_urlname": "moderation_status", "filetype": "all", - "dont_show_error": True + "files": all_resources, "group_hierarchy_obj_list": group_hierarchy_obj_list, + "detail_urlname": "moderation_status", "filetype": "all", "dont_show_error": True }, RequestContext(request)) else: @@ -154,9 +155,9 @@ def approve_resource(request, group_id): # make deep copy of object and not to copy it's reference with [:]. group_set_details_dict = get_moderator_group_set(node_group_set[:], group_id, get_details=True) updated_group_set = group_set_details_dict['updated_group_set'] - print "==== updated_group_set : ", updated_group_set - print "==== node_group_set : ", node_group_set - print "==== group_set_details_dict : ", group_set_details_dict + # print "==== updated_group_set : ", updated_group_set + # print "==== node_group_set : ", node_group_set + # print "==== group_set_details_dict : ", group_set_details_dict # if set(node_group_set) != set(updated_group_set): if group_set_details_dict['is_group_set_updated']: diff --git a/gnowsys-ndf/gnowsys_ndf/settings.py b/gnowsys-ndf/gnowsys_ndf/settings.py index 4c4c547..2a80481 100644 --- a/gnowsys-ndf/gnowsys_ndf/settings.py +++ b/gnowsys-ndf/gnowsys_ndf/settings.py @@ -629,6 +629,9 @@ GSTUDIO_RESOURCES_REPLY_RATING = 2 # the level of moderation means level of sub mode group hierarchy GSTUDIO_GROUP_MODERATION_LEVEL = 1 +# allowed moderation levels +GSTUDIO_ALLOWED_GROUP_MODERATION_LEVELS = [1, 2, 3] + try: from local_settings import * # print "Local settings applied" |