def theme_topic_create_edit(request, group_id, app_set_id=None): ##################### # 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 : # pass try: group_id = ObjectId(group_id) except: group_name, group_id = get_group_name_id(group_id) ###################### nodes_dict = [] create_edit = True themes_hierarchy = False themes_list_items = "" themes_cards = "" title = "" node = "" theme_topic_node = "" drawers = None drawer = None app_id = None nodes_list = [] parent_nodes_collection = "" translate = request.GET.get('translate', '') app_GST = node_collection.find_one({"_id": ObjectId(app_set_id)}) if app_GST._id != theme_GST._id: app_obj = node_collection.one({'_id': ObjectId(app_GST.member_of[0])}) else: app_obj = theme_GST if app_obj: app_id = app_obj._id 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' }) shelf = triple_collection.find({ '_type': 'GRelation', 'subject': ObjectId(auth._id), 'relation_type': has_shelf_RT._id }) shelf_list = {} 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 = [] if request.method == "POST": if app_GST: create_edit = True themes_list_items = "" root_themes = [] root_themes_id = [] nodes_list = [] name = request.POST.get('name') collection_list = request.POST.get('collection_list', '') prior_node_list = request.POST.get('prior_node_list', '') teaches_list = request.POST.get('teaches_list', '') assesses_list = request.POST.get('assesses_list', '') # To find the root nodes to maintain the uniquness while creating and editing themes nodes = node_collection.find({ 'member_of': { '$all': [theme_GST._id] }, 'group_set': { '$all': [ObjectId(group_id)] } }) for each in nodes: if each.collection_set: for k in each.collection_set: nodes_list.append(k) nodes.rewind() for each in nodes: if each._id not in nodes_list: root_themes.append(each.name) root_themes_id.append(each._id) if app_GST.name == "Theme" or app_GST.name == "Topic" or translate == "true": # For creating new themes & Topics themes_list_items = False create_edit = False themes_hierarchy = False themes_cards = True if name or translate == "true": if not name.upper() in (theme_name.upper() for theme_name in root_themes ) or translate == "true": if translate != "true": theme_topic_node = node_collection.collection.GSystem( ) # get_node_common_fields(request, theme_topic_node, group_id, app_GST) theme_topic_node.save( is_changed=get_node_common_fields( request, theme_topic_node, group_id, app_GST), groupid=group_id) if translate == "true": global list_trans_coll list_trans_coll = [] coll_set1 = get_coll_set(app_GST._id) for each in coll_set1: theme_topic_node = node_collection.collection.GSystem( ) if "Theme" in each.member_of_names_list: app_obj = theme_GST if "theme_item" in each.member_of_names_list: app_obj = theme_item_GST if "topic" in each.member_of_names_list: app_obj = topic_GST theme_topic_node.save( is_changed=get_node_common_fields( request, theme_topic_node, group_id, app_obj, each), groupid=group_id) coll_set_dict[each._id] = theme_topic_node._id relation_type = node_collection.one({ '_type': 'RelationType', 'name': 'translation_of' }) # grelation=collection.GRelation() # grelation.relation_type=relation_type # grelation.subject=each._id # grelation.right_subject=theme_topic_node._id # grelation.name=u"" # grelation.save() gr_node = create_grelation( each._id, relation_type, theme_topic_node._id) for each in coll_set1: #if "Theme" in each.member_of_names_list: if each.collection_set: for collset in each.collection_set: p = coll_set_dict[each._id] parent_node = node_collection.one( {'_id': ObjectId(str(p))}) n = coll_set_dict[collset] sub_node = node_collection.one( {'_id': ObjectId(str(n))}) parent_node.collection_set.append( sub_node._id) parent_node.save(groupid=group_id) # To return themes card view for listing theme nodes after creating new Themes nodes.rewind() nodes_dict = nodes else: themes_list_items = False create_edit = False themes_hierarchy = True theme_topic_node = node_collection.one( {'_id': ObjectId(app_GST._id)}) # For edititng themes if theme_GST._id in app_GST.member_of and translate != "true": # To find themes uniqueness within the context of its parent Theme collection, while editing theme name root_themes = [] nodes = node_collection.find({ 'member_of': { '$all': [theme_GST._id] }, 'group_set': { '$all': [ObjectId(group_id)] } }) for each in nodes: root_themes.append(each.name) if name: if name.upper() != theme_topic_node.name.upper(): if not name.upper() in ( theme_name.upper() for theme_name in root_themes): # get_node_common_fields(request, theme_topic_node, group_id, theme_GST) theme_topic_node.save( is_changed=get_node_common_fields( request, theme_topic_node, group_id, theme_GST), groupid=group_id) else: theme_topic_node.save( is_changed=get_node_common_fields( request, theme_topic_node, group_id, theme_GST), groupid=group_id) if translate != "true": # For storing and maintaning collection order if collection_list != '': theme_topic_node.collection_set = [] collection_list = collection_list.split(",") i = 0 while (i < len(collection_list)): node_id = ObjectId(collection_list[i]) if node_collection.one({"_id": node_id}): theme_topic_node.collection_set.append(node_id) i = i + 1 theme_topic_node.save(groupid=group_id) # End of storing collection title = theme_GST.name nodes.rewind() nodes_dict = nodes # This will return to Themes Hierarchy themes_list_items = False create_edit = False themes_hierarchy = False themes_cards = True elif theme_item_GST._id in app_GST.member_of and translate != "true": title = "Theme Item" dict_drawer = {} dict2 = [] node = app_GST prior_theme_collection = [] parent_nodes_collection = "" # To display the theme-topic drawer while create or edit theme checked = "theme_item" # drawers = get_drawers(group_id, node._id, node.collection_set, checked) # Code for fetching drawer2 for k in node.collection_set: obj = node_collection.one({'_id': ObjectId(k)}) dict2.append(obj) dict_drawer['2'] = dict2 # drawers = dict_drawer # End of code for drawer2 drawer = dict_drawer['2'] # To find themes uniqueness within the context of its parent Theme collection, while editing theme item nodes = node_collection.find({ 'member_of': { '$all': [theme_item_GST._id] }, 'group_set': { '$all': [ObjectId(group_id)] } }) for each in nodes: if app_GST._id in each.collection_set: for k in each.collection_set: prior_theme = node_collection.one( {'_id': ObjectId(k)}) prior_theme_collection.append(prior_theme.name) parent_nodes_collection = json.dumps( prior_theme_collection) if not prior_theme_collection: root_nodes = node_collection.find({ 'member_of': { '$all': [theme_GST._id] }, 'group_set': { '$all': [ObjectId(group_id)] } }) for k in root_nodes: if app_GST._id in k.collection_set: root_themes = [] root_themes_id = [] for l in k.collection_set: objs = node_collection.one( {'_id': ObjectId(l)}) root_themes.append(objs.name) root_themes_id.append(objs._id) # End of finding unique theme names for editing name # For adding a sub-theme-items and maintianing their uniqueness within their context nodes_list = [] for each in app_GST.collection_set: sub_theme = node_collection.one( {'_id': ObjectId(each)}) nodes_list.append(sub_theme.name) nodes_list = json.dumps(nodes_list) # End of finding unique sub themes if name: if name.upper() != theme_topic_node.name.upper(): # If "Name" has changed if theme_topic_node._id in root_themes_id: # If editing node in root theme items if not name.upper() in ( theme_name.upper() for theme_name in root_themes): # get_node_common_fields(request, theme_topic_node, group_id, theme_GST) theme_topic_node.save( is_changed=get_node_common_fields( request, theme_topic_node, group_id, theme_item_GST), groupid=group_id) else: # If editing theme item in prior_theme_collection hierarchy if not name.upper() in (theme_name.upper( ) for theme_name in prior_theme_collection): # get_node_common_fields(request, theme_topic_node, group_id, theme_GST) theme_topic_node.save( is_changed=get_node_common_fields( request, theme_topic_node, group_id, theme_item_GST), groupid=group_id) else: # If name not changed but other fields has changed theme_topic_node.save( is_changed=get_node_common_fields( request, theme_topic_node, group_id, theme_item_GST), groupid=group_id) if translate != "true" and collection_list: # For storing and maintaning collection order if collection_list != '': theme_topic_node.collection_set = [] collection_list = collection_list.split(",") i = 0 while (i < len(collection_list)): node_id = ObjectId(collection_list[i]) if node_collection.one({"_id": node_id}): theme_topic_node.collection_set.append(node_id) i = i + 1 theme_topic_node.save(groupid=group_id) # End of storing collection # This will return to Themes items edit if theme_topic_node: theme_topic_node.reload() node = theme_topic_node create_edit = True themes_hierarchy = False # For editing topics elif topic_GST._id in app_GST.member_of: root_topics = [] nodes_list = [] # To find the root nodes to maintain the uniquness while creating and editing topics nodes = node_collection.find({ 'member_of': { '$all': [topic_GST._id] }, 'group_set': { '$all': [ObjectId(group_id)] } }) for each in nodes: if each.collection_set: for k in each.collection_set: nodes_list.append(k) nodes.rewind() for each in nodes: if each._id not in nodes_list: root_topics.append(each.name) # End of finding the root nodes if name: if theme_topic_node.name != name: topic_name = theme_topic_node.name if not name.upper() in ( theme_name.upper() for theme_name in root_topics): theme_topic_node.save( is_changed=get_node_common_fields( request, theme_topic_node, group_id, topic_GST), groupid=group_id) elif topic_name.upper() == name.upper(): theme_topic_node.save( is_changed=get_node_common_fields( request, theme_topic_node, group_id, topic_GST), groupid=group_id) else: theme_topic_node.save( is_changed=get_node_common_fields( request, theme_topic_node, group_id, topic_GST), groupid=group_id) if collection_list: # For storing and maintaning collection order if collection_list != '': theme_topic_node.collection_set = [] collection_list = collection_list.split(",") i = 0 while (i < len(collection_list)): node_id = ObjectId(collection_list[i]) if node_collection.one({"_id": node_id}): theme_topic_node.collection_set.append( node_id) i = i + 1 theme_topic_node.save(groupid=group_id) title = topic_GST.name # To fill the metadata info while creating and editing topic node metadata = request.POST.get("metadata_info", '') if metadata: # Only while metadata editing if metadata == "metadata": if theme_topic_node: get_node_metadata(request, theme_topic_node) # End of filling metadata if prior_node_list != '': theme_topic_node.prior_node = [] prior_node_list = prior_node_list.split(",") i = 0 while (i < len(prior_node_list)): node_id = ObjectId(prior_node_list[i]) if node_collection.one({"_id": node_id}): theme_topic_node.prior_node.append(node_id) i = i + 1 theme_topic_node.save(groupid=group_id) if teaches_list != '': teaches_list = teaches_list.split(",") create_grelation_list(theme_topic_node._id, "teaches", teaches_list) if assesses_list != '': assesses_list = assesses_list.split(",") create_grelation_list(theme_topic_node._id, "assesses", assesses_list) # This will return to edit topic if theme_topic_node: theme_topic_node.reload() node = theme_topic_node create_edit = True themes_hierarchy = False else: app_node = None nodes_list = [] app_GST = node_collection.find_one({"_id": ObjectId(app_set_id)}) # print "\napp_GST in else: ",app_GST.name,"\n" if app_GST: # For adding new Theme & Topic if app_GST.name == "Theme" or app_GST.name == "Topic" or translate == True: print "22222" title = app_GST.name node = "" root_themes = [] # To find the root nodes to maintain the uniquness while creating new themes nodes = node_collection.find({ 'member_of': { '$all': [app_GST._id] }, 'group_set': { '$all': [ObjectId(group_id)] } }) for each in nodes: if each.collection_set: for k in each.collection_set: nodes_list.append(k) nodes.rewind() for each in nodes: if each._id not in nodes_list: root_themes.append(each.name) root_themes = json.dumps(root_themes) nodes_list = root_themes # End of finding unique root level Themes else: if theme_GST._id in app_GST.member_of: title = "Theme" node = app_GST prior_theme_collection = [] parent_nodes_collection = "" drawer = [] # End of editing Themes # For editing theme item if theme_item_GST._id in app_GST.member_of: title = "Theme Item" dict_drawer = {} dict2 = [] node = app_GST prior_theme_collection = [] parent_nodes_collection = "" # To display the theme-topic drawer while create or edit theme checked = "theme_item" # drawers = get_drawers(group_id, node._id, node.collection_set, checked) for k in node.collection_set: obj = node_collection.one({'_id': ObjectId(k)}) dict2.append(obj) dict_drawer['2'] = dict2 drawer = dict_drawer['2'] # To find themes uniqueness within the context of its parent Theme collection, while editing theme name nodes = node_collection.find({ 'member_of': { '$all': [theme_item_GST._id] }, 'group_set': { '$all': [ObjectId(group_id)] } }) for each in nodes: if app_GST._id in each.collection_set: for k in each.collection_set: prior_theme = node_collection.one( {'_id': ObjectId(k)}) prior_theme_collection.append(prior_theme.name) parent_nodes_collection = json.dumps( prior_theme_collection) # End of finding unique theme names for editing name # For adding a sub-themes and maintianing their uniqueness within their context for each in app_GST.collection_set: sub_theme = node_collection.one( {'_id': ObjectId(each)}) nodes_list.append(sub_theme.name) nodes_list = json.dumps(nodes_list) # End of finding unique sub themes # for editing topic elif topic_GST._id in app_GST.member_of: title = topic_GST.name node = app_GST prior_theme_collection = [] parent_nodes_collection = "" node.get_neighbourhood(node.member_of) # To find topics uniqueness within the context of its parent Theme item collection, while editing topic name nodes = node_collection.find({ 'member_of': { '$all': [theme_item_GST._id] }, 'group_set': { '$all': [ObjectId(group_id)] } }) for each in nodes: if app_GST._id in each.collection_set: for k in each.collection_set: prior_theme = node_collection.one( {'_id': ObjectId(k)}) prior_theme_collection.append(prior_theme.name) parent_nodes_collection = json.dumps( prior_theme_collection) # End of finding unique theme names for editing name if translate: global list_trans_coll list_trans_coll = [] trans_coll_list = get_coll_set(str(app_GST._id)) print LANGUAGES return render_to_response( "ndf/translation_page.html", { 'group_id': group_id, 'groupid': group_id, 'title': title, 'node': app_GST, 'lan': LANGUAGES, 'list1': trans_coll_list }, context_instance=RequestContext(request)) if title == "Topic": return render_to_response("ndf/node_edit_base.html", { 'group_id': group_id, 'groupid': group_id, 'drawer': drawer, 'themes_cards': themes_cards, '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, 'theme_GST_id': theme_GST._id, 'theme_item_GST_id': theme_item_GST._id, 'topic_GST_id': topic_GST._id, 'themes_list_items': themes_list_items, 'nodes': nodes_dict, 'lan': LANGUAGES }, context_instance=RequestContext(request)) return render_to_response("ndf/theme.html", { '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, 'theme_GST_id': theme_GST._id, 'theme_item_GST_id': theme_item_GST._id, 'topic_GST_id': topic_GST._id, 'themes_list_items': themes_list_items, 'nodes': nodes_dict, 'lan': LANGUAGES }, context_instance=RequestContext(request))
def video_edit(request,group_id,_id): # 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 : # pass try: group_id = ObjectId(group_id) except: group_name, group_id = get_group_name_id(group_id) vid_node = node_collection.one({"_id": ObjectId(_id)}) title = GST_VIDEO.name video_obj=request.GET.get("vid_id","") group_obj = node_collection.one({'_id': ObjectId(group_id)}) ce_id = request.GET.get('course_event_id') course_tab_title = request.POST.get("course_tab_title",'') res = request.GET.get('res') if request.method == "POST": # get_node_common_fields(request, vid_node, group_id, GST_VIDEO) vid_node.save(is_changed=get_node_common_fields(request, vid_node, group_id, GST_VIDEO),groupid=group_id) thread_create_val = request.POST.get("thread_create",'') course_tab_title = request.POST.get("course_tab_title",'') # help_info_page = request.POST.getlist('help_info_page','') help_info_page = request.POST['help_info_page'] if help_info_page: help_info_page = json.loads(help_info_page) discussion_enable_at = node_collection.one({"_type": "AttributeType", "name": "discussion_enable"}) if thread_create_val == "Yes": create_gattribute(vid_node._id, discussion_enable_at, True) return_status = create_thread_for_node(request,group_id, vid_node) else: create_gattribute(vid_node._id, discussion_enable_at, False) # print "\n\n help_info_page ================ ",help_info_page if help_info_page and u"None" not in help_info_page: has_help_rt = node_collection.one({'_type': "RelationType", 'name': "has_help"}) try: help_info_page = map(ObjectId, help_info_page) create_grelation(vid_node._id, has_help_rt,help_info_page) except Exception as invalidobjectid: # print "\n\n ERROR -------- ",invalidobjectid pass else: # Check if node had has_help RT grel_dict = get_relation_value(vid_node._id,"has_help") # print "\n\n grel_dict ==== ", grel_dict if grel_dict: grel_id = grel_dict.get("grel_id","") if grel_id: for each_grel_id in grel_id: del_status, del_status_msg = delete_grelation( subject_id=vid_node._id, node_id=each_grel_id, deletion_type=0 ) # print "\n\n del_status == ",del_status # print "\n\n del_status_msg == ",del_status_msg if "CourseEventGroup" not in group_obj.member_of_names_list: get_node_metadata(request,vid_node) teaches_list = request.POST.get('teaches_list', '') # get the teaches list assesses_list = request.POST.get('assesses_list', '') # get the teaches list if teaches_list !='': teaches_list=teaches_list.split(",") create_grelation_list(vid_node._id,"teaches",teaches_list) if assesses_list !='': assesses_list=assesses_list.split(",") create_grelation_list(vid_node._id,"assesses",assesses_list) return HttpResponseRedirect(reverse('video_detail', kwargs={'group_id': group_id, '_id': vid_node._id})) else: vid_node.status = u"PUBLISHED" vid_node.save() if course_tab_title: if course_tab_title == "raw material": course_tab_title = "raw_material" return HttpResponseRedirect(reverse('course_'+course_tab_title + '_detail', kwargs={'group_id': group_id, 'node_id': str(vid_node._id)})) return HttpResponseRedirect(reverse('course_about', kwargs={'group_id': group_id})) # url = "/"+ str(group_id) +"/?selected="+str(vid_node._id)+"#view_page" # return HttpResponseRedirect(url) else: vid_col = node_collection.find({'member_of': GST_VIDEO._id,'group_set': ObjectId(group_id)}) nodes_list = [] for each in vid_col: nodes_list.append(str((each.name).strip().lower())) return render_to_response("ndf/video_edit.html", { 'node': vid_node, 'title': title, 'group_id': group_id, 'groupid':group_id, 'video_obj':video_obj, 'nodes_list':nodes_list, 'ce_id': ce_id, 'res': res, 'course_tab_title':course_tab_title }, context_instance=RequestContext(request) )
def theme_topic_create_edit(request, group_id, app_set_id=None): ##################### # 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 : # pass try: group_id = ObjectId(group_id) except: group_name, group_id = get_group_name_id(group_id) ###################### nodes_dict = [] create_edit = True themes_hierarchy = False themes_list_items = "" themes_cards = "" title = "" node = "" theme_topic_node = "" drawers = None drawer = None app_id = None nodes_list = [] parent_nodes_collection = "" translate=request.GET.get('translate','') app_GST = node_collection.find_one({"_id":ObjectId(app_set_id)}) if app_GST._id != theme_GST._id: app_obj = node_collection.one({'_id': ObjectId(app_GST.member_of[0])}) else: app_obj = theme_GST if app_obj: app_id = app_obj._id 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' }) shelf = triple_collection.find({'_type': 'GRelation', 'subject': ObjectId(auth._id), 'relation_type.$id': has_shelf_RT._id}) shelf_list = {} 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 = [] if request.method == "POST": if app_GST: create_edit = True themes_list_items = "" root_themes = [] root_themes_id = [] nodes_list = [] name = request.POST.get('name') collection_list = request.POST.get('collection_list','') prior_node_list = request.POST.get('prior_node_list','') teaches_list = request.POST.get('teaches_list','') assesses_list = request.POST.get('assesses_list','') # To find the root nodes to maintain the uniquness while creating and editing themes nodes = node_collection.find({'member_of': {'$all': [theme_GST._id]},'group_set':{'$all': [ObjectId(group_id)]}}) for each in nodes: if each.collection_set: for k in each.collection_set: nodes_list.append(k) nodes.rewind() for each in nodes: if each._id not in nodes_list: root_themes.append(each.name) root_themes_id.append(each._id) if app_GST.name == "Theme" or app_GST.name == "Topic" or translate == "true": # For creating new themes & Topics themes_list_items = False create_edit = False themes_hierarchy = False themes_cards = True if name or translate == "true": if not name.upper() in (theme_name.upper() for theme_name in root_themes) or translate == "true": if translate != "true": theme_topic_node = node_collection.collection.GSystem() # get_node_common_fields(request, theme_topic_node, group_id, app_GST) theme_topic_node.save(is_changed=get_node_common_fields(request, theme_topic_node, group_id, app_GST),groupid=group_id) if translate == "true": global list_trans_coll list_trans_coll = [] coll_set1=get_coll_set(app_GST._id) for each in coll_set1: theme_topic_node = node_collection.collection.GSystem() if "Theme" in each.member_of_names_list: app_obj = theme_GST if "theme_item" in each.member_of_names_list: app_obj = theme_item_GST if "topic" in each.member_of_names_list: app_obj = topic_GST theme_topic_node.save(is_changed=get_node_common_fields(request, theme_topic_node, group_id, app_obj, each),groupid=group_id) coll_set_dict[each._id]=theme_topic_node._id relation_type = node_collection.one({'_type':'RelationType', 'name':'translation_of'}) # grelation=collection.GRelation() # grelation.relation_type=relation_type # grelation.subject=each._id # grelation.right_subject=theme_topic_node._id # grelation.name=u"" # grelation.save() gr_node = create_grelation(each._id, relation_type, theme_topic_node._id) for each in coll_set1: #if "Theme" in each.member_of_names_list: if each.collection_set: for collset in each.collection_set: p=coll_set_dict[each._id] parent_node = node_collection.one({'_id':ObjectId(str(p))}) n= coll_set_dict[collset] sub_node = node_collection.one({'_id':ObjectId(str(n))}) parent_node.collection_set.append(sub_node._id) parent_node.save(groupid=group_id) # To return themes card view for listing theme nodes after creating new Themes nodes.rewind() nodes_dict = nodes else: themes_list_items = False create_edit = False themes_hierarchy = True theme_topic_node = node_collection.one({'_id': ObjectId(app_GST._id)}) # For edititng themes if theme_GST._id in app_GST.member_of and translate != "true": # To find themes uniqueness within the context of its parent Theme collection, while editing theme name root_themes = [] nodes = node_collection.find({'member_of': {'$all': [theme_GST._id]},'group_set':{'$all': [ObjectId(group_id)]}}) for each in nodes: root_themes.append(each.name) if name: if name.upper() != theme_topic_node.name.upper(): if not name.upper() in (theme_name.upper() for theme_name in root_themes): # get_node_common_fields(request, theme_topic_node, group_id, theme_GST) theme_topic_node.save(is_changed=get_node_common_fields(request, theme_topic_node, group_id, theme_GST),groupid=group_id) else: theme_topic_node.save(is_changed=get_node_common_fields(request, theme_topic_node, group_id, theme_GST),groupid=group_id) if translate != "true": # For storing and maintaning collection order if collection_list != '': theme_topic_node.collection_set = [] collection_list = collection_list.split(",") i = 0 while (i < len(collection_list)): node_id = ObjectId(collection_list[i]) if node_collection.one({"_id": node_id}): theme_topic_node.collection_set.append(node_id) i = i+1 theme_topic_node.save(groupid=group_id) # End of storing collection title = theme_GST.name nodes.rewind() nodes_dict = nodes # This will return to Themes Hierarchy themes_list_items = False create_edit = False themes_hierarchy = False themes_cards = True elif theme_item_GST._id in app_GST.member_of and translate != "true": title = "Theme Item" dict_drawer = {} dict2 = [] node = app_GST prior_theme_collection = [] parent_nodes_collection = "" # To display the theme-topic drawer while create or edit theme checked = "theme_item" # drawers = get_drawers(group_id, node._id, node.collection_set, checked) # Code for fetching drawer2 for k in node.collection_set: obj = node_collection.one({'_id': ObjectId(k) }) dict2.append(obj) dict_drawer['2'] = dict2 # drawers = dict_drawer # End of code for drawer2 drawer = dict_drawer['2'] # To find themes uniqueness within the context of its parent Theme collection, while editing theme item nodes = node_collection.find({'member_of': {'$all': [theme_item_GST._id]},'group_set':{'$all': [ObjectId(group_id)]}}) for each in nodes: if app_GST._id in each.collection_set: for k in each.collection_set: prior_theme = node_collection.one({'_id': ObjectId(k) }) prior_theme_collection.append(prior_theme.name) parent_nodes_collection = json.dumps(prior_theme_collection) if not prior_theme_collection: root_nodes = node_collection.find({'member_of': {'$all': [theme_GST._id]},'group_set':{'$all': [ObjectId(group_id)]}}) for k in root_nodes: if app_GST._id in k.collection_set: root_themes = [] root_themes_id = [] for l in k.collection_set: objs = node_collection.one({'_id': ObjectId(l)}) root_themes.append(objs.name) root_themes_id.append(objs._id) # End of finding unique theme names for editing name # For adding a sub-theme-items and maintianing their uniqueness within their context nodes_list = [] for each in app_GST.collection_set: sub_theme = node_collection.one({'_id': ObjectId(each) }) nodes_list.append(sub_theme.name) nodes_list = json.dumps(nodes_list) # End of finding unique sub themes if name: if name.upper() != theme_topic_node.name.upper(): # If "Name" has changed if theme_topic_node._id in root_themes_id: # If editing node in root theme items if not name.upper() in (theme_name.upper() for theme_name in root_themes): # get_node_common_fields(request, theme_topic_node, group_id, theme_GST) theme_topic_node.save(is_changed=get_node_common_fields(request, theme_topic_node, group_id, theme_item_GST),groupid=group_id) else: # If editing theme item in prior_theme_collection hierarchy if not name.upper() in (theme_name.upper() for theme_name in prior_theme_collection): # get_node_common_fields(request, theme_topic_node, group_id, theme_GST) theme_topic_node.save(is_changed=get_node_common_fields(request, theme_topic_node, group_id, theme_item_GST),groupid=group_id) else: # If name not changed but other fields has changed theme_topic_node.save(is_changed=get_node_common_fields(request, theme_topic_node, group_id, theme_item_GST),groupid=group_id) if translate != "true" and collection_list: # For storing and maintaning collection order if collection_list != '': theme_topic_node.collection_set = [] collection_list = collection_list.split(",") i = 0 while (i < len(collection_list)): node_id = ObjectId(collection_list[i]) if node_collection.one({"_id": node_id}): theme_topic_node.collection_set.append(node_id) i = i+1 theme_topic_node.save(groupid=group_id) # End of storing collection # This will return to Themes items edit if theme_topic_node: theme_topic_node.reload() node = theme_topic_node create_edit = True themes_hierarchy = False # For editing topics elif topic_GST._id in app_GST.member_of: root_topics = [] nodes_list = [] # To find the root nodes to maintain the uniquness while creating and editing topics nodes = node_collection.find({'member_of': {'$all': [topic_GST._id]},'group_set':{'$all': [ObjectId(group_id)]}}) for each in nodes: if each.collection_set: for k in each.collection_set: nodes_list.append(k) nodes.rewind() for each in nodes: if each._id not in nodes_list: root_topics.append(each.name) # End of finding the root nodes if name: if theme_topic_node.name != name: topic_name = theme_topic_node.name if not name.upper() in (theme_name.upper() for theme_name in root_topics): theme_topic_node.save(is_changed=get_node_common_fields(request, theme_topic_node, group_id, topic_GST),groupid=group_id) elif topic_name.upper() == name.upper(): theme_topic_node.save(is_changed=get_node_common_fields(request, theme_topic_node, group_id, topic_GST),groupid=group_id) else: theme_topic_node.save(is_changed=get_node_common_fields(request, theme_topic_node, group_id, topic_GST),groupid=group_id) if collection_list: # For storing and maintaning collection order if collection_list != '': theme_topic_node.collection_set = [] collection_list = collection_list.split(",") i = 0 while (i < len(collection_list)): node_id = ObjectId(collection_list[i]) if node_collection.one({"_id": node_id}): theme_topic_node.collection_set.append(node_id) i = i+1 theme_topic_node.save(groupid=group_id) title = topic_GST.name # To fill the metadata info while creating and editing topic node metadata = request.POST.get("metadata_info", '') if metadata: # Only while metadata editing if metadata == "metadata": if theme_topic_node: get_node_metadata(request,theme_topic_node) # End of filling metadata if prior_node_list != '': theme_topic_node.prior_node = [] prior_node_list = prior_node_list.split(",") i = 0 while (i < len(prior_node_list)): node_id = ObjectId(prior_node_list[i]) if node_collection.one({"_id": node_id}): theme_topic_node.prior_node.append(node_id) i = i+1 theme_topic_node.save(groupid=group_id) if teaches_list !='': teaches_list=teaches_list.split(",") create_grelation_list(theme_topic_node._id,"teaches",teaches_list) if assesses_list !='': assesses_list=assesses_list.split(",") create_grelation_list(theme_topic_node._id,"assesses",assesses_list) # This will return to edit topic if theme_topic_node: theme_topic_node.reload() node = theme_topic_node create_edit = True themes_hierarchy = False else: app_node = None nodes_list = [] app_GST = node_collection.find_one({"_id":ObjectId(app_set_id)}) # print "\napp_GST in else: ",app_GST.name,"\n" if app_GST: # For adding new Theme & Topic if app_GST.name == "Theme" or app_GST.name == "Topic" or translate == True: print "22222" title = app_GST.name node = "" root_themes = [] # To find the root nodes to maintain the uniquness while creating new themes nodes = node_collection.find({'member_of': {'$all': [app_GST._id]},'group_set':{'$all': [ObjectId(group_id)]}}) for each in nodes: if each.collection_set: for k in each.collection_set: nodes_list.append(k) nodes.rewind() for each in nodes: if each._id not in nodes_list: root_themes.append(each.name) root_themes = json.dumps(root_themes) nodes_list = root_themes # End of finding unique root level Themes else: if theme_GST._id in app_GST.member_of: title = "Theme" node = app_GST prior_theme_collection = [] parent_nodes_collection = "" drawer = [] # End of editing Themes # For editing theme item if theme_item_GST._id in app_GST.member_of: title = "Theme Item" dict_drawer = {} dict2 = [] node = app_GST prior_theme_collection = [] parent_nodes_collection = "" # To display the theme-topic drawer while create or edit theme checked = "theme_item" # drawers = get_drawers(group_id, node._id, node.collection_set, checked) for k in node.collection_set: obj = node_collection.one({'_id': ObjectId(k) }) dict2.append(obj) dict_drawer['2'] = dict2 drawer = dict_drawer['2'] # To find themes uniqueness within the context of its parent Theme collection, while editing theme name nodes = node_collection.find({'member_of': {'$all': [theme_item_GST._id]},'group_set':{'$all': [ObjectId(group_id)]}}) for each in nodes: if app_GST._id in each.collection_set: for k in each.collection_set: prior_theme = node_collection.one({'_id': ObjectId(k) }) prior_theme_collection.append(prior_theme.name) parent_nodes_collection = json.dumps(prior_theme_collection) # End of finding unique theme names for editing name # For adding a sub-themes and maintianing their uniqueness within their context for each in app_GST.collection_set: sub_theme = node_collection.one({'_id': ObjectId(each) }) nodes_list.append(sub_theme.name) nodes_list = json.dumps(nodes_list) # End of finding unique sub themes # for editing topic elif topic_GST._id in app_GST.member_of: title = topic_GST.name node = app_GST prior_theme_collection = [] parent_nodes_collection = "" node.get_neighbourhood(node.member_of) # To find topics uniqueness within the context of its parent Theme item collection, while editing topic name nodes = node_collection.find({'member_of': {'$all': [theme_item_GST._id]},'group_set':{'$all': [ObjectId(group_id)]}}) for each in nodes: if app_GST._id in each.collection_set: for k in each.collection_set: prior_theme = node_collection.one({'_id': ObjectId(k) }) prior_theme_collection.append(prior_theme.name) parent_nodes_collection = json.dumps(prior_theme_collection) # End of finding unique theme names for editing name if translate: global list_trans_coll list_trans_coll = [] trans_coll_list = get_coll_set(str(app_GST._id)) print LANGUAGES return render_to_response("ndf/translation_page.html", {'group_id': group_id,'groupid': group_id,'title': title, 'node': app_GST, 'lan':LANGUAGES, 'list1':trans_coll_list },context_instance = RequestContext(request) ) if title == "Topic": return render_to_response("ndf/node_edit_base.html", {'group_id': group_id,'groupid': group_id, 'drawer': drawer, 'themes_cards': themes_cards, '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, 'theme_GST_id': theme_GST._id,'theme_item_GST_id': theme_item_GST._id, 'topic_GST_id': topic_GST._id, 'themes_list_items': themes_list_items,'nodes':nodes_dict,'lan':LANGUAGES },context_instance = RequestContext(request) ) return render_to_response("ndf/theme.html", {'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, 'theme_GST_id': theme_GST._id,'theme_item_GST_id': theme_item_GST._id, 'topic_GST_id': topic_GST._id, 'themes_list_items': themes_list_items,'nodes':nodes_dict,'lan':LANGUAGES },context_instance = RequestContext(request) )