diff options
author | katkamrachana <katkam.rachana@gmail.com> | 2015-04-24 14:37:20 +0530 |
---|---|---|
committer | katkamrachana <katkam.rachana@gmail.com> | 2015-04-24 14:37:20 +0530 |
commit | e89b683f96c02288eb111ad71a980587e70d2bb8 (patch) | |
tree | e3cc64f106e22c423bf2df48c8dbfce56846ade2 /gnowsys-ndf/gnowsys_ndf/ndf | |
parent | 98ed4dc030e718463fb8416aedab218e4e891947 (diff) | |
download | gnowsys-e89b683f96c02288eb111ad71a980587e70d2bb8.tar.gz |
Create unit before adding resources
Diffstat (limited to 'gnowsys-ndf/gnowsys_ndf/ndf')
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/urls/course.py | 6 | ||||
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/views/course.py | 87 |
2 files changed, 67 insertions, 26 deletions
diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/urls/course.py b/gnowsys-ndf/gnowsys_ndf/ndf/urls/course.py index 02c40d3..8cca7cf 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/urls/course.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/urls/course.py @@ -17,8 +17,12 @@ urlpatterns = patterns('gnowsys_ndf.ndf.views.course', url(r'^/create_css/$', 'save_course_sub_section', name='save_course_sub_section'), url(r'^/course_sub_section_prop/$', 'course_sub_section_prop', name='course_sub_section_prop'), url(r'^/resources/', 'get_resources', name='get_resources'), + url(r'^/add_units/', 'add_units', name='add_units'), - url(r'^/save_units/', 'save_resources', name='save_resources'), + url(r'^/publish_course/', 'publish_course', name='publish_course'), + + url(r'^/save_res/', 'save_resources', name='save_resources'), + url(r'^/create_edit_unit/', 'create_edit_unit', name='create_edit_unit'), url(r'^/change_node_name/$', 'change_node_name', name='change_node_name'), url(r'^/change_order/$', 'change_order', name='change_order'), url(r'^/delete/$', 'delete_from_course_structure', name='delete_from_cs'), diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/course.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/course.py index bfed82f..b888c8e 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/views/course.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/course.py @@ -119,6 +119,7 @@ def course(request, group_id, course_id=None): variable = RequestContext(request, {'title': title, 'course_nodes_count': course_coll.count(), 'course_coll': course_coll, 'groupid':group_id, 'appId':app._id, 'group_id':group_id}) return render_to_response(template, variable) + @login_required @get_execution_time def create_edit(request, group_id, node_id=None): @@ -168,6 +169,8 @@ def create_edit(request, group_id, node_id=None): context_instance=RequestContext(request) ) + +@login_required @get_execution_time def course_detail(request, group_id, _id): ins_objectid = ObjectId() @@ -200,6 +203,7 @@ def course_detail(request, group_id, _id): context_instance=RequestContext(request) ) + @login_required @get_execution_time def course_create_edit(request, group_id, app_id, app_set_id=None, app_set_instance_id=None, app_name=None): @@ -1062,7 +1066,7 @@ def course_sub_section_prop(request, group_id): @login_required -def add_units(request,group_id): +def add_units(request, group_id): ''' Accepts: * CourseSubSection node _id @@ -1071,7 +1075,6 @@ def add_units(request,group_id): Actions: * Redirects to course_units.html ''' - res_count_dict = {} variable = None unit_node = None css_node_id = request.GET.get('css_node_id', '') @@ -1084,13 +1087,6 @@ def add_units(request,group_id): title = "Course Units" try: unit_node = node_collection.one({"_id": ObjectId(unit_node_id)}) - for each in unit_node.collection_set: - each_node = node_collection.one({'_id': each}) - a = each_node.member_of_names_list - alen = len(a) - while alen > 0: - res_count_dict = count_res(a[alen-1], res_count_dict) - alen = alen - 1 except: unit_node = None variable = RequestContext(request, { @@ -1101,19 +1097,12 @@ def add_units(request,group_id): 'app_id': app_id, 'unit_node': unit_node, 'course_node': course_node, - 'res_count_dict': json.dumps(res_count_dict) }) template = "ndf/course_units.html" return render_to_response(template, variable) -def count_res(k,d): - if k not in d: - d[k] = 1 - else: - d[k] = d[k] + 1 - return d @login_required def get_resources(request, group_id): @@ -1197,7 +1186,6 @@ def save_resources(request, group_id): unit_name = request.POST.get('unit_name', "") unit_name = unit_name.strip() unit_node_id = request.POST.get('unit_node_id', "") - res_count_dict = {} css_node = node_collection.one({"_id": ObjectId(css_node_id)}) list_of_res_ids = [ObjectId(each_res) for each_res in list_of_res] @@ -1226,16 +1214,51 @@ def save_resources(request, group_id): node_collection.collection.update({'_id': cu_new._id}, {'$set': {'collection_set':list_of_res_ids}},upsert=False,multi=False) cu_new.reload() - for each in cu_new.collection_set: - each_node = node_collection.one({'_id': each}) - a = each_node.member_of_names_list - alen = len(a) - while alen > 0: - res_count_dict = count_res(a[alen-1], res_count_dict) - alen = alen - 1 response_dict["success"] = True response_dict["cu_new_id"] = str(cu_new._id) - response_dict["res_count_dict"] = res_count_dict + + return HttpResponse(json.dumps(response_dict)) + + +@login_required +def create_edit_unit(request, group_id): + ''' + Accepts: + * ObjectId of unit node if exists + * ObjectId of CourseSubSection node + + Actions: + * Creates/Updates Unit node + + Returns: + * success (i.e True/False) + ''' + response_dict = {"success": False} + if request.is_ajax() and request.method == "POST": + css_node_id = request.POST.get("css_node_id", '') + unit_node_id = request.POST.get("unit_node_id", '') + unit_name = request.POST.get("unit_name", '') + css_node = node_collection.one({"_id": ObjectId(css_node_id)}) + try: + cu_node = node_collection.one({'_id': ObjectId(unit_node_id)}) + except: + cu_node = None + if cu_node is None: + cu_gst = node_collection.one({'_type': "GSystemType", 'name': "CourseUnit"}) + cu_node = node_collection.collection.GSystem() + cu_node.member_of.append(cu_gst._id) + # set name + cu_node.name = unit_name.strip() + cu_node.modified_by = int(request.user.id) + cu_node.created_by = int(request.user.id) + cu_node.contributors.append(int(request.user.id)) + cu_node.prior_node.append(css_node._id) + cu_node.save() + response_dict["unit_node_id"] = str(cu_node._id) + node_collection.collection.update({'_id': cu_node._id}, {'$set': {'name': unit_name}}, upsert=False, multi=False) + + if cu_node._id not in css_node.collection_set: + node_collection.collection.update({'_id': css_node._id}, {'$push': {'collection_set': cu_node._id}}, upsert=False, multi=False) return HttpResponse(json.dumps(response_dict)) @@ -1275,3 +1298,17 @@ def delete_item(item): deletion_type=0 ) return del_status + + +@login_required +def publish_course(request, group_id): + if request.is_ajax() and request.method == "POST": + try: + node_id = request.POST.get("node_id", "") + node = node_collection.one({'_id': ObjectId(node_id)}) + node.status = unicode("PUBLISHED") + node.modified_by = int(request.user.id) + node.save() + except: + return HttpResponse("Fail") + return HttpResponse("Success") |