Example #1
0
def getImageThumbnail(request, group_id, _id):
    '''
    this funciton can be called to get thumbnail of image throw url
    '''
    # 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)

    img_obj = node_collection.one({"_type": u"File", "_id": ObjectId(_id)})

    if (img_obj is not None) and (len(img_obj.fs_file_ids) >= 2):
        # getting latest uploaded pic's _id
        img_fs = img_obj.fs_file_ids[1]

        if (img_obj.fs.files.exists(img_fs)):
            f = img_obj.fs.files.get(ObjectId(img_fs))
            return HttpResponse(f.read(), content_type=f.content_type)
    else:
        return HttpResponse("")
Example #2
0
def edit_comment(request, group_id, node_id=None,call_from_discussion=None):

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

    if request.GET:
        node_id = request.GET.get('sourceObjDataId');
    content_val = None
    if request.POST:
        content_val = request.POST.get("content_val", "")
        node_id = request.POST.get('sourceObjDataId')
    if node_id:
        node_id = node_id.strip()
        node_obj = node_collection.one({'_id': ObjectId(node_id)})
        if content_val:
            node_obj.content = content_val
            node_obj.save()

    context_variables = {
            'group_id': group_id, 'groupid': group_id,'node': node_obj,'node_id':node_id
            }

    template = 'ndf/html_editor.html'
    context_variables['var_name'] = "content_org",
    context_variables['var_value'] = node_obj.content
    context_variables['node_id'] = node_obj._id
    context_variables['ckeditor_toolbar'] ="BasicToolbar"

    return render_to_response(template, context_variables, context_instance = RequestContext(request))
Example #3
0
def write_files(request, group_id, make_collection=False, unique_gs_per_file=True):

	user_id        = request.user.id
	author_obj     = node_collection.one({'_type': u'Author', 'created_by': user_id})
	author_obj_id  = author_obj._id

	group_name, group_id = get_group_name_id(group_id)

	first_obj      = None
	collection_set = []
	uploaded_files = request.FILES.getlist('filehive', [])
	# print "uploaded_files",uploaded_files
	name           = request.POST.get('name')
	# print "name",name

	gs_obj_list    = []
	for each_file in uploaded_files:

		gs_obj = node_collection.collection.GSystem()

		language = request.POST.get('language', GSTUDIO_SITE_DEFAULT_LANGUAGE)
		language = get_language_tuple(language)

		group_set = [ObjectId(group_id), ObjectId(author_obj_id)]

		if name and not first_obj and (name != 'untitled'):
			file_name = name
		else:
			file_name = each_file.name if hasattr(each_file, 'name') else name

		existing_file_gs = gs_obj.fill_gstystem_values(request=request,
									name=file_name,
									group_set=group_set,
									language=language,
									uploaded_file=each_file,
									unique_gs_per_file=unique_gs_per_file)
		# print "existing_file_gs",existing_file_gs
		if (gs_obj.get('_id', None) or existing_file_gs.get('_id', None)) and \
		   (existing_file_gs.get('_id', None) == gs_obj.get('_id', None)):
			if gst_file_id not in gs_obj.member_of:
				gs_obj.member_of.append(gst_file_id)

			gs_obj.save(groupid=group_id,validate=False)

			if 'video' in gs_obj.if_file.mime_type:
				convertVideo.delay(user_id, str(gs_obj._id), file_name)
			if not first_obj:
				first_obj = gs_obj
			else:
				collection_set.append(gs_obj._id)

			gs_obj_list.append(gs_obj)
		elif existing_file_gs:
				gs_obj_list.append(existing_file_gs)

	if make_collection and collection_set:
		first_obj.collection_set = collection_set
		first_obj.save()

	return gs_obj_list
Example #4
0
def discussion_delete_reply(request, group_id, node_id):

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

    nodes_to_delete = json.loads(request.POST.get("nodes_to_delete", "[]"))

    deleted_replies = []
    node_obj = node_collection.one({'_id': ObjectId(node_id)})
    # print "\n\nnode_obj.name", node_obj.name, node_obj.member_of_names_list,node_obj._id

    for each_reply in nodes_to_delete:
        temp_reply = node_collection.one({"_id": ObjectId(each_reply)})

        if temp_reply:
            deleted_replies.append(temp_reply._id.__str__())
            temp_reply.delete()

    replies_cur = node_collection.find({'origin.thread_id': ObjectId(node_id)})
    # print "\n replies_cur",replies_cur.count()
    if (not replies_cur.count()) and (int(request.user.id) in node_obj.author_set):
        author_set_ids = node_obj.author_set
        author_set_ids.remove(int(request.user.id))
        node_obj.author_set = author_set_ids
        node_obj.save()
    return HttpResponse(json.dumps(deleted_replies))
Example #5
0
def get_possible_batches(request, group_id):
    '''
    Returns:
     * Batches of selected course
    '''
    group_name, group_id = get_group_name_id(group_id)
    response_dict = {"success": False}
    new_batch_node = None
    if request.is_ajax() and request.method == "POST":
        ac_id = request.POST.get("ac_id", '')
        create_new_batch = request.POST.get("create_new_batch", '')
        response_dict["success"] = True
        batch_user_list_dict = []
        list_of_members = []
        if ac_id:
            batch_cur = node_collection.find({'member_of': GST_BATCH._id,
                                'relation_set.has_course': ObjectId(ac_id)})
            for each_batch in batch_cur:
                each_batch_dict = {}
                if each_batch.relation_set:
                    for rel in each_batch.relation_set:
                        list_of_members = []
                        if rel and 'has_batch_member' in rel:
                            list_of_members.append(rel['has_batch_member'])
                            list_of_members.append(str(each_batch._id))
                            each_batch_dict[each_batch.name] = list_of_members
                batch_user_list_dict.append(each_batch_dict)
                # batch_user_list_dict.append(str(each_batch._id))
        # print "\n\nBatches----------", batch_user_list_dict
        response_dict["old_batches"] = batch_user_list_dict
        return HttpResponse(json.dumps(response_dict, cls=NodeJSONEncoder))
Example #6
0
def videoDashboard(request, group_id, video_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)

    if video_id is None:
        video_ins = node_collection.find_one({'_type':"GSystemType", "name":"Video"})
        if video_ins:
            video_id = str(video_ins._id)
    vid_col = node_collection.find({'member_of': {'$all': [ObjectId(video_id)]},'_type':'File', 'group_set': {'$all': [group_id]}})
    template = "ndf/videoDashboard.html"
    already_uploaded=request.GET.getlist('var',"")
    variable = RequestContext(request, {'videoCollection':vid_col, 'already_uploaded':already_uploaded, 'newgroup':group_id})
    return render_to_response(template, variable)
Example #7
0
def quiz(request, group_id):
    """Renders a list of all 'Quiz-type-GSystems' available within the database.
    """
    group_obj = get_group_name_id(group_id, get_obj=True)
    group_id = group_obj._id
    group_name = group_obj.name
    title = gst_quiz.name
    quiz_nodes = node_collection.find({
        'member_of': gst_quiz._id,
        'group_set': ObjectId(group_id)
    }).sort('last_update', -1)
    gst_quiz_names = ['QuizItem']
    if "CourseEventGroup" in group_obj.member_of_names_list:
        gst_quiz_names.append('QuizItemEvent')
    gst_quiz_item = node_collection.find({
        '_type': 'GSystemType',
        'name': {
            '$in': gst_quiz_names
        }
    })
    gst_quiz_item_ids = [each_quiz_gst._id for each_quiz_gst in gst_quiz_item]
    quiz_item_nodes = node_collection.find({
        'member_of': {
            '$in': gst_quiz_item_ids
        },
        'group_set': ObjectId(group_id)
    }).sort('last_update', -1)
    return render_to_response("ndf/quiz.html", {
        'title': title,
        'quiz_nodes': quiz_nodes,
        'quiz_item_nodes': quiz_item_nodes,
        'groupid': group_id,
        'group_id': group_id
    },
                              context_instance=RequestContext(request))
Example #8
0
def get_possible_batches(request, group_id):
    '''
    Returns:
     * Batches of selected course
    '''
    group_name, group_id = get_group_name_id(group_id)
    response_dict = {"success": False}
    new_batch_node = None
    if request.is_ajax() and request.method == "POST":
        ac_id = request.POST.get("ac_id", '')
        create_new_batch = request.POST.get("create_new_batch", '')
        response_dict["success"] = True
        batch_user_list_dict = []
        list_of_members = []
        if ac_id:
            batch_cur = node_collection.find({
                'member_of':
                GST_BATCH._id,
                'relation_set.has_course':
                ObjectId(ac_id)
            })
            for each_batch in batch_cur:
                each_batch_dict = {}
                if each_batch.relation_set:
                    for rel in each_batch.relation_set:
                        list_of_members = []
                        if rel and 'has_batch_member' in rel:
                            list_of_members.append(rel['has_batch_member'])
                            list_of_members.append(str(each_batch._id))
                            each_batch_dict[each_batch.name] = list_of_members
                batch_user_list_dict.append(each_batch_dict)
                # batch_user_list_dict.append(str(each_batch._id))
        # print "\n\nBatches----------", batch_user_list_dict
        response_dict["old_batches"] = batch_user_list_dict
        return HttpResponse(json.dumps(response_dict, cls=NodeJSONEncoder))
Example #9
0
def getFullvideo(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)

    videoobj = node_collection.one({"_id": ObjectId(_id)})
    if len(videoobj.fs_file_ids) > 2:
    	if (videoobj.fs.files.exists(videoobj.fs_file_ids[2])):
            f = videoobj.fs.files.get(ObjectId(videoobj.fs_file_ids[2]))
            return HttpResponse(f.read(), content_type=f.content_type)
    else : 
        if (videoobj.fs.files.exists(videoobj.fs_file_ids[0])):
            f = videoobj.fs.files.get(ObjectId(videoobj.fs_file_ids[0]))
            return HttpResponse(f.read(), content_type=f.content_type)
Example #10
0
def delete_page(request, group_id, node_id):
    """Change the status to Hidden.

    Just hide the page from users!
    """
    # 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)

    op = node_collection.collection.update({'_id': ObjectId(node_id)},
                                           {'$set': {
                                               'status': u"HIDDEN"
                                           }})
    return HttpResponseRedirect(reverse('page', kwargs={'group_id': group_id}))
Example #11
0
def video_search(request,group_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)

    vidcol = node_collection.find({'mime_type':{'$regex': 'video'}})
    if request.method=="GET":
        keyword=request.GET.get("search","")
        vid_search = node_collection.find({'$and':[{'mime_type':{'$regex': 'video'}},{'$or':[{'name':{'$regex':keyword}},{'tags':{'$regex':keyword}}]}]})
        template="ndf/file_search.html"
        variable=RequestContext(request,{'file_collection':vid_search,'view_name':'video_search','newgroup':group_id})
        return render_to_response(template,variable)        
Example #12
0
def my_performance(request, group_id):
    from gnowsys_ndf.settings import GSTUDIO_WORKSPACE_INSTANCE

    if str(request.user) == 'AnonymousUser':
        raise Http404("You don't have an authority for this page!")

    try:
        auth_obj = get_group_name_id(group_id, get_obj=True)
        user_id = auth_obj.created_by

    except:
        user_id = eval(group_id)
        auth_obj = node_collection.one({'_type': "Author", 'created_by': user_id})

    auth_id = auth_obj._id
    title = 'my performance'

    my_units = node_collection.find(
                {'member_of':
                    {'$in': [ce_gst._id, announced_unit_gst._id, gst_group._id]
                },
                'name': {'$nin': GSTUDIO_DEFAULT_GROUPS_LIST },
                'author_set': request.user.id}).sort('last_update', -1)
    return render_to_response('ndf/lms_dashboard.html',
                {
                    'group_id': auth_id, 'groupid': auth_id,
                    'node': auth_obj, 'title': title,
                    # 'my_course_objs': my_course_objs,
                    'units_cur':my_units,
                    # 'modules_cur': my_modules_cur
                },
                context_instance=RequestContext(request)
        )
Example #13
0
def getvideoThumbnail(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)

    videoobj = node_collection.one({"_id": ObjectId(_id)})        
    if videoobj:
        if hasattr(videoobj, 'if_file'):
            f = videoobj.get_file(videoobj.if_file.mid.relurl)
            return HttpResponse(f, content_type=videoobj.if_file.mime_type)

        else:
            f = videoobj.fs.files.get(ObjectId(videoobj.fs_file_ids[0]))
            return HttpResponse(f.read(), content_type=f.content_type)
Example #14
0
def getImageThumbnail(request, group_id, _id):
    '''
    this funciton can be called to get thumbnail of image throw url
    '''
    # 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)

    img_obj = node_collection.one({"_type": u"File", "_id": ObjectId(_id)})

    if (img_obj is not None) and (len(img_obj.fs_file_ids) >= 2):
        # getting latest uploaded pic's _id
        img_fs = img_obj.fs_file_ids[1]

        if (img_obj.fs.files.exists(img_fs)):
            f = img_obj.fs.files.get(ObjectId(img_fs))
            return HttpResponse(f.read(),content_type=f.content_type)
    else:
        return HttpResponse("")
Example #15
0
def get_mid_size_img(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)

    img_obj = node_collection.one({"_id": ObjectId(_id)})
    try:
        f = img_obj.fs.files.get(ObjectId(img_obj.fs_file_ids[2]))
        return HttpResponse(f.read(), content_type=f.content_type)
    except IndexError:
        f = img_obj.fs.files.get(ObjectId(img_obj.fs_file_ids[0]))
        return HttpResponse(f.read(), content_type=f.content_type)
Example #16
0
def discussion_delete_reply(request, group_id, node_id):

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

    nodes_to_delete = json.loads(request.POST.get("nodes_to_delete", "[]"))

    deleted_replies = []
    node_obj = node_collection.one({'_id': ObjectId(node_id)})
    # print "\n\nnode_obj.name", node_obj.name, node_obj.member_of_names_list,node_obj._id

    for each_reply in nodes_to_delete:
        temp_reply = node_collection.one({"_id": ObjectId(each_reply)})

        if temp_reply:
            deleted_replies.append(temp_reply._id.__str__())
            temp_reply.delete()

    replies_cur = node_collection.find({'origin.thread_id': ObjectId(node_id)})
    # print "\n replies_cur",replies_cur.count()
    if (not replies_cur.count()) and (int(request.user.id) in node_obj.author_set):
        author_set_ids = node_obj.author_set
        author_set_ids.remove(int(request.user.id))
        node_obj.author_set = author_set_ids
        node_obj.save()
    return HttpResponse(json.dumps(deleted_replies))
Example #17
0
def get_mid_size_img(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)

    img_obj = node_collection.one({"_id": ObjectId(_id)})
    try:
        f = img_obj.fs.files.get(ObjectId(img_obj.fs_file_ids[2]))
        return HttpResponse(f.read(), content_type=f.content_type)
    except IndexError:
        f = img_obj.fs.files.get(ObjectId(img_obj.fs_file_ids[0]))
        return HttpResponse(f.read(), content_type=f.content_type)
Example #18
0
def videoDashboard(request, group_id, video_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)

    if video_id is None:
        video_ins = node_collection.find_one({'_type':"GSystemType", "name":"Video"})
        if video_ins:
            video_id = str(video_ins._id)
    vid_col = node_collection.find({'member_of': {'$all': [ObjectId(video_id)]},'_type':'File', 'group_set': {'$all': [group_id]}})
    template = "ndf/videoDashboard.html"
    already_uploaded=request.GET.getlist('var',"")
    variable = RequestContext(request, {'videoCollection':vid_col, 'already_uploaded':already_uploaded, 'newgroup':group_id})
    return render_to_response(template, variable)
Example #19
0
def quiz_details(request, group_id, node_id):
    try:
        group_id = ObjectId(group_id)
    except:
        group_name, group_id = get_group_name_id(group_id)

    title = gst_quiz.name
    gst_quiz_item = node_collection.one({
        '_type': 'GSystemType',
        'name': u'QuizItem'
    })

    quiz_node = node_collection.one({'_id': ObjectId(node_id)})
    quiz_item_nodes = node_collection.find({
        '_id': {
            '$in': quiz_node.collection_set
        },
        'member_of': gst_quiz_item._id
    }).sort('last_update', -1)
    # quiz_node.get_neighbourhood(quiz_node.member_of)

    context_variables = {
        'groupid': group_id,
        'group_id': group_id,
        'title': title,
        'node': quiz_node,
        'quiz_item_nodes': quiz_item_nodes
    }
    return render_to_response("ndf/quiz_details.html",
                              context_variables,
                              context_instance=RequestContext(request))
Example #20
0
def get_user_replies(request, group_id, user_name_or_id):

    group_obj = get_group_name_id(group_id, get_obj=True)
    group_id = group_obj._id

    user_obj = None
    try:
        if user_name_or_id.isdigit():
            user_obj = User.objects.get(pk=int(user_name_or_id))
        else:
            user_obj = User.objects.get(username=(user_name_or_id).strip())
        if user_obj:
            gst_reply = node_collection.one({
                '_type': 'GSystemType',
                'name': 'Reply'
            })
            user_replies = node_collection.find({
                'member_of': gst_reply._id,
                'group_set': ObjectId(group_id),
                'contributors': user_obj.pk
            }).sort('last_update', -1)

            return render_to_response('ndf/user_interactions.html', {
                'group_id': group_id,
                'groupid': group_id,
                'group_name': group_obj.name,
                'user_replies': user_replies,
                'user_obj': user_obj
            },
                                      context_instance=RequestContext(request))
    except Exception as no_user:
        return HttpResponse('No such User found')
Example #21
0
def quiz(request, group_id):
    """Renders a list of all 'Quiz-type-GSystems' available within the database.
    """
    try:
        group_id = ObjectId(group_id)
    except:
        group_name, group_id = get_group_name_id(group_id)
    title = gst_quiz.name
    quiz_nodes = node_collection.find({
        'member_of': gst_quiz._id,
        'group_set': ObjectId(group_id)
    }).sort('last_update', -1)
    gst_quiz_item_id = node_collection.one({
        '_type': 'GSystemType',
        'name': u'QuizItem'
    })._id
    quiz_item_nodes = node_collection.find({
        'member_of': {
            '$all': [gst_quiz_item_id]
        },
        'group_set': {
            '$all': [ObjectId(group_id)]
        }
    }).sort('last_update', -1)
    return render_to_response("ndf/quiz.html", {
        'title': title,
        'quiz_nodes': quiz_nodes,
        'quiz_item_nodes': quiz_item_nodes,
        'groupid': group_id,
        'group_id': group_id
    },
                              context_instance=RequestContext(request))
Example #22
0
def group_list_activities(request,group_id):
	'''
	Renders the list of activities of all the members of the group
	'''

	group_name, group_id = get_group_name_id(group_id)

	query("group",{ "group_id" : group_id })
	cursor = analytics_collection.find({"group_id" : str(group_id)}).sort("timestamp",-1)
	lst=[]
	i=-1
	temp_date = datetime.date(1970,1,1)
	date_col = {}

	for doc in cursor :
		if temp_date != doc[u'timestamp'].date().strftime("%d %b, %Y") :
			temp_date = doc[u'timestamp'].date().strftime("%d %b, %Y")
			date_col = {}
			date_col[str(temp_date)] = []
			date_col[str(temp_date)].append(doc)
			lst.append(date_col)
			i=i+1
		else :
			lst[i][str(temp_date)].append(doc)
			pass

	return render (request, "ndf/analytics_list_group_details.html",
															{ "data" : lst, "group_id" : group_id, "groupid" : group_id, "group_name" : group_name})
Example #23
0
def create_assetcontent(asset_id,
                        name,
                        group_name_or_id,
                        created_by,
                        node_id=None,
                        content=None,
                        files=[None],
                        resource_type='Page',
                        request=HttpRequest(),
                        **kwargs):

    # Mandatory arg: 'asset_id'. AssetContent should fall under Asset.
    # And if no Asset exists with supplied arg, can't proceeed.
    asset_obj = Node.get_node_by_id(asset_id)
    if not asset_obj:
        raise ValueError('No Asset exists with supplied asset_id.')

    if not name:
        name = request.POST.get('name') if request else None
    if not created_by:
        created_by = request.user.id if request else None

    group_name, group_id = get_group_name_id(group_name_or_id)
    group_id = ObjectId(group_id)
    if group_id not in asset_obj['group_set']:
        # AssetContent should fall under Asset. If 'group_id' arg is
        # supplied, it should fall under asset's group id.
        raise Exception(
            'Supplied group_id and group_id of Asset does not match.')

    test_content = True if (content or files) else False

    # compulsory values, if not found raise error.
    # if not all([name, created_by, group_id, uploaded_files]):

    if not all([name, created_by, group_id, test_content]):
        raise ValueError(
            '"asset_id", "name", "created_by", "group" and ("content" or "files") are mandatory args.'
        )

    author_obj = node_collection.one({
        '_type': u'Author',
        'created_by': created_by
    })
    author_obj_id = author_obj._id

    group_set = [ObjectId(group_id), ObjectId(author_obj_id)]
    gst_name_id_dict = {
        'Page': gst_page_id,
        'page': gst_page_id,
        'File': gst_file_id,
        'file': gst_file_id
    }

    try:
        member_of_gst_id = gst_name_id_dict[resource_type]
    except Exception, e:
        print "resource_type arg is not supplied."
        # handle condition based on files.
        member_of_gst_id = gst_file_id if files[0] else gst_page_id
Example #24
0
def edit_comment(request, group_id, node_id=None,call_from_discussion=None):

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

    if request.GET:
        node_id = request.GET.get('sourceObjDataId');
    content_val = None
    if request.POST:
        content_val = request.POST.get("content_val", "")
        node_id = request.POST.get('sourceObjDataId')
    if node_id:
        node_id = node_id.strip()
        node_obj = node_collection.one({'_id': ObjectId(node_id)})
        if content_val:
            node_obj.content = content_val
            node_obj.save()

    context_variables = {
            'group_id': group_id, 'groupid': group_id,'node': node_obj,'node_id':node_id
            }

    template = 'ndf/html_editor.html'
    context_variables['var_name'] = "content_org",
    context_variables['var_value'] = node_obj.content
    context_variables['node_id'] = node_obj._id
    context_variables['ckeditor_toolbar'] ="BasicToolbar"

    return render_to_response(template, context_variables, context_instance = RequestContext(request))
Example #25
0
def quiz(request, group_id):
    """Renders a list of all 'Quiz-type-GSystems' available within the database.
    """
    group_obj = get_group_name_id(group_id, get_obj=True)
    group_id = group_obj._id
    group_name = group_obj.name
    title = gst_quiz.name
    quiz_nodes = node_collection.find({'member_of': gst_quiz._id, 'group_set': ObjectId(group_id)}).sort('last_update', -1)
    # gst_quiz_item_ids = [gst_quiz_item._id]
    quiz_item_nodes = node_collection.find({'member_of': gst_quiz_item._id,
     'group_set': ObjectId(group_id)}).sort('last_update', -1)

    if "CourseEventGroup" in group_obj.member_of_names_list or "announced_unit" in group_obj.member_of_names_list:
        # gst_quiz_item_ids = [gst_quiz_item_event._id]
        if not quiz_item_nodes.count():
            quiz_item_nodes = node_collection.find({'member_of': gst_quiz_item_event._id,
             'group_set': ObjectId(group_id)}).sort('last_update', -1)
    supported_languages = ['Hindi', 'Telugu']

    print "\nquiz_item_nodes: ", quiz_item_nodes.count()
    return render_to_response("ndf/quiz.html",
                              {'title': title,
                               'quiz_nodes': quiz_nodes,
                               'quiz_item_nodes': quiz_item_nodes,
                               'groupid':group_id,
                               'group_id':group_id,
                               'supported_languages': supported_languages
                              },
                              context_instance=RequestContext(request)
    )
Example #26
0
def batch_detail(request, group_id):
    group_name, group_id = get_group_name_id(group_id)
    new_batch_node = None
    if request.is_ajax() and request.method == "GET":
        batch_id = request.GET.get("batch_id", '')

        student_coll = []
        node = node_collection.one({'_id': ObjectId(batch_id)})
        rt_has_batch_member = node_collection.one({
            '_type': 'RelationType',
            'name': 'has_batch_member'
        })
        relation_coll = triple_collection.find({
            '_type':
            'GRelation',
            'relation_type':
            rt_has_batch_member._id,
            'subject':
            node._id,
            'status':
            u'PUBLISHED'
        })

        for each in relation_coll:
            n = node_collection.one({'_id': ObjectId(each.right_subject)})
            student_coll.append(n)
        return HttpResponse(json.dumps(student_coll, cls=NodeJSONEncoder))
Example #27
0
def my_courses(request, group_id):

    if str(request.user) == 'AnonymousUser':
        raise Http404("You don't have an authority for this page!")

    try:
        auth_obj = get_group_name_id(group_id, get_obj=True)
        user_id = auth_obj.created_by

    except:
        user_id = eval(group_id)
        auth_obj = node_collection.one({'_type': "Author", 'created_by': user_id})

    auth_id = auth_obj._id
    title = 'My Courses'
    my_course_objs = get_user_course_groups(user_id)
    # print my_course_objs

    return render_to_response('ndf/my-courses.html',
                {
                    'group_id': auth_id, 'groupid': auth_id,
                    'node': auth_obj, 'title': title,
                    'my_course_objs': my_course_objs
                },
                context_instance=RequestContext(request)
        )
Example #28
0
def my_groups(request, group_id):

    # if request.user == 'AnonymousUser':
    # raise 404

    try:
        auth_obj = get_group_name_id(group_id, get_obj=True)

    except:
        user_id = eval(group_id)
        auth_obj = node_collection.one({
            '_type': "Author",
            'created_by': user_id
        })

    auth_id = auth_obj._id
    title = 'My Groups'

    return render_to_response('ndf/my-groups.html', {
        'group_id': auth_id,
        'groupid': auth_id,
        'node': auth_obj,
        'title': title
    },
                              context_instance=RequestContext(request))
Example #29
0
def list_themes(request, group_id):

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

    title = theme_GST.name

    nodes = node_collection.find(
        {
            'member_of': {
                '$all': [theme_GST._id]
            },
            'group_set': {
                '$all': [ObjectId(group_id)]
            }
        }, {
            '_id': 1,
            'name': 1,
            'created_by': 1,
            'created_at': 1
        })

    return render_to_response("ndf/list_themes.html", {
        'groupid': group_id,
        'group_id': group_id,
        'nodes': nodes,
        'theme_GST': theme_GST
    },
                              context_instance=RequestContext(request))
Example #30
0
def my_performance(request, group_id):

    if str(request.user) == 'AnonymousUser':
        raise Http404("You don't have an authority for this page!")

    try:
        auth_obj = get_group_name_id(group_id, get_obj=True)
        user_id = auth_obj.created_by

    except:
        user_id = eval(group_id)
        auth_obj = node_collection.one({'_type': "Author", 'created_by': user_id})

    auth_id = auth_obj._id
    title = 'my performance'

    my_units = node_collection.find({'member_of': {'$in': [ce_gst._id, announced_unit_gst._id]},
                                          'author_set': request.user.id,
                                        }).sort('last_update', -1)
    # my_modules_cur.rewind()
    return render_to_response('ndf/lms_dashboard.html',
                {
                    'group_id': auth_id, 'groupid': auth_id,
                    'node': auth_obj, 'title': title,
                    # 'my_course_objs': my_course_objs,
                    'units_cur':my_units,
                    # 'modules_cur': my_modules_cur
                },
                context_instance=RequestContext(request)
        )
Example #31
0
def user_profile(request, group_id):
    from django.contrib.auth.models import User

    auth_node = get_group_name_id(group_id, get_obj=True)

    user_dict = {}
    user_details = User.objects.get(id=request.user.id)
    user_dict['fname'] = user_details.first_name
    user_dict['lname'] = user_details.last_name

    if request.method == "POST":
        user = User.objects.get(id=request.user.id)
        user_data = request.POST.getlist('forminputs[]', '')
        user_select_data = request.POST.getlist('formselects[]', '')
        apps_to_set = request.POST.getlist('selected_apps_list[]', [])
        apps_to_set = [ObjectId(app_id) for app_id in apps_to_set if app_id]

        apps_list = []
        apps_list_append = apps_list.append
        for each in apps_to_set:
            apps_list_append(node_collection.find_one({"_id": each}))

        at_apps_list = node_collection.one({
            '_type': 'AttributeType',
            'name': 'apps_list'
        })
        ga_node = create_gattribute(auth_node._id, at_apps_list, apps_list)

        for i in user_data:
            a = ast.literal_eval(i)
            if a.get('first_name', None) != None:
                user.first_name = a['first_name']
                user_dict['fname'] = user.first_name
            if a.get('last_name', None) != None:
                user.last_name = a['last_name']
                user_dict['lname'] = user.last_name
        user.save()
        for i in user_select_data:
            a = ast.literal_eval(i)
            if a.get('language_proficiency', None) != None:
                auth_node['language_proficiency'] = []
                for k in a.get('language_proficiency', ''):
                    language = get_language_tuple(k)
                    auth_node['language_proficiency'].append(language)
            if a.get('subject_proficiency', None) != None:
                auth_node['subject_proficiency'] = list(
                    a.get('subject_proficiency', ''))
        auth_node.save()
        user_dict['node'] = auth_node
        user_dict['success'] = True
        return HttpResponse(json.dumps(user_dict, cls=NodeJSONEncoder))
    else:
        user_dict['node'] = auth_node
        return render_to_response(
            "ndf/user_profile_form.html", {
                'group_id': group_id,
                'node': auth_node,
                'user': json.dumps(user_dict, cls=NodeJSONEncoder)
            },
            context_instance=RequestContext(request))
Example #32
0
def remove_stud_from_batch(request, group_id):
    group_name, group_id = get_group_name_id(group_id)
    if request.is_ajax() and request.method == "POST":
        batch_id = request.POST.get("batch_id", '')
        stud_id = request.POST.get("stud_id", '')
        rt_has_batch_member = node_collection.one({
            '_type': 'RelationType',
            'name': 'has_batch_member'
        })
        grelation_node = triple_collection.one({
            '_type':
            'GRelation',
            'relation_type':
            rt_has_batch_member._id,
            'subject':
            ObjectId(batch_id),
            'status':
            u'PUBLISHED',
            'right_subject':
            ObjectId(stud_id)
        })
        rel_name = grelation_node.relation_type.name
        inv_rel_name = grelation_node.relation_type.inverse_name
        subj = grelation_node.subject
        right_subj = grelation_node.right_subject

        # Remove right-subject-node's ObjectId from the value
        # corresponding to subject-node's "relation-name" key
        # referenced in relation_set field
        res = node_collection.collection.update(
            {
                '_id': subj,
                'relation_set.' + rel_name: {
                    '$exists': True
                }
            }, {'$pull': {
                'relation_set.$.' + rel_name: right_subj
            }},
            upsert=False,
            multi=False)
        # Remove subject-node's ObjectId from the value corresponding
        # to right-subject-node's "inverse-relation-name" key
        # referenced in relation_set field
        res = node_collection.collection.update(
            {
                '_id': right_subj,
                'relation_set.' + inv_rel_name: {
                    '$exists': True
                }
            }, {'$pull': {
                'relation_set.$.' + inv_rel_name: subj
            }},
            upsert=False,
            multi=False)

        grelation_node.status = u"DELETED"
        grelation_node.save(groupid=group_id)
        status = "success"
        return HttpResponse(json.dumps(status, cls=NodeJSONEncoder))
Example #33
0
def delete_task(request, group_name, _id):
    """This method will delete task object and its Attribute and Relation
    """
    # ins_objectid  = ObjectId()
    # if ins_objectid.is_valid(group_name) is False :
    #     group_ins = node_collection.find_one({'_type': "Group", "name": group_name})
    #     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_name)
    except:
        group_name, group_id = get_group_name_id(group_name)

    pageurl = request.GET.get("next", "")
    try:
        node = node_collection.one({'_id': ObjectId(_id)})
        if node:
            attributes = triple_collection.find({
                '_type': 'GAttribute',
                'subject': node._id
            })
            relations = triple_collection.find({
                '_type': 'GRelation',
                'subject': node._id
            })
            if attributes.count() > 0:
                for each in attributes:
                    triple_collection.one({'_id': each['_id']}).delete()

            if relations.count() > 0:
                for each in relations:
                    triple_collection.one({'_id': each['_id']}).delete()
            if len(node.post_node) > 0:
                for each in node.post_node:
                    sys_each_postnode = node_collection.find_one({'_id': each})
                    member_of_name = node_collection.find_one({
                        '_id':
                        sys_each_postnode.member_of[0]
                    }).name
                    if member_of_name == "Task":
                        sys_each_postnode.prior_node.remove(node._id)
                        sys_each_postnode.save(groupid=group_id)
                    if member_of_name == "task_update_history":
                        sys_each_postnode.delete(groupid=group_id)

            node.delete()
    except Exception as e:
        print "Exception:", e

    return HttpResponseRedirect(
        reverse('task', kwargs={'group_name': group_name}))
def audioDashboard(request, group_id, audio_id=None):
    '''
    fetching audio files acording to group name
    '''
    try:
        group_id = ObjectId(group_id)
    except:
        group_name, group_id = get_group_name_id(group_id)
    files_cur = node_collection.find(
        {
            '_type': {
                '$in': ["GSystem"]
            },
            'member_of': file_gst._id,
            'group_set': {
                '$all': [ObjectId(group_id)]
            },
            'if_file.mime_type': {
                '$regex': 'audio'
            },
            'status': {
                '$ne': u"DELETED"
            }

            # 'created_by': {'$in': gstaff_users},
            # '$or': [
            # {
            # },
            # {
            #     '$or': [
            #             {'access_policy': u"PUBLIC"},
            #             {
            #                 '$and': [
            #                         {'access_policy': u"PRIVATE"},
            #                         {'created_by': request.user.id}
            #                     ]
            #             }
            #         ],
            # }
            # {    'collection_set': {'$exists': "true", '$not': {'$size': 0} }}
            # ]
        },
        {
            'name': 1,
            '_id': 1,
            'fs_file_ids': 1,
            'member_of': 1,
            'mime_type': 1,
            'if_file': 1
        }).sort("last_update", -1)
    # print "files_cur length++++++++++",files_cur.count()
    template = "ndf/audioDashboard.html"
    variable = RequestContext(request, {
        'audioCollection': files_cur,
        'groupid': group_id,
        'group_id': group_id
    })
    return render_to_response(template, variable)
Example #35
0
def create_edit_quiz(request, group_id, node_id=None):
    """Creates/Edits quiz category.
    """
    try:
        group_id = ObjectId(group_id)
    except:
        group_name, group_id = get_group_name_id(group_id)

    context_variables = {
        'title': gst_quiz.name,
        'group_id': group_id,
        'groupid': group_id
    }
    if node_id:
        quiz_node = node_collection.one({
            '_type': u'GSystem',
            '_id': ObjectId(node_id)
        })

    if request.method == "POST":
        if node_id:
            quiz_node = node_collection.one({
                '_type': u'GSystem',
                '_id': ObjectId(node_id)
            })
        else:
            quiz_node = node_collection.collection.GSystem()
        # get_node_common_fields(request, quiz_node, group_id, gst_quiz)
        quiz_node.save(is_changed=get_node_common_fields(
            request, quiz_node, group_id, gst_quiz),
                       groupid=group_id)
        quiz_node.get_neighbourhood(quiz_node.member_of)
        # get_node_metadata(request, quiz_node,gst_quiz)
        #if teaches is required
        # teaches_list = request.POST.get('teaches_list','') # get the teaches list
        # if teaches_list !='':
        #       teaches_list=teaches_list.split(",")
        # create_grelation_list(quiz_node._id,"teaches",teaches_list)

        # assesses_list = request.POST.get('assesses_list','') # get the assesses list
        # if assesses_list !='':
        #       assesses_list=assesses_list.split(",")
        # create_grelation_list(quiz_node._id,"assesses",assesses_list)
        return HttpResponseRedirect(
            reverse('quiz_details',
                    kwargs={
                        'group_id': group_id,
                        'node_id': quiz_node._id
                    }))
    else:
        if node_id:
            context_variables['node'] = quiz_node
            context_variables['groupid'] = group_id
            context_variables['group_id'] = group_id
            # context_variables['appId']=app._id
        return render_to_response("ndf/quiz_create_edit.html",
                                  context_variables,
                                  context_instance=RequestContext(request))
Example #36
0
def image_detail(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)

    img_node = node_collection.one({"_id": ObjectId(_id)})

    # First get the navigation list till topic from theme map
    nav_l=request.GET.get('nav_li','')
    breadcrumbs_list = []
    nav_li = ""

    if nav_l:
      nav_li = nav_l

    if img_node._type == "GSystemType":
    	return imageDashboard(request, group_id, _id)
    img_node.get_neighbourhood(img_node.member_of)
    thread_node = None
    allow_to_comment = None
    thread_node, allow_to_comment = node_thread_access(group_id, img_node)

    imageCollection = node_collection.find({'member_of': {'$all': [ObjectId(GST_IMAGE._id)]},
                                              '_type': 'File','fs_file_ids': {'$ne': []},
                                              'group_set': {'$all': [ObjectId(group_id)]},
                                              '$or': [
                                                {'access_policy': u"PUBLIC"},
                                                {'$and': [
                                                  {'access_policy': u"PRIVATE"},
                                                  {'created_by': request.user.id}
                                                  ]
                                                }
                                              ]
                                            }).sort("last_update", -1)

    return render_to_response("ndf/image_detail.html",
                                  { 'node': img_node,
                                    'group_id': group_id, 'nav_list':nav_li,
                                    'node_has_thread': thread_node,
                                    'allow_to_comment':allow_to_comment,
                                    'groupid':group_id, 'imageCollection': imageCollection
                                  },
                                  context_instance = RequestContext(request)
        )
Example #37
0
def my_desk(request, group_id):
    from gnowsys_ndf.settings import GSTUDIO_WORKSPACE_INSTANCE

    if str(request.user) == 'AnonymousUser':
        raise Http404("You don't have an authority for this page!")

    try:
        auth_obj = get_group_name_id(group_id, get_obj=True)
        user_id = auth_obj.created_by

    except:
        user_id = eval(group_id)
        auth_obj = node_collection.one({'_type': "Author", 'created_by': user_id})

    auth_id = auth_obj._id
    title = 'my desk'
    
    # modules_cur = node_collection.find({'member_of': gst_module_id  }).sort('last_update', -1)

    # my_course_objs = get_user_course_groups(user_id)
    # module_unit_ids = [val for each_module in modules_cur for val in each_module.collection_set ]

    # modules_cur.rewind()
        # print my_course_objs
    # base_unit_cur = node_collection.find({'member_of': {'$in': [ce_gst._id, announced_unit_gst._id]},
    #                                       'author_set': request.user.id,
    #                                     }).sort('last_update', -1)
    # my_list_unit = []
    # for each in base_unit_cur:
    #     my_list_unit.append(each._id)

    # base_unit_cur.rewind()
    # my_modules_cur = node_collection.find({'member_of': gst_module_id ,'collection_set':{'$in':my_list_unit } }).sort('last_update', -1)
    
    # my_modules = []
    # for each in my_modules_cur:
    #     my_modules.append(each._id)

    
    my_units = node_collection.find(
                {'member_of':
                    {'$in': [ce_gst._id, announced_unit_gst._id, gst_group._id]
                },
                'name': {'$nin': GSTUDIO_DEFAULT_GROUPS_LIST },
                'author_set': request.user.id}).sort('last_update', -1)

    # my_modules_cur.rewind()
    return render_to_response('ndf/lms_dashboard.html',
                {
                    'group_id': auth_id, 'groupid': auth_id,
                    'node': auth_obj, 'title': title,
                    # 'my_course_objs': my_course_objs,
                    'units_cur':my_units,
                    # 'modules_cur': my_modules_cur
                },
                context_instance=RequestContext(request)
        )
Example #38
0
def program_event_list(request, group_id):
    """
    * Renders a list of all 'programs'
    """
    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)})

    course_coll = None
    enr_ce_coll = []
    list_of_pe = []
    all_pe = []
    pe_gst = node_collection.one({'_type': "GSystemType", 'name': "ProgramEventGroup"})

    # program events
    title = "Events"

    pe_coll = node_collection.find({'member_of': pe_gst._id}).sort('last_update', -1)
    for each_pe in pe_coll:
        list_of_hierarchy = get_prior_node_hierarchy(each_pe._id)
        if list_of_hierarchy:
            pe_obj = list_of_hierarchy[len(list_of_hierarchy)-1]
        if pe_obj not in list_of_pe and pe_obj._id in group_obj.post_node:
            list_of_pe.append(pe_obj)
    # print "\n\n list_of_pe",list_of_pe
    gstaff_access = False
    if request.user.id:
        gstaff_access = check_is_gstaff(group_id,request.user)
        userid = int(request.user.id)
        for each in list_of_pe:
            if userid in each.author_set:
                if each not in enr_ce_coll:
                    enr_ce_coll.append(each)     
            else:
                all_pe.append(each)   
    else:
        all_pe = list_of_pe
    if gstaff_access:
        all_pe = enr_ce_coll
    # If request.user is admin, enr_ce_coll is all_pe. 
    # As admin is added in author set of all pe
        # enr_ce_coll = node_collection.find({'$in': list_of_pe,'author_set': int(request.user.id)}).sort('last_update', -1)

    # ce_coll = node_collection.find({'member_of': pe_gst._id, 'author_set': {'$ne': int(request.user.id)}})

    return render_to_response("ndf/course.html",
                            {'title': title,
                             'course_gst': pe_gst,
                             'course_coll': list_of_pe,
                             'groupid': group_id, 'group_id': group_id,
                             'ce_coll':all_pe,
                             'enr_ce_coll':enr_ce_coll,
                            },
                            context_instance=RequestContext(request)
                            )     
Example #39
0
def user_profile(request, group_id):
    from django.contrib.auth.models import User

    auth_node = get_group_name_id(group_id, get_obj=True)

    user_dict={}
    user_details = User.objects.get(id=request.user.id)
    user_dict['fname'] = user_details.first_name
    user_dict['lname']  = user_details.last_name

    if request.method == "POST":
        user = User.objects.get(id=request.user.id)
        user_data = request.POST.getlist('forminputs[]','')
        user_select_data = request.POST.getlist('formselects[]','')
        apps_to_set = request.POST.getlist('selected_apps_list[]', [])
        apps_to_set = [ObjectId(app_id) for app_id in apps_to_set if app_id ]

        apps_list = []
        apps_list_append = apps_list.append
        for each in apps_to_set:
            apps_list_append(
                node_collection.find_one({
                    "_id": each
                })
            )

        at_apps_list = node_collection.one({'_type': 'AttributeType', 'name': 'apps_list'})
        ga_node = create_gattribute(auth_node._id, at_apps_list, apps_list)

        for i in user_data:
			a=ast.literal_eval(i)
			if  a.get('first_name',None) != None:
			  	user.first_name = a['first_name']
			  	user_dict['fname'] = user.first_name
			if a.get('last_name',None) != None:
				user.last_name = a['last_name']
			  	user_dict['lname'] = user.last_name
        user.save()
        for i in user_select_data:
			a=ast.literal_eval(i)
			if  a.get('language_proficiency',None) != None:
				auth_node['language_proficiency'] = []
				for k in a.get('language_proficiency',''):
					language = get_language_tuple(k)
					auth_node['language_proficiency'].append(language)
			if  a.get('subject_proficiency',None) != None:
				auth_node['subject_proficiency'] =  list(a.get('subject_proficiency',''))
        auth_node.save()
        user_dict['node'] = auth_node
        user_dict['success'] = True
        return HttpResponse(json.dumps(user_dict,cls=NodeJSONEncoder))
    else:
		user_dict['node'] = auth_node
		return render_to_response(  "ndf/user_profile_form.html",
				{'group_id':group_id,'node':auth_node,'user':json.dumps(user_dict,cls=NodeJSONEncoder)},
				context_instance=RequestContext(request)
		)
Example #40
0
def delete_reply(request,group_id,forum_id,thread_id,node_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

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

    activity = ""

    op = node_collection.collection.update({'_id': ObjectId(node_id)}, {'$set': {'status': u"HIDDEN"}})

    # ??? CHECK
    replyobj=node_collection.one({'_id':ObjectId(node_id)})

    forumobj=node_collection.one({"_id": ObjectId(forum_id)})
    threadobj=node_collection.one({"_id": ObjectId(thread_id)})
    # notifications to all group members
    colg=node_collection.one({'_id':ObjectId(group_id)})
    link="http://"+sitename+"/"+str(colg._id)+"/forum/thread/"+str(threadobj._id)
    for each in colg.author_set:
        if each != colg.created_by:
            bx=get_userobject(each)
            if bx:
                msg=request.user.username+" has deleted reply- "+replyobj.content_org+"- in the thread " + threadobj.name + " in the group -'" + colg.name+"'\n"+"Please visit "+link+" to see the thread."
                activity="Deleted reply"
                #auth = node_collection.one({'_type': 'Author', 'name': unicode(bx.username) })
                #if colg._id and auth:
                     #no_check=forum_notification_status(colg._id,auth._id)
#               else:
#                    no_check=True
#                    if no_check:
                ret = set_notif_val(request,colg._id,msg,activity,bx)
        prefix="-in the forum -"+forumobj.name
        msg=request.user.username+" has deleted reply- "+replyobj.content_org+"- in the thread " + threadobj.name +prefix+ " in the group -'" + colg.name+"' created by you"+"\n Please visit "+link+" to see the thread."
        bx=get_userobject(colg.created_by)
        if bx:
#            no_check=forum_notification_status(group_id,auth._id)
#            if no_check:
            ret = set_notif_val(request,group_id,msg,activity,bx)

    
    variables=RequestContext(request,{'thread':threadobj,'user':request.user,'forum':forumobj,'groupid':group_id,'group_id':group_id})
    return HttpResponseRedirect(reverse('thread', kwargs={'group_id':group_id,'thread_id': threadobj._id }))
Example #41
0
def image_detail(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)

    img_node = node_collection.one({"_id": ObjectId(_id)})

    # First get the navigation list till topic from theme map
    nav_l=request.GET.get('nav_li','')
    breadcrumbs_list = []
    nav_li = ""

    if nav_l:
      nav_li = nav_l

    if img_node._type == "GSystemType":
    	return imageDashboard(request, group_id, _id)
    img_node.get_neighbourhood(img_node.member_of)
    thread_node = None
    allow_to_comment = None
    thread_node, allow_to_comment = node_thread_access(group_id, img_node)

    imageCollection = node_collection.find({'member_of': {'$all': [ObjectId(GST_IMAGE._id)]},
                                              '_type': 'File','fs_file_ids': {'$ne': []},
                                              'group_set': {'$all': [ObjectId(group_id)]},
                                              '$or': [
                                                {'access_policy': u"PUBLIC"},
                                                {'$and': [
                                                  {'access_policy': u"PRIVATE"},
                                                  {'created_by': request.user.id}
                                                  ]
                                                }
                                              ]
                                            }).sort("last_update", -1)

    return render_to_response("ndf/image_detail.html",
                                  { 'node': img_node,
                                    'group_id': group_id, 'nav_list':nav_li,
                                    'node_has_thread': thread_node,
                                    'allow_to_comment':allow_to_comment,
                                    'groupid':group_id, 'imageCollection': imageCollection
                                  },
                                  context_instance = RequestContext(request)
        )
Example #42
0
def delete_batch(request, group_id, _id):

    group_name, group_id = get_group_name_id(group_id)

    # if 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

    node = node_collection.one({'_id': ObjectId(_id)})
    left_relations = triple_collection.find({
        "_type": "GRelation",
        "subject": node._id
    })
    right_relations = triple_collection.find({
        "_type": "GRelation",
        "right_subject": node._id
    })
    attributes = triple_collection.find({
        "_type": "GAttribute",
        "subject": node._id
    })

    for eachobject in right_relations:
        # If given node is used in relationship with any other node (as right_subject)
        # Then this node's ObjectId must be removed from relation_set field of other node
        node_collection.collection.update(
            {
                '_id': eachobject.subject,
                'relation_set.' + eachobject.relation_type.name: {
                    '$exists': True
                }
            }, {
                '$pull': {
                    'relation_set.$.' + eachobject.relation_type.name: node._id
                }
            },
            upsert=False,
            multi=False)
        eachobject.delete()

    all_associates = list(left_relations) + list(attributes)
    # Deleting GAttributes and GRelations where given node is used as left subject
    for eachobject in all_associates:
        eachobject.delete()

    # Finally deleting given node
    node.delete()
    return HttpResponseRedirect(reverse('batch', kwargs={'group_id':
                                                         group_id}))
Example #43
0
def my_groups(request, group_id, page_no=1):

    from gnowsys_ndf.settings import GSTUDIO_NO_OF_OBJS_PP
    # if request.user == 'AnonymousUser':
    # raise 404

    try:
        auth = get_group_name_id(group_id, get_obj=True)

    except:
        user_id = eval(group_id)
        auth = node_collection.one({'_type': "Author", 'created_by': user_id})
    usrid = auth.created_by
    current_user = usrid
    if current_user:
        exclued_from_public = ""
        if int(current_user) == int(usrid):
            Access_policy = ["PUBLIC", "PRIVATE"]
        if int(current_user) != int(usrid):
            Access_policy = ["PUBLIC"]
    else:
        Access_policy = ["PUBLIC"]
        exclued_from_public = ObjectId(task_gst._id)

    group_cur = node_collection.find({
        '_type':
        "Group",
        'name': {
            '$nin': ["home", auth.name]
        },
        "access_policy": {
            "$in": Access_policy
        },
        'status':
        u'PUBLISHED',
        '$or': [{
            'group_admin': int(usrid)
        }, {
            'author_set': int(usrid)
        }]
    }).sort('last_update', -1)
    group_page_cur = paginator.Paginator(group_cur, page_no,
                                         GSTUDIO_NO_OF_OBJS_PP)

    auth_id = auth._id
    title = 'My Groups'

    return render_to_response('ndf/my-groups.html', {
        'group_id': group_id,
        'groupid': group_id,
        'node': auth,
        'title': title,
        'group_cur': group_cur,
        'group_page_cur': group_page_cur
    },
                              context_instance=RequestContext(request))
Example #44
0
def batch(request, group_id):
    """
   * Renders a list of all 'batches' available within the database.
    """
    group_name, group_id = get_group_name_id(group_id)
    # ins_objectid = ObjectId()
    # st_student = node_collection.one({'_type':'GSystemType','name':'Student'})
    # 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
    nussd_course_type_name = ""
    announced_course_name = ""

    if request.method == "POST":
        announced_course_name = request.POST.get("announced_course_name", "")
        nussd_course_type_name = request.POST.get("nussd_course_name", "")
        # colg_gst = node_collection.one({'_type': "GSystemType", 'name': 'College'})
        # req_colg_id = node_collection.one({'member_of': colg_gst._id, 'relation_set.has_group': ObjectId(group_id)})
        batch_coll = node_collection.find({'member_of': GST_BATCH._id, 'relation_set.has_course': ObjectId(announced_course_name)})
        # for each_batch in batch_coll:
        #   each_batch['batch_name_human_readble'] = (each_batch.name).replace('_',' ')
    else:
        batch_coll = node_collection.find({'member_of': GST_BATCH._id, 'relation_set.batch_in_group':ObjectId(group_id)})
    fetch_ATs = ["nussd_course_type"]
    req_ATs = []
    for each in fetch_ATs:
        each = node_collection.one({'_type': "AttributeType", 'name': each}, {'_type': 1, '_id': 1, 'data_type': 1, 'complex_data_type': 1, 'name': 1, 'altnames': 1})

        if each["data_type"] == "IS()":
            dt = "IS("
            for v in each.complex_data_type:
                dt = dt + "u'" + v + "'" + ", "
            dt = dt[:(dt.rfind(", "))] + ")"
            each["data_type"] = dt

        each["data_type"] = eval(each["data_type"])
        each["value"] = None
        req_ATs.append(each)
    # users_in_group = node_collection.one({'_id':ObjectId(group_id)}).author_set
    template = "ndf/batch.html"
    variable = RequestContext(request, {'batch_coll': batch_coll,
                            'appId': app._id,
                            'nussd_course_name_var': nussd_course_type_name,
                            'announced_course_name_var': announced_course_name,
                            'ATs': req_ATs, 'group_id': group_id,
                            'groupid': group_id, 'title': GST_BATCH.name,
                            'st_batch_id': GST_BATCH._id})
    return render_to_response(template, variable)
Example #45
0
def get_dr_search_result_dict(request, group_id, search_text=None, page_no=1):

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

    # check if request is from form or from next page
    if request.GET.has_key("search_text"):
        search_text = request.GET.get("search_text", "")

    else:
        search_text = search_text.replace("+", " ")
        get_req = request.GET.copy()
        # adding values to GET req
        get_req.update({"search_text": search_text})
        # overwriting request.GET with newly created QueryDict instance get_req
        request.GET = get_req

    search_reply = json.loads(results_search(request, group_id, return_only_dict = True))
    exact_search_res = search_reply["exact"]["name"]
    result_ids_list = [ ObjectId(each_dict["_id"]) for each_dict in exact_search_res ]
    result_cur = node_collection.find({
                                    "_id": {"$in": result_ids_list},
                                    'member_of': {'$in': [ObjectId(file_id._id), ObjectId(page_id._id)]}
                                    })

    paged_resources = paginator.Paginator(result_cur, page_no, 10)

    # list to hold resources instances with it's attributes and relations
    files_list = []

    for each_resource in paged_resources.items:
        each_resource, ver = get_page(request, each_resource)
        each_resource.get_neighbourhood(each_resource.member_of)
        files_list.append(node_collection.collection.GSystem(each_resource))

    return render_to_response("ndf/data_review.html",
                {
                    "group_id": group_id, "groupid": group_id,
                    "files": files_list, "page_info": paged_resources,
                    "urlname": "data_review_search_page",
                    "second_arg": search_text, "search_text": search_text,
                    "static_educationalsubject": GSTUDIO_RESOURCES_EDUCATIONAL_SUBJECT,
                    # "static_language": EXTRA_LANG_INFO,
                    "static_language": GSTUDIO_RESOURCES_LANGUAGES,
                    "static_educationaluse": GSTUDIO_RESOURCES_EDUCATIONAL_USE,
                    "static_interactivitytype": GSTUDIO_RESOURCES_INTERACTIVITY_TYPE,
                    "static_educationalalignment": GSTUDIO_RESOURCES_EDUCATIONAL_ALIGNMENT,
                    "static_educationallevel": GSTUDIO_RESOURCES_EDUCATIONAL_LEVEL,
                    "static_curricular": GSTUDIO_RESOURCES_CURRICULAR,
                    "static_audience": GSTUDIO_RESOURCES_AUDIENCE,
                    "static_status": list(STATUS_CHOICES),
                    "static_textcomplexity": GSTUDIO_RESOURCES_TEXT_COMPLEXITY
                }, context_instance=RequestContext(request))
Example #46
0
def display_forum(request, group_id, forum_id):
    hide_create_thread_btn = True
    other_forums_list = None
    other_forums = node_collection.find({
        'member_of': forum_gst._id,
        'group_set': ObjectId(group_id),
        '_id': {
            '$nin': [ObjectId(forum_id)]
        }
    })
    if other_forums.count():
        other_forums_list = [[str(d._id), d.name] for d in other_forums]

    forum = node_collection.one({'_id': ObjectId(forum_id)})

    usrname = User.objects.get(id=forum.created_by).username

    # 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)

    forum_object = node_collection.one({'_id': ObjectId(forum_id)})
    if forum_object._type == "GSystemType":
        return forum(request, group_id, forum_id)
    th_all = get_forum_twists(forum)
    if th_all:
        th_count = len(list(th_all))
    else:
        th_count = 0
    variables = RequestContext(
        request, {
            'forum': forum,
            'hide_create_thread_btn': hide_create_thread_btn,
            'groupid': group_id,
            'group_id': group_id,
            'forum_created_by': usrname,
            'other_forums': other_forums_list,
            'thread_count': th_count,
        })

    return render_to_response("ndf/forumdetails.html", variables)
Example #47
0
def videoDashboard(request, group_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)
    files_cur = node_collection.find({
                                        '_type': {'$in': ["GSystem"]},
                                        'member_of': file_gst._id,
                                        'group_set': {'$all': [ObjectId(group_id)]},
                                        'if_file.mime_type': {'$regex': 'video'},
                                        'status' : { '$ne': u"DELETED" }

                                        # 'created_by': {'$in': gstaff_users},
                            # '$or': [
                                    # {
                                    # },
                                    # {
                                    #     '$or': [
                                    #             {'access_policy': u"PUBLIC"},
                                    #             {
                                    #                 '$and': [
                                    #                         {'access_policy': u"PRIVATE"},
                                    #                         {'created_by': request.user.id}
                                    #                     ]
                                    #             }
                                    #         ],
                                    # }
                                    # {    'collection_set': {'$exists': "true", '$not': {'$size': 0} }}
                                # ]
                        },
                        {
                            'name': 1,
                            '_id': 1,
                            'fs_file_ids': 1,
                            'member_of': 1,
                            'mime_type': 1,
                            'if_file':1
                        }).sort("last_update", -1)
    template = "ndf/videoDashboard.html"
    variable = RequestContext(request, {'group_id':group_id,'groupid':group_id,'files_cur':files_cur})
    return render_to_response(template, variable)
Example #48
0
def create_assetcontent(asset_id,
						name,
						group_name_or_id,
						created_by,
						node_id=None,
						content=None,
						files=[None],
						resource_type='Page',
						request=HttpRequest(),
						**kwargs):

	# Mandatory arg: 'asset_id'. AssetContent should fall under Asset.
	# And if no Asset exists with supplied arg, can't proceeed.
	asset_obj = Node.get_node_by_id(asset_id)
	if not asset_obj:
		raise ValueError('No Asset exists with supplied asset_id.')

	if not name:
		name = request.POST.get('name') if request else None
	if not created_by:
		created_by = request.user.id if request else None

	group_name, group_id = get_group_name_id(group_name_or_id)
	group_id = ObjectId(group_id)
	if group_id not in asset_obj['group_set']:
		# AssetContent should fall under Asset. If 'group_id' arg is
		# supplied, it should fall under asset's group id.
		raise Exception('Supplied group_id and group_id of Asset does not match.')

	test_content = True if (content or files) else False

	# compulsory values, if not found raise error.
	# if not all([name, created_by, group_id, uploaded_files]):

	if not all([name, created_by, group_id, test_content]):
		raise ValueError('"asset_id", "name", "created_by", "group" and ("content" or "files") are mandatory args.')

	author_obj     = node_collection.one({'_type': u'Author', 'created_by': created_by})
	author_obj_id  = author_obj._id

	group_set = [ObjectId(group_id), ObjectId(author_obj_id)]
	gst_name_id_dict = {
		'Page': gst_page_id, 'page': gst_page_id,
		'File': gst_file_id, 'file': gst_file_id
	}

	try:
		member_of_gst_id = gst_name_id_dict[resource_type]
	except Exception, e:
		print "resource_type arg is not supplied."
		# handle condition based on files.
		member_of_gst_id = gst_file_id if files[0] else gst_page_id
Example #49
0
def ebook_listing(request, group_id, page_no=1):
	from gnowsys_ndf.settings import GSTUDIO_NO_OF_OBJS_PP
	import urllib

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

	selfilters = urllib.unquote(request.GET.get('selfilters', ''))
	# print "===\n", selfilters, "===\n"
	query_dict = [{}]
	if selfilters:
		selfilters = json.loads(selfilters)
		query_dict = get_filter_querydict(selfilters)
	# else:
	# 	query_dict.append({'collection_set': {'$exists': "true", '$not': {'$size': 0} }})
        
	# print "\n----\n", query_dict
	# all_ebooks = node_collection.find({
	# 		# "_type": "File",
	# 		# "attribute_set.educationaluse": "eBooks",
	# 		'$and': query_dict,
	# 		'collection_set': {'$exists': "true", '$not': {'$size': 0} }
	# 	})

	all_ebooks = node_collection.find({												
								'member_of': {'$in': [GST_FILE._id, GST_PAGE._id]},
								# '_type': 'File',
								# 'fs_file_ids': {'$ne': []}, 
								'group_set': {'$in': [ObjectId(group_id)]},
								'attribute_set.educationaluse': 'eBooks',
								'$and': query_dict,
								'$or': [
										{ 'access_policy': u"PUBLIC" },
										{ '$and': [
													{'access_policy': u"PRIVATE"}, 
													{'created_by': request.user.id}
												]
										}
									],
								'collection_set': {'$exists': "true", '$not': {'$size': 0} }
								}).sort("last_update", -1)

	ebooks_page_info = paginator.Paginator(all_ebooks, page_no, GSTUDIO_NO_OF_OBJS_PP)

	return render_to_response("ndf/ebook.html", {
								"all_ebooks": all_ebooks, "ebook_gst": ebook_gst,
								"page_info": ebooks_page_info, "title": "eBooks",
								"group_id": group_id, "groupid": group_id
								}, context_instance = RequestContext(request))
Example #50
0
def save_batch(request, group_id):
# def save_batch(batch_name, user_list, group_id, request, ac_id):

    group_name, group_id = get_group_name_id(group_id)
    response_dict = {"success": False}
    # new_batch_node = None
    rt_has_batch_member = node_collection.one({'_type': 'RelationType', 'name': 'has_batch_member'})
    if request.is_ajax() and request.method == "POST":
        ac_id = request.POST.get("ac_id", '')
        batch_name = request.POST.get("batch_name", '')
        batch_id = request.POST.get("batch_id", '')
        user_list = request.POST.getlist("user_list[]", '')
        # create_new_batch = request.POST.get("create_new_batch", '')
        # response_dict["old_batches"] = find_batches_of_ac(ac_id)
        user_list = [ObjectId(each) for each in user_list]
        all_batches_in_grp = []
        if not batch_id:
            # b_node = node_collection.one({'member_of':GST_BATCH._id,'name':unicode(batch_name)})
            b_node = node_collection.collection.GSystem()
            b_node.member_of.append(GST_BATCH._id)
            b_node.created_by = int(request.user.id)
            b_node.group_set.append(ObjectId(group_id))
            b_node.name = batch_name
            b_node['altnames'] = batch_name.replace('_', ' ')

            b_node.contributors.append(int(request.user.id))
            b_node.modified_by = int(request.user.id)
            b_node.save(groupid=group_id)
            all_batches_in_grp.append(b_node._id)

            rt_group_has_batch = node_collection.one({'_type': 'RelationType', 'name': 'group_has_batch'})
            relation_coll = triple_collection.find({'_type': 'GRelation', 'relation_type.$id': rt_group_has_batch._id,'subject':ObjectId(group_id)})

            for each in relation_coll:
                all_batches_in_grp.append(each.right_subject)
                # to get all batches of the group
            rt_has_course = node_collection.one({'_type': 'RelationType', 'name': 'has_course'})

            create_grelation(ObjectId(group_id), rt_group_has_batch, all_batches_in_grp)
            create_grelation(b_node._id, rt_has_course, ObjectId(ac_id))
            response_dict['new_batch_created'] = True
            response_dict['new_batch_node_name'] = b_node.name
            response_dict['new_batch_node_id'] = str(b_node._id)
        else:
            response_dict['new_batch_created'] = False
            b_node = node_collection.one({'_id': ObjectId(batch_id)})
        if user_list:
            create_grelation(b_node._id, rt_has_batch_member, user_list)
        response_dict['success'] = True
        return HttpResponse(json.dumps(response_dict, cls=NodeJSONEncoder))
Example #51
0
def delete_task(request, group_name, _id):
    """This method will delete task object and its Attribute and Relation
    """
    # ins_objectid  = ObjectId()
    # if ins_objectid.is_valid(group_name) is False :
    #     group_ins = node_collection.find_one({'_type': "Group", "name": group_name})
    #     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_name)
    except:
        group_name, group_id = get_group_name_id(group_name)

    pageurl = request.GET.get("next", "")
    try:
        node = node_collection.one({'_id': ObjectId(_id)})
        if node:
            attributes = triple_collection.find({'_type': 'GAttribute', 'subject': node._id})
            relations = triple_collection.find({'_type': 'GRelation', 'subject': node._id})
            if attributes.count() > 0:
                for each in attributes:
                    triple_collection.one({'_id': each['_id']}).delete()

            if relations.count() > 0:
                for each in relations:
                    triple_collection.one({'_id': each['_id']}).delete()
	    if len(node.post_node) > 0 :
		for each in node.post_node :
		    sys_each_postnode = node_collection.find_one({'_id': each})
		    member_of_name = node_collection.find_one({'_id': sys_each_postnode.member_of[0]}).name
		    if member_of_name == "Task" :
			sys_each_postnode.prior_node.remove(node._id)
			sys_each_postnode.save(groupid=group_id)
		    if member_of_name == "task_update_history":
			sys_each_postnode.delete(groupid=group_id)

            node.delete()
    except Exception as e:
        print "Exception:", e

    return HttpResponseRedirect(reverse('task', kwargs={'group_name': group_name }))
Example #52
0
def batch_detail(request, group_id):
    group_name, group_id = get_group_name_id(group_id)
    new_batch_node = None
    if request.is_ajax() and request.method == "GET":
        batch_id = request.GET.get("batch_id", '')

        student_coll = []
        node = node_collection.one({'_id':ObjectId(batch_id)})
        rt_has_batch_member = node_collection.one({'_type':'RelationType','name':'has_batch_member'})
        relation_coll = triple_collection.find({'_type':'GRelation','relation_type.$id':rt_has_batch_member._id,'subject':node._id,'status':u'PUBLISHED'})

        for each in relation_coll:
            n = node_collection.one({'_id':ObjectId(each.right_subject)})
            student_coll.append(n)
        return HttpResponse(json.dumps(student_coll, cls=NodeJSONEncoder))
Example #53
0
def delete_theme(request, group_id, theme_id):

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

    trash_group = node_collection.one({'_type': 'Group', 'name': 'Trash'})

    theme_to_be_deleted = node_collection.one({'_id': ObjectId(theme_id)})
    theme_to_be_deleted.group_set = [ObjectId(trash_group._id)]
    theme_to_be_deleted.save()
    # print trash_group._id,"  ", theme_to_be_deleted.group_set

    return HttpResponseRedirect( reverse('list_themes', kwargs={"group_id": group_id} ))
Example #54
0
def display_forum(request,group_id,forum_id):
    hide_create_thread_btn = True
    other_forums_list = None
    other_forums = node_collection.find({'member_of': forum_gst._id,'group_set': ObjectId(group_id),
                                        '_id':{'$nin':[ObjectId(forum_id)]}})
    if other_forums.count():
        other_forums_list = [[str(d._id), d.name] for d in other_forums]

    forum = node_collection.one({'_id': ObjectId(forum_id)})

    usrname = User.objects.get(id=forum.created_by).username

    # 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)

    forum_object = node_collection.one({'_id': ObjectId(forum_id)})
    if forum_object._type == "GSystemType":
       return forum(request, group_id, forum_id)
    th_all=get_forum_twists(forum)
    if th_all:
        th_count=len(list(th_all))
    else:
        th_count=0
    variables = RequestContext(request,{
                                        'forum':forum,
                                        'hide_create_thread_btn': hide_create_thread_btn,
                                        'groupid':group_id,'group_id':group_id,
                                        'forum_created_by':usrname,
                                        'other_forums': other_forums_list,
                                        'thread_count':th_count,
                                        })

    return render_to_response("ndf/forumdetails.html",variables)
Example #55
0
def audioDashboard(request, group_id, audio_id=None):

    '''
    fetching audio files acording to group name
    '''
    try:
        group_id = ObjectId(group_id)
    except:
        group_name, group_id = get_group_name_id(group_id)
    files_cur = node_collection.find({

                                    '_type': {'$in': ["GSystem"]},
                                    'member_of': file_gst._id,
                                    'group_set': {'$all': [ObjectId(group_id)]},
                                    'if_file.mime_type': {'$regex': 'audio'},
                                    'status' : { '$ne': u"DELETED" } 

                                    # 'created_by': {'$in': gstaff_users},
                        # '$or': [
                                # {
                                # },
                                # {
                                #     '$or': [
                                #             {'access_policy': u"PUBLIC"},
                                #             {
                                #                 '$and': [
                                #                         {'access_policy': u"PRIVATE"},
                                #                         {'created_by': request.user.id}
                                #                     ]
                                #             }
                                #         ],
                                # }
                                # {    'collection_set': {'$exists': "true", '$not': {'$size': 0} }}
                            # ]
                    },
                    {
                        'name': 1,
                        '_id': 1,
                        'fs_file_ids': 1,
                        'member_of': 1,
                        'mime_type': 1,
                        'if_file':1
                    }).sort("last_update", -1)
    # print "files_cur length++++++++++",files_cur.count()
    template = "ndf/audioDashboard.html"
    variable = RequestContext(request, {'audioCollection': files_cur,'groupid':group_id,'group_id':group_id })
    return render_to_response(template, variable)
Example #56
0
def group_summary(request,group_id):
	'''
	Renders the summary of all the activities done by the members of the Group
	'''
	group_name, group_id = get_group_name_id(group_id)

	query("group",{ "group_id" : group_id })

	data = {}
	pipe = [{'$match' : { 'group_id' : str(group_id)}}, {'$group': {'_id': '$user.name', 'num_of_activities': {'$sum': 1}}}]
	sorted_list = analytics_collection.aggregate(pipeline=pipe)
	sorted_list_acc_activities = sorted(sorted_list['result'],key = lambda k:k[u'num_of_activities'],reverse=True)

	data['active_users'] = []
	i=0
	for doc in sorted_list_acc_activities :
		data['active_users'].append({ "name" : (doc[u'_id']) , "activities" : doc[u'num_of_activities'] } )
		i+=1
		if i==3:
			break
	Course = node_collection.find_one({"_type":"GSystemType","name":"Course"})
	CourseEventGroup  =  node_collection.find_one({"_type":"GSystemType","name":"CourseEventGroup"})
        TwistGst = node_collection.find_one({"_type":"GSystemType","name":"Twist"})
	data['forums'] = db['Nodes'].find({"url":"forum", "group_set":ObjectId(group_id)}).count()
	data['threads'] = db['Nodes'].find({"member_of":ObjectId(TwistGst._id),"group_set":ObjectId(group_id)}).count()
	regx=re.compile("^Reply of:.*")
	data['replies'] = db['Nodes'].find({"name": regx,"group_set":ObjectId(group_id)}).count()
	data['files'] = db['Nodes'].find({"url":"file", "group_set":ObjectId(group_id)}).count()
	data['pages'] = db['Nodes'].find({"url":"page", "group_set":ObjectId(group_id)}).count()
	data['total_activities'] = analytics_collection.find({ "group_id" : unicode(group_id)}).count()
	data['Courses'] =  node_collection.find({"type_of":Course._id}).count()
	data['announce_courses'] = node_collection.find({"prior_node":ObjectId(group_id),"member_of":CourseEventGroup._id}).count()
	data['recent'] = {}

	specific_date = datetime.datetime.now() - datetime.timedelta(days=7)

	data['recent']['forums'] = analytics_collection.find({"action.key": {"$in" : ['create', 'edit']}, "group_id": str(group_id), "obj.forum" : { '$exists' : 'true'},"timestamp":{'$gte':specific_date}}).count()
	data['recent']['threads'] = analytics_collection.find({"action.key": {"$in" : ['create', 'edit']}, "group_id": str(group_id), "obj.thread" : { '$exists' : 'true'},"timestamp":{'$gte':specific_date}}).count()
	data['recent']['replies'] = analytics_collection.find({"action.key": {"$in" : ['add']}, "group_id": str(group_id), "obj.reply" : { '$exists' : 'true'},"timestamp":{'$gte':specific_date}}).count()
	data['recent']['files'] = analytics_collection.find({"action.key": {"$in" : ['create', 'edit']}, "group_id": str(group_id), "obj.file" : { '$exists' : 'true'},"timestamp":{'$gte':specific_date}}).count()
	data['recent']['pages'] = analytics_collection.find({"action.key": {"$in" : ['create', 'edit']}, "group_id": str(group_id), "obj.page" : { '$exists' : 'true'},"timestamp":{'$gte':specific_date}}).count()
	data['recent']['create_edit_course'] = analytics_collection.find({"action.key": {"$in" : ['create', 'edit']}, "group_id": str(group_id), "obj.course" : { '$exists' : 'true'},"timestamp":{'$gte':specific_date}}).count()


	return render (request ,"ndf/analytics_group_summary.html",
																{ "data" : data, "group_id" : group_id, "groupid" : group_id})