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 node_create_edit(request, group_id=None, member_of=None, detail_url_name=None, node_type='GSystem', node_id=None): ''' creation as well as edit of node ''' # check for POST method to node update operation if request.method == "POST": # put validations if node_type not in node_collection.db.connection._registered_documents.keys(): raise ValueError('Improper node_type passed') kwargs={} group_name, group_id = Group.get_group_name_id(group_id) member_of_name, member_of_id = GSystemType.get_gst_name_id(member_of) if node_id: # existing node object node_obj = Node.get_node_by_id(node_id) else: # create new kwargs={ 'group_set': group_id, 'member_of': member_of_id } node_obj = node_collection.collection[node_type]() language = get_language_tuple(request.POST.get('language', None)) node_obj.fill_gstystem_values(request=request, language=language, **kwargs) node_obj.save(group_id=group_id) node_id = node_obj['_id'] # Consider for Blog page creation if member_of_name == "Page": blog_page_gst_name, blog_page_gst_id = GSystemType.get_gst_name_id("Blog page") if blog_page_gst_id in node_obj.type_of: discussion_enable_at = node_collection.one({"_type": "AttributeType", "name": "discussion_enable"}) create_gattribute(node_obj._id, discussion_enable_at, True) return_status = create_thread_for_node(request,group_id, node_obj) 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() post_req = request.POST attrs_to_create_update = [f for f in post_req.keys() if ('attribute' in f)] attrs_to_create_update = [a.split('_')[1] for a in attrs_to_create_update] for each_attr_name in attrs_to_create_update: each_attr_name_obj = Node.get_name_id_from_type(each_attr_name, 'AttributeType', get_obj=True) post_req_attr_key = 'attribute_'+each_attr_name post_method = 'getlist' if (each_attr_name_obj.data_type in [list, 'list']) else 'get' create_gattribute(node_id, each_attr_name_obj, object_value=getattr(post_req, post_method)(post_req_attr_key)) return HttpResponseRedirect(reverse(detail_url_name, kwargs={'group_id': group_id, 'node_id': node_id}))
each_row_dict['user_notes'] = analytics_data['user_notes'] each_row_dict['others_reading_my_notes'] = analytics_data['others_reading_my_notes'] each_row_dict['cmts_on_user_notes'] = analytics_data['cmts_on_user_notes'] each_row_dict['cmnts_rcvd_by_user'] = analytics_data['cmnts_rcvd_by_user'] each_row_dict['total_notes_read_by_user'] = analytics_data['total_notes_read_by_user'] each_row_dict['commented_on_others_notes'] = analytics_data['commented_on_others_notes'] each_row_dict['total_rating_rcvd_on_notes'] = analytics_data['total_rating_rcvd_on_notes'] each_row_dict["correct_attempted_assessments"] = analytics_data["correct_attempted_assessments"] each_row_dict["unattempted_assessments"] = analytics_data["unattempted_assessments"] each_row_dict["visited_assessments"] = analytics_data["visited_assessments"] each_row_dict["notapplicable_assessments"] = analytics_data["notapplicable_assessments"] each_row_dict["incorrect_attempted_assessments"] = analytics_data["incorrect_attempted_assessments"] each_row_dict["attempted_assessments"] = analytics_data["attempted_assessments"] each_row_dict["total_assessment_items"] = analytics_data["total_assessment_items"] buddy_userids_list_within_datetime = Buddy.get_buddy_userids_list_within_datetime(each_user, datetime.datetime.now()) each_row_dict["buddy_userids"] = str(buddy_userids_list_within_datetime) each_row_dict["buddy_usernames"] = Author.get_author_usernames_list_from_user_id_list(buddy_userids_list_within_datetime) for each_act_key, each_act_val in column_keys_dict_addons.iteritems(): each_row_dict[each_act_key] = analytics_data["counter_obj"]["visited_nodes"].get(unicode(each_act_val), 0) all_rows.append(each_row_dict) # with open(file_name_path, 'a') as f: # Just use 'w' mode in 3.x # w = csv.DictWriter(f, (column_keys_list + column_keys_list_addons)) # if not header_written: # w.writeheader() # header_written = True # w.writerow(each_row_dict) # csv_created = True
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) )
asset_content_obj.fill_node_values(**kwargs) asset_content_obj.save(groupid=group_id) asset_contents_list = [asset_content_obj._id] rt_has_asset_content = node_collection.one({ '_type': 'RelationType', 'name': 'has_assetcontent' }) asset_grels = triple_collection.find({'_type': 'GRelation', \ 'relation_type': rt_has_asset_content._id,'subject': asset_obj._id}, {'_id': 0, 'right_subject': 1}) for each_asset in asset_grels: asset_contents_list.append(each_asset['right_subject']) create_grelation(asset_obj._id, rt_has_asset_content, asset_contents_list) 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) # counter_obj = Counter.get_counter_obj(request.user.id, group_id) for each_counter_obj in counter_objs_cur: each_counter_obj['file']['created'] += 1 each_counter_obj['group_points'] += GSTUDIO_FILE_UPLOAD_POINTS each_counter_obj.last_update = datetime.datetime.now() each_counter_obj.save() return asset_content_obj
asset_content_obj = node_collection.collection.GSystem() asset_content_obj.fill_gstystem_values(request=request, uploaded_file=files[0], **kwargs) asset_content_obj.fill_node_values(**kwargs) asset_content_obj.save(groupid=group_id) asset_contents_list = [asset_content_obj._id] rt_has_asset_content = node_collection.one({'_type': 'RelationType', 'name': 'has_assetcontent'}) asset_grels = triple_collection.find({'_type': 'GRelation', \ 'relation_type': rt_has_asset_content._id,'subject': asset_obj._id}, {'_id': 0, 'right_subject': 1}) for each_asset in asset_grels: asset_contents_list.append(each_asset['right_subject']) create_grelation(asset_obj._id, rt_has_asset_content, asset_contents_list) 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) # counter_obj = Counter.get_counter_obj(request.user.id, group_id) for each_counter_obj in counter_objs_cur: each_counter_obj['file']['created'] += 1 each_counter_obj['group_points'] += GSTUDIO_FILE_UPLOAD_POINTS each_counter_obj.last_update = datetime.datetime.now() each_counter_obj.save() return asset_content_obj