def create_edit_page(request, group_id, node_id=None): """Creates/Modifies details about the given quiz-item. """ # 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 group_name, group_id = get_group_name_id(group_id) ce_id = request.GET.get('course_event_id', '') blog_type = request.GET.get('blog_type', '') res = request.GET.get('res', '') program_res = request.GET.get('program_res', '') context_variables = { 'title': gst_page.name, 'group_id': group_id, 'groupid': group_id, 'ce_id': ce_id, 'res': res, 'program_res': program_res, 'blog_type': blog_type } group_obj = node_collection.one({'_id': ObjectId(group_id)}) available_nodes = node_collection.find({ '_type': u'GSystem', 'member_of': ObjectId(gst_page._id), 'group_set': ObjectId(group_id), '_id': { '$ne': ObjectId(node_id) } }) nodes_list = [] thread = None url_name = "/home" # for each in available_nodes: # nodes_list.append(str((each.name).strip().lower())) # loop replaced by a list comprehension node_list = [str((each.name).strip().lower()) for each in available_nodes] # print "available_nodes: ", node_list if request.method == "POST": # get_node_common_fields(request, page_node, group_id, gst_page) page_name = request.POST.get('name', '') # print "====== page_name: ", page_name if page_name.strip().lower() in node_list and not node_id: new_page = False return render_to_response("error_base.html", { 'message': 'Page with same name already exists in the group!' }, context_instance=RequestContext(request)) elif node_id: new_page = False page_node = node_collection.one({ '_type': u'GSystem', '_id': ObjectId(node_id) }) else: new_page = True page_node = node_collection.collection.GSystem() # page_type = request.POST.getlist("type_of",'') ce_id = request.POST.get("ce_id", '') blog_type = request.POST.get('blog_type', '') res = request.POST.get("res", '') program_res = request.POST.get('program_res', '') # we are fetching the value of release_response flag # if this is set, it means, we can proceed to create a thread node # for the current page node. thread_create_val = request.POST.get("thread_create", '') # print "\n\n thread_create_val", thread_create_val # print "\n\n request.POST === ",request.POST # raise Exception("demo") # 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) # print "\n\n help_info_page === ",help_info_page #program_res and res are boolean values if program_res: program_res = eval(program_res) if res: res = eval(res) if blog_type: blog_type = eval(blog_type) # if page_type: # objid= page_type[0] # if not ObjectId(objid) in page_node.type_of: # page_type1=[] # page_type1.append(ObjectId(objid)) # page_node.type_of = page_type1 # page_node.type_of page_node.save(is_changed=get_node_common_fields( request, page_node, group_id, gst_page)) # if course event grp's id is passed, it means # its a blog page added in notebook and hence set type_of field as "Blog page" # print "\n\n blog_type---",blog_type if blog_type: blogpage_gst = node_collection.one({ '_type': "GSystemType", 'name': "Blog page" }) page_node.type_of = [blogpage_gst._id] elif GSTUDIO_SITE_NAME == "NROER" and "Author" in group_obj.member_of_names_list: infopage_gst = node_collection.one({ '_type': "GSystemType", 'name': "Info page" }) page_node.type_of = [infopage_gst._id] # if the page created is as a resource in course or program event, # set status to PUBLISHED by default # one major reason for this, ONLY published nodes can be replicated. if res or program_res or ce_id: page_node.status = u"PUBLISHED" page_node.save() # if page is created in program event, add page_node to group's collection set if program_res: group_obj = node_collection.one({'_id': ObjectId(group_id)}) group_obj.collection_set.append(page_node._id) group_obj.save() discussion_enable_at = node_collection.one({ "_type": "AttributeType", "name": "discussion_enable" }) if thread_create_val == "Yes" or blog_type: create_gattribute(page_node._id, discussion_enable_at, True) return_status = create_thread_for_node(request, group_id, page_node) else: create_gattribute(page_node._id, discussion_enable_at, False) # print "\n\n help_info_page ================ ",help_info_page if "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(page_node._id, has_help_rt, help_info_page) page_node.reload() except Exception as invalidobjectid: # print invalidobjectid pass else: # Check if node had has_help RT grel_dict = get_relation_value(page_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=page_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 # To fill the metadata info while creating and editing page node metadata = request.POST.get("metadata_info", '') if "CourseEventGroup" in group_obj.member_of_names_list and blog_type: if new_page: # counter_obj = Counter.get_counter_obj(request.user.id,ObjectId(group_id)) # # counter_obj.no_notes_written=counter_obj.no_notes_written+1 # counter_obj['page']['blog']['created'] += 1 # # counter_obj.course_score += GSTUDIO_NOTE_CREATE_POINTS # counter_obj['group_points'] += GSTUDIO_NOTE_CREATE_POINTS # counter_obj.last_update = datetime.datetime.now() # counter_obj.save() active_user_ids_list = [request.user.id] if GSTUDIO_BUDDY_LOGIN: active_user_ids_list += Buddy.get_buddy_userids_list_within_datetime( request.user.id, datetime.datetime.now()) # removing redundancy of user ids: active_user_ids_list = dict.fromkeys( active_user_ids_list).keys() counter_objs_cur = Counter.get_counter_objs_cur( active_user_ids_list, group_id) for each_counter_obj in counter_objs_cur: each_counter_obj['page']['blog']['created'] += 1 each_counter_obj[ 'group_points'] += GSTUDIO_NOTE_CREATE_POINTS each_counter_obj.last_update = datetime.datetime.now() each_counter_obj.save() return HttpResponseRedirect( reverse('course_notebook_tab_note', kwargs={ 'group_id': group_id, 'tab': 'my-notes', 'notebook_id': page_node._id })) if ce_id or res or program_res: url_name = "/" + group_name + "/" + str(page_node._id) if ce_id: # url_name = "/" + group_name + "/#journal-tab" url_name = "/" + group_name if res or program_res: url_name = "/" + group_name + "/?selected=" + str( page_node._id) + "#view_page" # print "\n\n url_name---",url_name return HttpResponseRedirect(url_name) if metadata: # Only while metadata editing if metadata == "metadata": if page_node: get_node_metadata(request, page_node, is_changed=True) # End of filling metadata return HttpResponseRedirect( reverse('page_details', kwargs={ 'group_id': group_id, 'app_id': page_node._id })) else: if node_id: page_node = node_collection.one({ '_type': u'GSystem', '_id': ObjectId(node_id) }) #page_node,ver=get_page(request,page_node) page_node.get_neighbourhood(page_node.member_of) context_variables['node'] = page_node context_variables['groupid'] = group_id context_variables['group_id'] = group_id # fetch Page instances # Page_node = node_collection.find_one({'_type':"GSystemType","name":"Page"}) page_instances = node_collection.find({"type_of": gst_page._id}) page_ins_list = [i for i in page_instances] context_variables['page_instance'] = page_ins_list context_variables['nodes_list'] = json.dumps(nodes_list) # print "\n\n context_variables----\n",context_variables return render_to_response("ndf/page_create_edit.html", context_variables, 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': 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 data_review_save(request, group_id): ''' Method to save each and every data-row edit of data review app ''' userid = request.user.pk try: group_id = ObjectId(group_id) except: group_name, group_id = get_group_name_id(group_id) group_obj = node_collection.one({"_id": ObjectId(group_id)}) node_oid = request.POST.get("node_oid", "") node_details = request.POST.get("node_details", "") node_details = json.loads(node_details) # print "node_details : ", node_details # updating some key names of dictionary as per get_node_common_fields. node_details["lan"] = node_details.pop("language") node_details["prior_node_list"] = node_details.pop("prior_node") node_details["login-mode"] = node_details.pop("access_policy") status = node_details.pop("status") # node_details["collection_list"] = node_details.pop("collection") for future use # Making copy of POST QueryDict instance. # To make it mutable and fill in node_details value/s. post_req = request.POST.copy() # removing node_details dict from req post_req.pop('node_details') # adding values to post req post_req.update(node_details) # overwriting request.POST with newly created QueryDict instance post_req request.POST = post_req # print "\n---\n", request.POST, "\n---\n" license = request.POST.get('license', '') file_node = node_collection.one({"_id": ObjectId(node_oid)}) if request.method == "POST": edit_summary = [] file_node_before = file_node.copy( ) # copying before it is getting modified is_changed = get_node_common_fields(request, file_node, group_id, GST_FILE) for key, val in file_node_before.iteritems(): if file_node_before[key] != file_node[key]: temp_edit_summ = {} temp_edit_summ["name"] = "Field: " + key temp_edit_summ["before"] = file_node_before[key] temp_edit_summ["after"] = file_node[key] edit_summary.append(temp_edit_summ) # to fill/update attributes of the node and get updated attrs as return ga_nodes = get_node_metadata(request, file_node, is_changed=True) if len(ga_nodes): is_changed = True # adding the edit attribute name in summary for each_ga in ga_nodes: temp_edit_summ = {} temp_edit_summ["name"] = "Attribute: " + each_ga["node"][ "attribute_type"]["name"] temp_edit_summ["before"] = each_ga["before_obj_value"] temp_edit_summ["after"] = each_ga["node"]["object_value"] edit_summary.append(temp_edit_summ) teaches_list = request.POST.get('teaches', '') # get the teaches list prev_teaches_list = request.POST.get( "teaches_prev", "") # get the before-edit teaches list # check if teaches list exist means nodes added/removed for teaches relation_type # also check for if previous teaches list made empty with prev_teaches_list if (teaches_list != '') or prev_teaches_list: teaches_list = teaches_list.split(",") if teaches_list else [] teaches_list = [ObjectId(each_oid) for each_oid in teaches_list] relation_type_node = node_collection.one({ '_type': "RelationType", 'name': 'teaches' }) gr_nodes = create_grelation(file_node._id, relation_type_node, teaches_list) gr_nodes_oid_list = [ ObjectId(each_oid["right_subject"]) for each_oid in gr_nodes ] if gr_nodes else [] prev_teaches_list = prev_teaches_list.split( ",") if prev_teaches_list else [] prev_teaches_list = [ ObjectId(each_oid) for each_oid in prev_teaches_list ] if len(gr_nodes_oid_list) == len(prev_teaches_list) and set( gr_nodes_oid_list) == set(prev_teaches_list): pass else: rel_nodes = triple_collection.find({ '_type': "GRelation", 'subject': file_node._id, 'relation_type': relation_type_node._id }) rel_oid_name = {} for each in rel_nodes: temp = {} temp[each.right_subject] = each.name rel_oid_name.update(temp) is_changed = True temp_edit_summ = {} temp_edit_summ["name"] = "Relation: Teaches" temp_edit_summ["before"] = [ rel_oid_name[each_oid].split(" -- ")[2] for each_oid in prev_teaches_list ] temp_edit_summ["after"] = [ rel_oid_name[each_oid].split(" -- ")[2] for each_oid in gr_nodes_oid_list ] edit_summary.append(temp_edit_summ) assesses_list = request.POST.get('assesses_list', '') if assesses_list != '': assesses_list = assesses_list.split(",") assesses_list = [ObjectId(each_oid) for each_oid in assesses_list] relation_type_node = node_collection.one({ '_type': "RelationType", 'name': 'assesses' }) gr_nodes = create_grelation(file_node._id, relation_type_node, teaches_list) gr_nodes_oid_list = [ ObjectId(each_oid["right_subject"]) for each_oid in gr_nodes ] if len(gr_nodes_oid_list) == len(teaches_list) and set( gr_nodes_oid_list) == set(teaches_list): pass else: is_changed = True # changing status to draft even if attributes/relations are changed if is_changed: file_node.status = unicode("DRAFT") file_node.modified_by = userid if userid not in file_node.contributors: file_node.contributors.append(userid) # checking if user is authenticated to change the status of node if status and ((group_obj.is_gstaff(request.user)) or (userid in group_obj.author_set)): if file_node.status != status: file_node.status = unicode(status) file_node.modified_by = userid if userid not in file_node.contributors: file_node.contributors.append(userid) is_changed = True if is_changed: file_node.save(groupid=group_id) # print edit_summary return HttpResponse(file_node.status)
def create_edit_page(request, group_id, node_id=None): """Creates/Modifies details about the given quiz-item. """ # 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 group_name, group_id = get_group_name_id(group_id) ce_id = request.GET.get('course_event_id','') blog_type = request.GET.get('blog_type','') res = request.GET.get('res','') program_res = request.GET.get('program_res','') context_variables = { 'title': gst_page.name, 'group_id': group_id, 'groupid': group_id, 'ce_id': ce_id, 'res':res, 'program_res':program_res, 'blog_type': blog_type } group_obj = node_collection.one({'_id': ObjectId(group_id)}) available_nodes = node_collection.find({'_type': u'GSystem', 'member_of': ObjectId(gst_page._id),'group_set': ObjectId(group_id), '_id': {'$ne': ObjectId(node_id)} }) nodes_list = [] thread = None url_name = "/home" # for each in available_nodes: # nodes_list.append(str((each.name).strip().lower())) # loop replaced by a list comprehension node_list = [str((each.name).strip().lower()) for each in available_nodes] # print "available_nodes: ", node_list if request.method == "POST": # get_node_common_fields(request, page_node, group_id, gst_page) page_name = request.POST.get('name', '') # print "====== page_name: ", page_name if page_name.strip().lower() in node_list and not node_id: new_page=False return render_to_response("error_base.html", {'message': 'Page with same name already exists in the group!'}, context_instance=RequestContext(request)) elif node_id: new_page = False page_node = node_collection.one({'_type': u'GSystem', '_id': ObjectId(node_id)}) else: new_page = True page_node = node_collection.collection.GSystem() # page_type = request.POST.getlist("type_of",'') ce_id = request.POST.get("ce_id",'') blog_type = request.POST.get('blog_type','') res = request.POST.get("res",'') program_res = request.POST.get('program_res','') # we are fetching the value of release_response flag # if this is set, it means, we can proceed to create a thread node # for the current page node. thread_create_val = request.POST.get("thread_create",'') # print "\n\n thread_create_val", thread_create_val # print "\n\n request.POST === ",request.POST # raise Exception("demo") # 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) # print "\n\n help_info_page === ",help_info_page #program_res and res are boolean values if program_res: program_res = eval(program_res) if res: res = eval(res) if blog_type: blog_type = eval(blog_type) # if page_type: # objid= page_type[0] # if not ObjectId(objid) in page_node.type_of: # page_type1=[] # page_type1.append(ObjectId(objid)) # page_node.type_of = page_type1 # page_node.type_of page_node.save(is_changed=get_node_common_fields(request, page_node, group_id, gst_page)) # if course event grp's id is passed, it means # its a blog page added in notebook and hence set type_of field as "Blog page" # print "\n\n blog_type---",blog_type if blog_type: blogpage_gst = node_collection.one({'_type': "GSystemType", 'name': "Blog page"}) page_node.type_of = [blogpage_gst._id] elif GSTUDIO_SITE_NAME == "NROER" and "Author" in group_obj.member_of_names_list: infopage_gst = node_collection.one({'_type': "GSystemType", 'name': "Info page"}) page_node.type_of = [infopage_gst._id] # if the page created is as a resource in course or program event, # set status to PUBLISHED by default # one major reason for this, ONLY published nodes can be replicated. if res or program_res or ce_id: page_node.status = u"PUBLISHED" page_node.save() # if page is created in program event, add page_node to group's collection set if program_res: group_obj = node_collection.one({'_id': ObjectId(group_id)}) group_obj.collection_set.append(page_node._id) group_obj.save() discussion_enable_at = node_collection.one({"_type": "AttributeType", "name": "discussion_enable"}) if thread_create_val == "Yes" or blog_type: create_gattribute(page_node._id, discussion_enable_at, True) return_status = create_thread_for_node(request,group_id, page_node) else: create_gattribute(page_node._id, discussion_enable_at, False) # print "\n\n help_info_page ================ ",help_info_page if "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(page_node._id, has_help_rt,help_info_page) page_node.reload() except Exception as invalidobjectid: # print invalidobjectid pass else: # Check if node had has_help RT grel_dict = get_relation_value(page_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=page_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 # To fill the metadata info while creating and editing page node metadata = request.POST.get("metadata_info", '') if "CourseEventGroup" in group_obj.member_of_names_list and blog_type: if new_page: # counter_obj = Counter.get_counter_obj(request.user.id,ObjectId(group_id)) # # counter_obj.no_notes_written=counter_obj.no_notes_written+1 # counter_obj['page']['blog']['created'] += 1 # # counter_obj.course_score += GSTUDIO_NOTE_CREATE_POINTS # counter_obj['group_points'] += GSTUDIO_NOTE_CREATE_POINTS # counter_obj.last_update = datetime.datetime.now() # counter_obj.save() active_user_ids_list = [request.user.id] if GSTUDIO_BUDDY_LOGIN: active_user_ids_list += Buddy.get_buddy_userids_list_within_datetime(request.user.id, datetime.datetime.now()) # removing redundancy of user ids: active_user_ids_list = dict.fromkeys(active_user_ids_list).keys() counter_objs_cur = Counter.get_counter_objs_cur(active_user_ids_list, group_id) for each_counter_obj in counter_objs_cur: each_counter_obj['page']['blog']['created'] += 1 each_counter_obj['group_points'] += GSTUDIO_NOTE_CREATE_POINTS each_counter_obj.last_update = datetime.datetime.now() each_counter_obj.save() return HttpResponseRedirect(reverse('course_notebook_tab_note', kwargs={ 'group_id': group_id, 'tab': 'my-notes', 'notebook_id': page_node._id }) ) if ce_id or res or program_res: url_name = "/" + group_name + "/" + str(page_node._id) if ce_id: # url_name = "/" + group_name + "/#journal-tab" url_name = "/" + group_name if res or program_res: url_name = "/" + group_name + "/?selected=" + str(page_node._id) + "#view_page" # print "\n\n url_name---",url_name return HttpResponseRedirect(url_name) if metadata: # Only while metadata editing if metadata == "metadata": if page_node: get_node_metadata(request,page_node,is_changed=True) # End of filling metadata return HttpResponseRedirect(reverse('page_details', kwargs={'group_id': group_id, 'app_id': page_node._id })) else: if node_id: page_node = node_collection.one({'_type': u'GSystem', '_id': ObjectId(node_id)}) #page_node,ver=get_page(request,page_node) page_node.get_neighbourhood(page_node.member_of) context_variables['node'] = page_node context_variables['groupid'] = group_id context_variables['group_id'] = group_id # fetch Page instances # Page_node = node_collection.find_one({'_type':"GSystemType","name":"Page"}) page_instances = node_collection.find({"type_of": gst_page._id}) page_ins_list = [i for i in page_instances] context_variables['page_instance'] = page_ins_list context_variables['nodes_list'] = json.dumps(nodes_list) # print "\n\n context_variables----\n",context_variables return render_to_response("ndf/page_create_edit.html", context_variables, 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) )
def create_edit_term(request, group_id, node_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) context_variables = { 'title': title, 'group_id': group_id, 'groupid': group_id } # To list all term instances terms_list = node_collection.find({'_type': 'GSystem', 'member_of': {'$all': [ObjectId(term_GST._id), ObjectId(topic_GST._id)]}, 'group_set': ObjectId(group_id) }).sort('name', 1) nodes_list = [] for each in terms_list: nodes_list.append(str((each.name).strip().lower())) if node_id: term_node = node_collection.one({'_id': ObjectId(node_id)}) else: term_node = node_collection.collection.GSystem() if request.method == "POST": # get_node_common_fields(request, page_node, group_id, gst_page) term_node.save(is_changed=get_node_common_fields(request, term_node, group_id, term_GST),groupid=group_id) get_node_metadata(request,term_node,term_GST) return HttpResponseRedirect(reverse('term_details', kwargs={'group_id': group_id, 'node_id': term_node._id })) else: if node_id: term_node,ver=get_page(request,term_node) term_node.get_neighbourhood(term_node.member_of) context_variables['node'] = term_node context_variables['groupid']=group_id context_variables['group_id']=group_id context_variables['nodes_list'] = json.dumps(nodes_list) else: context_variables['nodes_list'] = json.dumps(nodes_list) return render_to_response("ndf/term_create_edit.html", context_variables, context_instance=RequestContext(request) )
def create_edit_term(request, group_id, node_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) context_variables = { 'title': title, 'group_id': group_id, 'groupid': group_id } # To list all term instances terms_list = node_collection.find({ '_type': 'GSystem', 'member_of': { '$all': [ObjectId(term_GST._id), ObjectId(topic_GST._id)] }, 'group_set': ObjectId(group_id) }).sort('name', 1) nodes_list = [] for each in terms_list: nodes_list.append(str((each.name).strip().lower())) if node_id: term_node = node_collection.one({'_id': ObjectId(node_id)}) else: term_node = node_collection.collection.GSystem() if request.method == "POST": # get_node_common_fields(request, page_node, group_id, gst_page) term_node.save(is_changed=get_node_common_fields( request, term_node, group_id, term_GST), groupid=group_id) get_node_metadata(request, term_node, term_GST) return HttpResponseRedirect( reverse('term_details', kwargs={ 'group_id': group_id, 'node_id': term_node._id })) else: if node_id: term_node, ver = get_page(request, term_node) term_node.get_neighbourhood(term_node.member_of) context_variables['node'] = term_node context_variables['groupid'] = group_id context_variables['group_id'] = group_id context_variables['nodes_list'] = json.dumps(nodes_list) else: context_variables['nodes_list'] = json.dumps(nodes_list) return render_to_response("ndf/term_create_edit.html", context_variables, context_instance=RequestContext(request))
def data_review_save(request, group_id): ''' Method to save each and every data-row edit of data review app ''' userid = request.user.pk try: group_id = ObjectId(group_id) except: group_name, group_id = get_group_name_id(group_id) group_obj = node_collection.one({"_id": ObjectId(group_id)}) node_oid = request.POST.get("node_oid", "") node_details = request.POST.get("node_details", "") node_details = json.loads(node_details) # print "node_details : ", node_details # updating some key names of dictionary as per get_node_common_fields. node_details["lan"] = node_details.pop("language") node_details["prior_node_list"] = node_details.pop("prior_node") node_details["login-mode"] = node_details.pop("access_policy") status = node_details.pop("status") # node_details["collection_list"] = node_details.pop("collection") for future use # Making copy of POST QueryDict instance. # To make it mutable and fill in node_details value/s. post_req = request.POST.copy() # removing node_details dict from req post_req.pop('node_details') # adding values to post req post_req.update(node_details) # overwriting request.POST with newly created QueryDict instance post_req request.POST = post_req # print "\n---\n", request.POST, "\n---\n" copyright = request.POST.get('copyright', '') file_node = node_collection.one({"_id": ObjectId(node_oid)}) if request.method == "POST": edit_summary = [] file_node_before = file_node.copy() # copying before it is getting modified is_changed = get_node_common_fields(request, file_node, group_id, GST_FILE) for key, val in file_node_before.iteritems(): if file_node_before[key] != file_node[key]: temp_edit_summ = {} temp_edit_summ["name"] = "Field: " + key temp_edit_summ["before"] = file_node_before[key] temp_edit_summ["after"] = file_node[key] edit_summary.append(temp_edit_summ) # to fill/update attributes of the node and get updated attrs as return ga_nodes = get_node_metadata(request, file_node, is_changed=True) if len(ga_nodes): is_changed = True # adding the edit attribute name in summary for each_ga in ga_nodes: temp_edit_summ = {} temp_edit_summ["name"] = "Attribute: " + each_ga["node"]["attribute_type"]["name"] temp_edit_summ["before"] = each_ga["before_obj_value"] temp_edit_summ["after"] = each_ga["node"]["object_value"] edit_summary.append(temp_edit_summ) teaches_list = request.POST.get('teaches', '') # get the teaches list prev_teaches_list = request.POST.get("teaches_prev", "") # get the before-edit teaches list # check if teaches list exist means nodes added/removed for teaches relation_type # also check for if previous teaches list made empty with prev_teaches_list if (teaches_list != '') or prev_teaches_list: teaches_list = teaches_list.split(",") if teaches_list else [] teaches_list = [ObjectId(each_oid) for each_oid in teaches_list] relation_type_node = node_collection.one({'_type': "RelationType", 'name':'teaches'}) gr_nodes = create_grelation(file_node._id, relation_type_node, teaches_list) gr_nodes_oid_list = [ObjectId(each_oid["right_subject"]) for each_oid in gr_nodes] if gr_nodes else [] prev_teaches_list = prev_teaches_list.split(",") if prev_teaches_list else [] prev_teaches_list = [ObjectId(each_oid) for each_oid in prev_teaches_list] if len(gr_nodes_oid_list) == len(prev_teaches_list) and set(gr_nodes_oid_list) == set(prev_teaches_list): pass else: rel_nodes = triple_collection.find({'_type': "GRelation", 'subject': file_node._id, 'relation_type': relation_type_node._id }) rel_oid_name = {} for each in rel_nodes: temp = {} temp[each.right_subject] = each.name rel_oid_name.update(temp) is_changed = True temp_edit_summ = {} temp_edit_summ["name"] = "Relation: Teaches" temp_edit_summ["before"] = [rel_oid_name[each_oid].split(" -- ")[2] for each_oid in prev_teaches_list] temp_edit_summ["after"] = [rel_oid_name[each_oid].split(" -- ")[2] for each_oid in gr_nodes_oid_list] edit_summary.append(temp_edit_summ) assesses_list = request.POST.get('assesses_list','') if assesses_list != '': assesses_list = assesses_list.split(",") assesses_list = [ObjectId(each_oid) for each_oid in assesses_list] relation_type_node = node_collection.one({'_type': "RelationType", 'name':'assesses'}) gr_nodes = create_grelation(file_node._id, relation_type_node, teaches_list) gr_nodes_oid_list = [ObjectId(each_oid["right_subject"]) for each_oid in gr_nodes] if len(gr_nodes_oid_list) == len(teaches_list) and set(gr_nodes_oid_list) == set(teaches_list): pass else: is_changed = True # changing status to draft even if attributes/relations are changed if is_changed: file_node.status = unicode("DRAFT") file_node.modified_by = userid if userid not in file_node.contributors: file_node.contributors.append(userid) # checking if user is authenticated to change the status of node if status and ((group_obj.is_gstaff(request.user)) or (userid in group_obj.author_set)): if file_node.status != status: file_node.status = unicode(status) file_node.modified_by = userid if userid not in file_node.contributors: file_node.contributors.append(userid) is_changed = True if is_changed: file_node.save(groupid=group_id) # print edit_summary return HttpResponse(file_node.status)