def export_group_analytics(group_obj, assessment_and_quiz_data):

    # print "Enter 'group name(case sensitive)' OR 'id': "
    # group_name_or_id = raw_input()
    # group_obj = Group.get_group_name_id(group_name_or_id, get_obj=True)

    # if not group_obj:
    #     raise ValueError('\nSorry. Request could not be visited. \
    #         \nGroup/Course, matching argument entered "' + group_name_or_id + '" does not exists!!')

    # group_users = group_obj.author_set
    # Previously, above was implementation strategy. Now we are using counter users instead of group's author_set,
    # because we do wanted to gather all data irrespective of student enrollment.
    group_users = Counter.get_group_counters(group_obj._id).distinct('user_id')
    # group_users is a list of integer user ids
    # print group_users

    # CSV file name-convention: schoolcode-course-name-datetimestamp.csv
    try:
        group_name = slugify(group_obj['name'])
    except Exception, e:
        # print e
        group_name = str(group_obj['_id'])
Example #2
0
def export_group_analytics(group_obj, assessment_and_quiz_data):

    # print "Enter 'group name(case sensitive)' OR 'id': "
    # group_name_or_id = raw_input()
    # group_obj = Group.get_group_name_id(group_name_or_id, get_obj=True)

    # if not group_obj:
    #     raise ValueError('\nSorry. Request could not be visited. \
    #         \nGroup/Course, matching argument entered "' + group_name_or_id + '" does not exists!!')

    # group_users = group_obj.author_set
    # Previously, above was implementation strategy. Now we are using counter users instead of group's author_set,
    # because we do wanted to gather all data irrespective of student enrollment.
    group_users = Counter.get_group_counters(group_obj._id).distinct('user_id')
    # group_users is a list of integer user ids
    #print group_users

    # CSV file name-convention: schoolcode-course-name-datetimestamp.csv
    try:
        group_name = slugify(group_obj['name'])
    except Exception, e:
        # print e
        group_name = str(group_obj['_id'])
Example #3
0
def create_edit_page(request, group_id, node_id=None):
    """Creates/Modifies details about the given quiz-item.
    """

    # ins_objectid = ObjectId()
    # if ins_objectid.is_valid(group_id) is False :
    #     group_ins = node_collection.find_one({'_type': "Group", "name": group_id})
    #     auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) })
    #     if group_ins:
    #         group_id = str(group_ins._id)
    #     else :
    #         auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) })
    #         if auth :
    #             group_id = str(auth._id)
    # else :
    #     pass
    group_name, group_id = get_group_name_id(group_id)
    ce_id = request.GET.get('course_event_id', '')
    blog_type = request.GET.get('blog_type', '')
    res = request.GET.get('res', '')
    program_res = request.GET.get('program_res', '')
    context_variables = {
        'title': gst_page.name,
        'group_id': group_id,
        'groupid': group_id,
        'ce_id': ce_id,
        'res': res,
        'program_res': program_res,
        'blog_type': blog_type
    }
    group_obj = node_collection.one({'_id': ObjectId(group_id)})
    available_nodes = node_collection.find({
        '_type': u'GSystem',
        'member_of': ObjectId(gst_page._id),
        'group_set': ObjectId(group_id),
        '_id': {
            '$ne': ObjectId(node_id)
        }
    })

    nodes_list = []
    thread = None
    url_name = "/home"
    # for each in available_nodes:
    #   nodes_list.append(str((each.name).strip().lower()))
    # loop replaced by a list comprehension
    node_list = [str((each.name).strip().lower()) for each in available_nodes]
    # print "available_nodes: ", node_list

    if request.method == "POST":
        # get_node_common_fields(request, page_node, group_id, gst_page)
        page_name = request.POST.get('name', '')
        # print "====== page_name: ", page_name
        if page_name.strip().lower() in node_list and not node_id:
            new_page = False
            return render_to_response("error_base.html", {
                'message':
                'Page with same name already exists in the group!'
            },
                                      context_instance=RequestContext(request))
        elif node_id:
            new_page = False
            page_node = node_collection.one({
                '_type': u'GSystem',
                '_id': ObjectId(node_id)
            })
        else:
            new_page = True
            page_node = node_collection.collection.GSystem()

        # page_type = request.POST.getlist("type_of",'')

        ce_id = request.POST.get("ce_id", '')
        blog_type = request.POST.get('blog_type', '')

        res = request.POST.get("res", '')
        program_res = request.POST.get('program_res', '')

        # we are fetching the value of release_response flag
        # if this is set, it means, we can proceed to create a thread node
        # for the current page node.
        thread_create_val = request.POST.get("thread_create", '')
        # print "\n\n thread_create_val", thread_create_val
        # print "\n\n request.POST === ",request.POST
        # raise Exception("demo")
        # help_info_page = request.POST.getlist('help_info_page','')
        help_info_page = request.POST['help_info_page']
        if help_info_page:
            help_info_page = json.loads(help_info_page)
        # print "\n\n help_info_page === ",help_info_page

        #program_res and res are boolean values
        if program_res:
            program_res = eval(program_res)

        if res:
            res = eval(res)

        if blog_type:
            blog_type = eval(blog_type)
        # if page_type:
        #     objid= page_type[0]
        #     if not ObjectId(objid) in page_node.type_of:
        #         page_type1=[]
        #         page_type1.append(ObjectId(objid))
        #         page_node.type_of = page_type1
        #         page_node.type_of
        page_node.save(is_changed=get_node_common_fields(
            request, page_node, group_id, gst_page))

        # if course event grp's id is passed, it means
        # its a blog page added in notebook and hence set type_of field as "Blog page"
        # print "\n\n blog_type---",blog_type
        if blog_type:
            blogpage_gst = node_collection.one({
                '_type': "GSystemType",
                'name': "Blog page"
            })
            page_node.type_of = [blogpage_gst._id]
        elif GSTUDIO_SITE_NAME == "NROER" and "Author" in group_obj.member_of_names_list:
            infopage_gst = node_collection.one({
                '_type': "GSystemType",
                'name': "Info page"
            })
            page_node.type_of = [infopage_gst._id]
        # if the page created is as a resource in course or program event,
        # set status to PUBLISHED by default
        # one major reason for this, ONLY published nodes can be replicated.
        if res or program_res or ce_id:
            page_node.status = u"PUBLISHED"
        page_node.save()
        # if page is created in program event, add page_node to group's collection set
        if program_res:
            group_obj = node_collection.one({'_id': ObjectId(group_id)})
            group_obj.collection_set.append(page_node._id)
            group_obj.save()

        discussion_enable_at = node_collection.one({
            "_type": "AttributeType",
            "name": "discussion_enable"
        })
        if thread_create_val == "Yes" or blog_type:
            create_gattribute(page_node._id, discussion_enable_at, True)
            return_status = create_thread_for_node(request, group_id,
                                                   page_node)
        else:
            create_gattribute(page_node._id, discussion_enable_at, False)

        # print "\n\n help_info_page ================ ",help_info_page
        if "None" not in help_info_page:
            has_help_rt = node_collection.one({
                '_type': "RelationType",
                'name': "has_help"
            })
            try:
                help_info_page = map(ObjectId, help_info_page)
                create_grelation(page_node._id, has_help_rt, help_info_page)
                page_node.reload()
            except Exception as invalidobjectid:
                # print invalidobjectid
                pass
        else:

            # Check if node had has_help RT
            grel_dict = get_relation_value(page_node._id, "has_help")
            # print "\n\n grel_dict ==== ", grel_dict
            if grel_dict:
                grel_id = grel_dict.get("grel_id", "")
                if grel_id:
                    for each_grel_id in grel_id:
                        del_status, del_status_msg = delete_grelation(
                            subject_id=page_node._id,
                            node_id=each_grel_id,
                            deletion_type=0)
                        # print "\n\n del_status == ",del_status
                        # print "\n\n del_status_msg == ",del_status_msg

        # To fill the metadata info while creating and editing page node
        metadata = request.POST.get("metadata_info", '')
        if "CourseEventGroup" in group_obj.member_of_names_list and blog_type:
            if new_page:
                # counter_obj = Counter.get_counter_obj(request.user.id,ObjectId(group_id))
                # # counter_obj.no_notes_written=counter_obj.no_notes_written+1
                # counter_obj['page']['blog']['created'] += 1
                # # counter_obj.course_score += GSTUDIO_NOTE_CREATE_POINTS
                # counter_obj['group_points'] += GSTUDIO_NOTE_CREATE_POINTS
                # counter_obj.last_update = datetime.datetime.now()
                # counter_obj.save()

                active_user_ids_list = [request.user.id]
                if GSTUDIO_BUDDY_LOGIN:
                    active_user_ids_list += Buddy.get_buddy_userids_list_within_datetime(
                        request.user.id, datetime.datetime.now())
                    # removing redundancy of user ids:
                    active_user_ids_list = dict.fromkeys(
                        active_user_ids_list).keys()

                counter_objs_cur = Counter.get_counter_objs_cur(
                    active_user_ids_list, group_id)

                for each_counter_obj in counter_objs_cur:
                    each_counter_obj['page']['blog']['created'] += 1
                    each_counter_obj[
                        'group_points'] += GSTUDIO_NOTE_CREATE_POINTS
                    each_counter_obj.last_update = datetime.datetime.now()
                    each_counter_obj.save()

            return HttpResponseRedirect(
                reverse('course_notebook_tab_note',
                        kwargs={
                            'group_id': group_id,
                            'tab': 'my-notes',
                            'notebook_id': page_node._id
                        }))

        if ce_id or res or program_res:
            url_name = "/" + group_name + "/" + str(page_node._id)
            if ce_id:
                # url_name = "/" + group_name + "/#journal-tab"
                url_name = "/" + group_name
            if res or program_res:
                url_name = "/" + group_name + "/?selected=" + str(
                    page_node._id) + "#view_page"
            # print "\n\n url_name---",url_name
            return HttpResponseRedirect(url_name)
        if metadata:
            # Only while metadata editing
            if metadata == "metadata":
                if page_node:
                    get_node_metadata(request, page_node, is_changed=True)
        # End of filling metadata

        return HttpResponseRedirect(
            reverse('page_details',
                    kwargs={
                        'group_id': group_id,
                        'app_id': page_node._id
                    }))

    else:
        if node_id:
            page_node = node_collection.one({
                '_type': u'GSystem',
                '_id': ObjectId(node_id)
            })
            #page_node,ver=get_page(request,page_node)
            page_node.get_neighbourhood(page_node.member_of)

            context_variables['node'] = page_node
            context_variables['groupid'] = group_id
            context_variables['group_id'] = group_id
    # fetch Page instances
    # Page_node = node_collection.find_one({'_type':"GSystemType","name":"Page"})
        page_instances = node_collection.find({"type_of": gst_page._id})
        page_ins_list = [i for i in page_instances]
        context_variables['page_instance'] = page_ins_list
        context_variables['nodes_list'] = json.dumps(nodes_list)
        # print "\n\n context_variables----\n",context_variables
        return render_to_response("ndf/page_create_edit.html",
                                  context_variables,
                                  context_instance=RequestContext(request))
Example #4
0
def node_create_edit(request,
                    group_id=None,
                    member_of=None,
                    detail_url_name=None,
                    node_type='GSystem',
                    node_id=None):
    '''
    creation as well as edit of node
    '''
    # check for POST method to node update operation
    if request.method == "POST":

        # put validations
        if node_type not in node_collection.db.connection._registered_documents.keys():
            raise ValueError('Improper node_type passed')

        kwargs={}
        group_name, group_id = Group.get_group_name_id(group_id)
        member_of_name, member_of_id = GSystemType.get_gst_name_id(member_of)

        if node_id: # existing node object
            node_obj = Node.get_node_by_id(node_id)

        else: # create new
            kwargs={
                    'group_set': group_id,
                    'member_of': member_of_id
                    }
            node_obj = node_collection.collection[node_type]()

        language = get_language_tuple(request.POST.get('language', None))
        node_obj.fill_gstystem_values(request=request,
                                    language=language,
                                            **kwargs)
        node_obj.save(group_id=group_id)
        node_id = node_obj['_id']

        # Consider for Blog page creation
        if member_of_name == "Page":
            blog_page_gst_name, blog_page_gst_id = GSystemType.get_gst_name_id("Blog page")
            if blog_page_gst_id in node_obj.type_of:
                discussion_enable_at = node_collection.one({"_type": "AttributeType", "name": "discussion_enable"})
                create_gattribute(node_obj._id, discussion_enable_at, True)
                return_status = create_thread_for_node(request,group_id, node_obj)

                active_user_ids_list = [request.user.id]
                if GSTUDIO_BUDDY_LOGIN:
                    active_user_ids_list += Buddy.get_buddy_userids_list_within_datetime(request.user.id, datetime.datetime.now())
                # removing redundancy of user ids:
                active_user_ids_list = dict.fromkeys(active_user_ids_list).keys()
                counter_objs_cur = Counter.get_counter_objs_cur(active_user_ids_list, group_id)
                for each_counter_obj in counter_objs_cur:
                    each_counter_obj['page']['blog']['created'] += 1
                    each_counter_obj['group_points'] += GSTUDIO_NOTE_CREATE_POINTS
                    each_counter_obj.last_update = datetime.datetime.now()
                    each_counter_obj.save()

        post_req = request.POST
        attrs_to_create_update = [f for f in post_req.keys() if ('attribute' in f)]
        attrs_to_create_update = [a.split('_')[1] for a in attrs_to_create_update]

        for each_attr_name in attrs_to_create_update:
            each_attr_name_obj = Node.get_name_id_from_type(each_attr_name, 'AttributeType', get_obj=True)
            post_req_attr_key = 'attribute_'+each_attr_name
            post_method = 'getlist' if (each_attr_name_obj.data_type in [list, 'list']) else 'get'
            create_gattribute(node_id,
                            each_attr_name_obj,
                            object_value=getattr(post_req, post_method)(post_req_attr_key))


        return HttpResponseRedirect(reverse(detail_url_name, kwargs={'group_id': group_id, 'node_id': node_id}))
Example #5
0
def node_create_edit(request,
                    group_id=None,
                    member_of=None,
                    detail_url_name=None,
                    node_type='GSystem',
                    node_id=None):
    '''
    creation as well as edit of node
    '''
    # check for POST method to node update operation
    if request.method == "POST":

        # put validations
        if node_type not in node_collection.db.connection._registered_documents.keys():
            raise ValueError('Improper node_type passed')

        kwargs={}
        group_name, group_id = Group.get_group_name_id(group_id)
        member_of_name, member_of_id = GSystemType.get_gst_name_id(member_of)

        if node_id: # existing node object
            node_obj = Node.get_node_by_id(node_id)

        else: # create new
            kwargs={
                    'group_set': group_id,
                    'member_of': member_of_id
                    }
            node_obj = node_collection.collection[node_type]()

        language = get_language_tuple(request.POST.get('language', None))
        node_obj.fill_gstystem_values(request=request,
                                    language=language,
                                            **kwargs)
        node_obj.save(group_id=group_id)
        node_id = node_obj['_id']

        # Consider for Blog page creation
        if member_of_name == "Page":
            blog_page_gst_name, blog_page_gst_id = GSystemType.get_gst_name_id("Blog page")
            if blog_page_gst_id in node_obj.type_of:
                discussion_enable_at = node_collection.one({"_type": "AttributeType", "name": "discussion_enable"})
                create_gattribute(node_obj._id, discussion_enable_at, True)
                return_status = create_thread_for_node(request,group_id, node_obj)

                active_user_ids_list = [request.user.id]
                if GSTUDIO_BUDDY_LOGIN:
                    active_user_ids_list += Buddy.get_buddy_userids_list_within_datetime(request.user.id, datetime.datetime.now())
                # removing redundancy of user ids:
                active_user_ids_list = dict.fromkeys(active_user_ids_list).keys()
                counter_objs_cur = Counter.get_counter_objs_cur(active_user_ids_list, group_id)
                for each_counter_obj in counter_objs_cur:
                    each_counter_obj['page']['blog']['created'] += 1
                    each_counter_obj['group_points'] += GSTUDIO_NOTE_CREATE_POINTS
                    each_counter_obj.last_update = datetime.datetime.now()
                    each_counter_obj.save()

        post_req = request.POST
        attrs_to_create_update = [f for f in post_req.keys() if ('attribute' in f)]
        attrs_to_create_update = [a.split('_')[1] for a in attrs_to_create_update]

        for each_attr_name in attrs_to_create_update:
            each_attr_name_obj = Node.get_name_id_from_type(each_attr_name, 'AttributeType', get_obj=True)
            post_req_attr_key = 'attribute_'+each_attr_name
            post_method = 'getlist' if (each_attr_name_obj.data_type in [list, 'list']) else 'get'
            create_gattribute(node_id,
                            each_attr_name_obj,
                            object_value=getattr(post_req, post_method)(post_req_attr_key))


        return HttpResponseRedirect(reverse(detail_url_name, kwargs={'group_id': group_id, 'node_id': node_id}))
Example #6
0
def create_edit_page(request, group_id, node_id=None):
    """Creates/Modifies details about the given quiz-item.
    """

    # ins_objectid = ObjectId()
    # if ins_objectid.is_valid(group_id) is False :
    #     group_ins = node_collection.find_one({'_type': "Group", "name": group_id})
    #     auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) })
    #     if group_ins:
    #         group_id = str(group_ins._id)
    #     else :
    #         auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) })
    #         if auth :
    #             group_id = str(auth._id)
    # else :
    #     pass
    group_name, group_id = get_group_name_id(group_id)
    ce_id = request.GET.get('course_event_id','')
    blog_type = request.GET.get('blog_type','')
    res = request.GET.get('res','')
    program_res = request.GET.get('program_res','')
    context_variables = { 'title': gst_page.name,
                          'group_id': group_id,
                          'groupid': group_id,
                          'ce_id': ce_id,
                          'res':res,
                          'program_res':program_res,
                          'blog_type': blog_type
                      }
    group_obj = node_collection.one({'_id': ObjectId(group_id)})
    available_nodes = node_collection.find({'_type': u'GSystem', 'member_of': ObjectId(gst_page._id),'group_set': ObjectId(group_id), '_id': {'$ne': ObjectId(node_id)} })

    nodes_list = []
    thread = None
    url_name = "/home"
    # for each in available_nodes:
    #   nodes_list.append(str((each.name).strip().lower()))
    # loop replaced by a list comprehension
    node_list = [str((each.name).strip().lower()) for each in available_nodes]
    # print "available_nodes: ", node_list

    if request.method == "POST":
        # get_node_common_fields(request, page_node, group_id, gst_page)
        page_name = request.POST.get('name', '')
        # print "====== page_name: ", page_name
        if page_name.strip().lower() in node_list and not node_id:
            new_page=False
            return render_to_response("error_base.html",
                                      {'message': 'Page with same name already exists in the group!'},
                                      context_instance=RequestContext(request))
        elif node_id:
            new_page = False
            page_node = node_collection.one({'_type': u'GSystem', '_id': ObjectId(node_id)})
        else:
            new_page = True
            page_node = node_collection.collection.GSystem()

        # page_type = request.POST.getlist("type_of",'')

        ce_id = request.POST.get("ce_id",'')
        blog_type = request.POST.get('blog_type','')

        res = request.POST.get("res",'')
        program_res = request.POST.get('program_res','')

        # we are fetching the value of release_response flag
        # if this is set, it means, we can proceed to create a thread node
        # for the current page node.
        thread_create_val = request.POST.get("thread_create",'')
        # print "\n\n thread_create_val", thread_create_val
        # print "\n\n request.POST === ",request.POST
        # raise Exception("demo")
        # help_info_page = request.POST.getlist('help_info_page','')
        help_info_page = request.POST['help_info_page']
        if help_info_page:
            help_info_page = json.loads(help_info_page)
        # print "\n\n help_info_page === ",help_info_page

        #program_res and res are boolean values
        if program_res:
            program_res = eval(program_res)

        if res:
            res = eval(res)

        if blog_type:
            blog_type = eval(blog_type)
        # if page_type:
        #     objid= page_type[0]
        #     if not ObjectId(objid) in page_node.type_of:
        #         page_type1=[]
        #         page_type1.append(ObjectId(objid))
        #         page_node.type_of = page_type1
        #         page_node.type_of
        page_node.save(is_changed=get_node_common_fields(request, page_node, group_id, gst_page))

        # if course event grp's id is passed, it means
        # its a blog page added in notebook and hence set type_of field as "Blog page"
        # print "\n\n blog_type---",blog_type
        if blog_type:
            blogpage_gst = node_collection.one({'_type': "GSystemType", 'name': "Blog page"})
            page_node.type_of = [blogpage_gst._id]
        elif GSTUDIO_SITE_NAME == "NROER" and "Author" in group_obj.member_of_names_list:
            infopage_gst = node_collection.one({'_type': "GSystemType", 'name': "Info page"})
            page_node.type_of = [infopage_gst._id]
        # if the page created is as a resource in course or program event,
        # set status to PUBLISHED by default
        # one major reason for this, ONLY published nodes can be replicated.
        if res or program_res or ce_id:
            page_node.status = u"PUBLISHED"
        page_node.save()
        # if page is created in program event, add page_node to group's collection set
        if program_res:
            group_obj = node_collection.one({'_id': ObjectId(group_id)})
            group_obj.collection_set.append(page_node._id)
            group_obj.save()

        discussion_enable_at = node_collection.one({"_type": "AttributeType", "name": "discussion_enable"})
        if thread_create_val == "Yes" or blog_type:
          create_gattribute(page_node._id, discussion_enable_at, True)
          return_status = create_thread_for_node(request,group_id, page_node)
        else:
          create_gattribute(page_node._id, discussion_enable_at, False)

        # print "\n\n help_info_page ================ ",help_info_page
        if "None" not in help_info_page:
          has_help_rt = node_collection.one({'_type': "RelationType", 'name': "has_help"})
          try:
            help_info_page = map(ObjectId, help_info_page)
            create_grelation(page_node._id, has_help_rt,help_info_page)
            page_node.reload()
          except Exception as invalidobjectid:
            # print invalidobjectid
            pass
        else:

          # Check if node had has_help RT
          grel_dict = get_relation_value(page_node._id,"has_help")
          # print "\n\n grel_dict ==== ", grel_dict
          if grel_dict:
            grel_id = grel_dict.get("grel_id","")
            if grel_id:
              for each_grel_id in grel_id:
                del_status, del_status_msg = delete_grelation(
                    subject_id=page_node._id,
                    node_id=each_grel_id,
                    deletion_type=0
                )
                # print "\n\n del_status == ",del_status
                # print "\n\n del_status_msg == ",del_status_msg

        # To fill the metadata info while creating and editing page node
        metadata = request.POST.get("metadata_info", '')
        if "CourseEventGroup" in group_obj.member_of_names_list and blog_type:
            if new_page:
              # counter_obj = Counter.get_counter_obj(request.user.id,ObjectId(group_id))
              # # counter_obj.no_notes_written=counter_obj.no_notes_written+1
              # counter_obj['page']['blog']['created'] += 1
              # # counter_obj.course_score += GSTUDIO_NOTE_CREATE_POINTS
              # counter_obj['group_points'] += GSTUDIO_NOTE_CREATE_POINTS
              # counter_obj.last_update = datetime.datetime.now()
              # counter_obj.save()

              active_user_ids_list = [request.user.id]
              if GSTUDIO_BUDDY_LOGIN:
                  active_user_ids_list += Buddy.get_buddy_userids_list_within_datetime(request.user.id, datetime.datetime.now())
                  # removing redundancy of user ids:
                  active_user_ids_list = dict.fromkeys(active_user_ids_list).keys()

              counter_objs_cur = Counter.get_counter_objs_cur(active_user_ids_list, group_id)

              for each_counter_obj in counter_objs_cur:
                  each_counter_obj['page']['blog']['created'] += 1
                  each_counter_obj['group_points'] += GSTUDIO_NOTE_CREATE_POINTS
                  each_counter_obj.last_update = datetime.datetime.now()
                  each_counter_obj.save()

            return HttpResponseRedirect(reverse('course_notebook_tab_note',
                                    kwargs={
                                            'group_id': group_id,
                                            'tab': 'my-notes',
                                            'notebook_id': page_node._id
                                            })
                                      )

        if ce_id or res or program_res:
            url_name = "/" + group_name + "/" + str(page_node._id)
            if ce_id:
                # url_name = "/" + group_name + "/#journal-tab"
                url_name = "/" + group_name
            if res or program_res:
                url_name = "/" + group_name + "/?selected=" + str(page_node._id) + "#view_page"
            # print "\n\n url_name---",url_name
            return HttpResponseRedirect(url_name)
        if metadata:
            # Only while metadata editing
            if metadata == "metadata":
                if page_node:
                    get_node_metadata(request,page_node,is_changed=True)
        # End of filling metadata

        return HttpResponseRedirect(reverse('page_details', kwargs={'group_id': group_id, 'app_id': page_node._id }))

    else:
        if node_id:
            page_node = node_collection.one({'_type': u'GSystem', '_id': ObjectId(node_id)})
            #page_node,ver=get_page(request,page_node)
            page_node.get_neighbourhood(page_node.member_of)

            context_variables['node'] = page_node
            context_variables['groupid'] = group_id
            context_variables['group_id'] = group_id
    	# fetch Page instances
    	# Page_node = node_collection.find_one({'_type':"GSystemType","name":"Page"})
    	page_instances = node_collection.find({"type_of": gst_page._id})
    	page_ins_list = [i for i in page_instances]
        context_variables['page_instance'] = page_ins_list
        context_variables['nodes_list'] = json.dumps(nodes_list)
        # print "\n\n context_variables----\n",context_variables
        return render_to_response("ndf/page_create_edit.html",
                                  context_variables,
                                  context_instance=RequestContext(request)
                              )
Example #7
0
    asset_content_obj.fill_node_values(**kwargs)
    asset_content_obj.save(groupid=group_id)
    asset_contents_list = [asset_content_obj._id]
    rt_has_asset_content = node_collection.one({
        '_type': 'RelationType',
        'name': 'has_assetcontent'
    })
    asset_grels = triple_collection.find({'_type': 'GRelation', \
     'relation_type': rt_has_asset_content._id,'subject': asset_obj._id},
     {'_id': 0, 'right_subject': 1})
    for each_asset in asset_grels:
        asset_contents_list.append(each_asset['right_subject'])

    create_grelation(asset_obj._id, rt_has_asset_content, asset_contents_list)
    active_user_ids_list = [request.user.id]
    if GSTUDIO_BUDDY_LOGIN:
        active_user_ids_list += Buddy.get_buddy_userids_list_within_datetime(
            request.user.id, datetime.datetime.now())
        # removing redundancy of user ids:
        active_user_ids_list = dict.fromkeys(active_user_ids_list).keys()

    counter_objs_cur = Counter.get_counter_objs_cur(active_user_ids_list,
                                                    group_id)
    # counter_obj = Counter.get_counter_obj(request.user.id, group_id)
    for each_counter_obj in counter_objs_cur:
        each_counter_obj['file']['created'] += 1
        each_counter_obj['group_points'] += GSTUDIO_FILE_UPLOAD_POINTS
        each_counter_obj.last_update = datetime.datetime.now()
        each_counter_obj.save()
    return asset_content_obj
Example #8
0
def invite_users(request, group_id):
    try:
        sending_user = request.user
        node = node_collection.one({'_id': ObjectId(group_id)})
        if request.method == "POST":
            exst_users = []
            new_users = []
            users = []
            deleted_users = node.author_set
            groupname = node.name
            users_to_invite = request.POST['users']
            not_status = request.POST['notif_status']
            new_users_list = users_to_invite.split(",")
            for each in new_users_list:
                if each:
                    users.append(int(each))
            if users:
                for each in users:
                    if each in node.author_set:
                        exst_users.append(each)
                    else:
                        if each not in node.author_set:
                            new_users.append(each)
                            node.author_set.append(each)
                node.save(groupid=group_id)
                for each in users:
                    counter_obj = Counter.get_counter_obj(
                        each, ObjectId(group_id))
                    counter_obj['is_group_member'] = True
                    counter_obj.save()
                try:
                    # Send invitations according to not_status variable
                    activ = "invitation to join in group"
                    if not_status == "ON":
                        for each in exst_users:
                            bx = User.objects.get(id=each)
                            msg = "'This is to inform you that " + sending_user.username + " has subscribed you to the group " + groupname + "'"
                            set_notif_val(request, group_id, msg, activ, bx)
                    for each in new_users:
                        bx = User.objects.get(id=each)
                        msg = "'This is to inform you that " + sending_user.username + " has subscribed you to the group " + groupname + "'"
                        set_notif_val(request, group_id, msg, activ, bx)
                except Exception as mailerr:
                    pass
            deleted_users = set(deleted_users) - set(users)
            activ = "Unsubscribed from group"
            if deleted_users:
                for each in deleted_users:
                    bx = User.objects.get(id=each)
                    node.author_set.remove(each)
                    try:
                        msg = "'This is to inform you that " + sending_user.username + " has unsubscribed you from the group " + groupname + "'"
                        set_notif_val(request, group_id, msg, activ, bx)
                    except Exception as mailerror:
                        pass
                node.save(groupid=group_id)
            return HttpResponse("Success")
        else:
            coll_obj_list = []
            lstusers = []
            owner = node.created_by
            users = User.objects.all().order_by("email")
            user_names = []
            st = []
            for each in users:
                if each.id != owner and each.id not in node.author_set:
                    st.append(each)
                else:
                    if each.id != owner:
                        coll_obj_list.append(each)

            data_list = set_drawer_widget_for_users(st, coll_obj_list)
            return HttpResponse(json.dumps(data_list))

    except Exception as e:
        print "Exception in invite_users " + str(e)
        return HttpResponse("Failure")
Example #9
0
def invite_users(request,group_id):
    try:
        sending_user=request.user
        node = node_collection.one({'_id': ObjectId(group_id)})
        if request.method == "POST":
            exst_users=[]
            new_users=[]
            users=[]
            deleted_users=node.author_set
            groupname=node.name
            users_to_invite = request.POST['users']
            not_status=request.POST['notif_status']
            new_users_list=users_to_invite.split(",")
            for each in new_users_list:
                if each :
                    users.append(int(each))
            if users:
                for each in users:
                    if each in node.author_set:
                        exst_users.append(each)
                    else:
                        if each not in node.author_set:
                            new_users.append(each)
                            node.author_set.append(each);
                node.save(groupid=group_id)
                for each in users:
                    counter_obj = Counter.get_counter_obj(each, ObjectId(group_id))
                    counter_obj['is_group_member'] = True
                    counter_obj.save()
                try:
                    # Send invitations according to not_status variable
                    activ="invitation to join in group"
                    if not_status == "ON":
                        for each in exst_users:
                            bx=User.objects.get(id=each)
                            msg="'This is to inform you that " +sending_user.username+ " has subscribed you to the group " +groupname+"'"
                            set_notif_val(request,group_id,msg,activ,bx)
                    for each in new_users:
                        bx=User.objects.get(id=each)
                        msg="'This is to inform you that " +sending_user.username+ " has subscribed you to the group " +groupname+"'"
                        set_notif_val(request,group_id,msg,activ,bx)
                except Exception as mailerr:
                    pass
            deleted_users=set(deleted_users)-set(users)
            activ="Unsubscribed from group"
            if deleted_users:
                for each in deleted_users:
                    bx=User.objects.get(id=each)
                    node.author_set.remove(each)
                    try:
                        msg="'This is to inform you that " +sending_user.username+ " has unsubscribed you from the group " +groupname+"'"
                        set_notif_val(request,group_id,msg,activ,bx)
                    except Exception as mailerror:
                        pass
                node.save(groupid=group_id)
            return HttpResponse("Success")
        else:
            coll_obj_list = []
            lstusers=[]
            owner=node.created_by
            users=User.objects.all().order_by("email")
            user_names=[]
            st=[]
            for each in users:
                if each.id != owner and each.id not in node.author_set:
                   st.append(each)
                else:
                    if each.id !=owner:
                        coll_obj_list.append(each)
            from gnowsys_ndf.ndf.views.ajax_views import set_drawer_widget_for_users

            data_list=set_drawer_widget_for_users(st,coll_obj_list)
            return HttpResponse(json.dumps(data_list))

    except Exception as e:
        print "Exception in invite_users "+str(e)
        return HttpResponse("Failure")
Example #10
0
		asset_content_obj = node_collection.collection.GSystem()
	asset_content_obj.fill_gstystem_values(request=request,
											uploaded_file=files[0],
											**kwargs)
	asset_content_obj.fill_node_values(**kwargs)
	asset_content_obj.save(groupid=group_id)
	asset_contents_list = [asset_content_obj._id]
	rt_has_asset_content = node_collection.one({'_type': 'RelationType',
		'name': 'has_assetcontent'})
	asset_grels = triple_collection.find({'_type': 'GRelation', \
		'relation_type': rt_has_asset_content._id,'subject': asset_obj._id},
		{'_id': 0, 'right_subject': 1})
	for each_asset in asset_grels:
		asset_contents_list.append(each_asset['right_subject'])
	
	create_grelation(asset_obj._id, rt_has_asset_content, asset_contents_list)
	active_user_ids_list = [request.user.id]
	if GSTUDIO_BUDDY_LOGIN:
		active_user_ids_list += Buddy.get_buddy_userids_list_within_datetime(request.user.id, datetime.datetime.now())
		# removing redundancy of user ids:
		active_user_ids_list = dict.fromkeys(active_user_ids_list).keys()

	counter_objs_cur = Counter.get_counter_objs_cur(active_user_ids_list, group_id)
	# counter_obj = Counter.get_counter_obj(request.user.id, group_id)
	for each_counter_obj in counter_objs_cur:
		each_counter_obj['file']['created'] += 1
		each_counter_obj['group_points'] += GSTUDIO_FILE_UPLOAD_POINTS
		each_counter_obj.last_update = datetime.datetime.now()
		each_counter_obj.save()
	return asset_content_obj