Ejemplo n.º 1
0
def all_under_moderation(request, group_id):
	from gnowsys_ndf.ndf.views.group import CreateModeratedGroup, CreateEventGroup, CreateGroup

	group_obj = get_group_name_id(group_id, get_obj=True)
	if not group_obj.edit_policy == 'EDITABLE_MODERATED':
		raise Http404('Group is not EDITABLE_MODERATED')
	list_of_sg_mn = get_sg_member_of(group_id)
	# mod_group_instance = CreateGroup(request)
	# print "\n\n list_of_sg_mn",list_of_sg_mn
	# list_of_sg_mn = mod_group_instance.get_all_subgroups_member_of_list(group_obj._id)
	if "ProgramEventGroup" in list_of_sg_mn:
		sg_member_of = "ProgramEventGroup"
		mod_group_instance = CreateEventGroup(request)
	elif "CourseEventGroup" in list_of_sg_mn:
		sg_member_of = "CourseEventGroup"
		mod_group_instance = CreateEventGroup(request)
	elif "ModeratingGroup" in list_of_sg_mn:
		sg_member_of = "ModeratingGroup"
		mod_group_instance = CreateModeratedGroup(request)

	group_hierarchy_result = mod_group_instance.get_all_group_hierarchy(group_obj._id,sg_member_of)
	group_hierarchy_obj_list = []

	if group_hierarchy_result[0]:
		group_hierarchy_obj_list = group_hierarchy_result[1]
		group_hierarchy_id_list = [g._id for g in group_hierarchy_obj_list]

		file_gst = node_collection.one({'_type': 'GSystemType', 'name': 'File'})
		page_gst = node_collection.one({'_type': 'GSystemType', 'name': 'Page'})

		all_resources = node_collection.find({'member_of': {'$in': [file_gst._id, page_gst._id]}, 'group_set': {'$in': group_hierarchy_id_list[1:]} })

		# print "=== ", res_cur.count()
		# print [x.name for x in all_resources]

		return render_to_response('ndf/all_under_moderation_status.html', {
			"group_id": group_id, "groupid": group_id, "title": "All Under Moderation Resources",
			"files": all_resources, "group_hierarchy_obj_list": group_hierarchy_obj_list,
			"detail_urlname": "moderation_status", "filetype": "all", "dont_show_error": True
			}, RequestContext(request))

	else:
		raise Http404('Group is not EDITABLE_MODERATED')
Ejemplo n.º 2
0
def moderation_status(request, group_id, node_id, get_only_response_dict=False):

	try:
		group_id = ObjectId(group_id)
	except:
		group_name, group_id = get_group_name_id(group_id)

	node = node_collection.one({'_id': ObjectId(node_id)})

	if not node:  # invalid ObjectId
		return render_to_response('ndf/under_moderation.html', {
		'group_id': group_id, 'groupid': group_id, 'title': 'Under Moderation Status',
		}, RequestContext(request))

	node_status = node.status
	node_group_set = node.group_set
	current_mod_group_obj = None
	group_hierarchy_obj_list = []
	is_under_moderation = True
	top_group_obj = None
	cleared_group_objs = []
	next_mod_group_objs = []
	group_obj = node_collection.one({'_id': ObjectId(group_id)})
	mod_group_instance = CreateModeratedGroup(request)
	# list_of_sg_mn = mod_group_instance.get_all_subgroups_member_of_list(group_obj._id)
	# list_of_sg_member_of = get_sg_member_of(group_obj._id)
	# print "\n\nlist_of_sg_mn-----",list_of_sg_member_of

	# selected_group = None

	for each_group_id in node_group_set:
		each_group_obj = node_collection.one({'_id': ObjectId(each_group_id), '_type': 'Group'})
		if each_group_obj:
			# selected_group = each_group_obj._id
			selected_group_obj = each_group_obj

	# selected_group = selected_group if selected_group else group_id
	selected_group_obj = selected_group_obj if selected_group_obj else group_obj
	# selected_group_obj = node_collection.one({'_id': ObjectId(selected_group)})
	list_of_sg_member_of = []
	# To prevent error if resource is pulished in top_level_group
	if "Group" in selected_group_obj.member_of_names_list:
		list_of_sg_member_of = get_sg_member_of(selected_group_obj._id)

	# Based on the resource's current group's member_of 
	# or if resource is in top_level_group, based on its sg_member_of
	if "ModeratingGroup" in selected_group_obj.member_of_names_list or "ModeratingGroup" in list_of_sg_member_of or selected_group_obj.name == "home":
		sg_member_of = "ModeratingGroup"
		mod_group_instance = CreateModeratedGroup(request)
	elif "ProgramEventGroup" in selected_group_obj.member_of_names_list or "ProgramEventGroup" in list_of_sg_member_of:
		sg_member_of = "ProgramEventGroup"
		mod_group_instance = CreateEventGroup(request)
	elif "CourseEventGroup" in selected_group_obj.member_of_names_list or "CourseEventGroup" in list_of_sg_member_of:
		sg_member_of = "CourseEventGroup"
		mod_group_instance = CreateEventGroup(request)

	# group_hierarchy_result = mod_group_instance.get_all_group_hierarchy(selected_group,sg_member_of)
	# print "\n sg_member_of",sg_member_of
	group_hierarchy_result = mod_group_instance.get_all_group_hierarchy(selected_group_obj._id,sg_member_of)
	# returns result in <True, all_sub_group_list> format
	# print "\n\n group_hierarchy_result",group_hierarchy_result
	if group_hierarchy_result[0]:
		group_hierarchy_obj_list = group_hierarchy_result[1]
		group_hierarchy_id_list = [g._id for g in group_hierarchy_obj_list]
		group_hierarchy_names_list = [str(g.altnames) if g.altnames else g.name for g in group_hierarchy_obj_list]
		top_group_id = group_hierarchy_id_list[0]
		top_group_obj = group_hierarchy_obj_list[0]
		# cntr = 0
		# for each_group_id in node_group_set:
		# 	cntr += 1
		# 	if each_group_id in group_hierarchy_id_list:
		# 		if ObjectId(each_group_id) == ObjectId(top_group_id):
		# 			is_under_moderation = False
		# 		else:
		# 			current_mod_group_obj = group_hierarchy_obj_list[cntr+1]
		# 			is_under_moderation = True
		if selected_group_obj != top_group_obj:
			current_mod_group_obj = selected_group_obj
			is_under_moderation = True
		else:
			is_under_moderation = False

		if current_mod_group_obj:
			current_group_index = None
			try:
				current_group_index = group_hierarchy_names_list.index(current_mod_group_obj.name)
			except ValueError as e:
				current_group_index = group_hierarchy_names_list.index(current_mod_group_obj.altnames)

			if current_group_index:
				cleared_group_objs = group_hierarchy_names_list[1:current_group_index]
				next_mod_group_objs = group_hierarchy_names_list[current_group_index+1:]
	elif node_status == u'MODERATION':
		is_under_moderation = True
	else:
		is_under_moderation = False

	# print "is_under_moderation : ", is_under_moderation
	# print "=== ", current_mod_group_obj.name
	# print "\n\n cleared_group_objs",cleared_group_objs
	# print "\n\n next_mod_group_objs",next_mod_group_objs

	response_dict = {
		'group_id': group_id, 'groupid': group_id, 'node': node, 'title': 'Under Moderation Status',
		'is_under_moderation': is_under_moderation, 'current_mod_group_obj': current_mod_group_obj,
		'group_hierarchy_obj_list': json.dumps(group_hierarchy_obj_list,cls=NodeJSONEncoder), 'top_group_obj': top_group_obj,
		'group_obj': group_obj, 'next_mod_group_objs':next_mod_group_objs,
		'cleared_group_objs':cleared_group_objs
	}

	if get_only_response_dict:
		return response_dict

	return render_to_response('ndf/under_moderation.html', response_dict, RequestContext(request))