示例#1
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))
示例#2
0
def video_edit(request,group_id,_id):
    # ins_objectid  = ObjectId()
    # if ins_objectid.is_valid(group_id) is False :
    #     group_ins = node_collection.find_one({'_type': "Group","name": group_id})
    #     auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) })
    #     if group_ins:
    #         group_id = str(group_ins._id)
    #     else :
    #         auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) })
    #         if auth :
    #             group_id = str(auth._id)
    # else :
    #     pass
    try:
        group_id = ObjectId(group_id)
    except:
        group_name, group_id = get_group_name_id(group_id)
        
    vid_node = node_collection.one({"_id": ObjectId(_id)})
    title = GST_VIDEO.name
    video_obj=request.GET.get("vid_id","")
    group_obj = node_collection.one({'_id': ObjectId(group_id)})
    ce_id = request.GET.get('course_event_id')
    course_tab_title = request.POST.get("course_tab_title",'')
    res = request.GET.get('res')

    if request.method == "POST":

        # get_node_common_fields(request, vid_node, group_id, GST_VIDEO)
        vid_node.save(is_changed=get_node_common_fields(request, vid_node, group_id, GST_VIDEO),groupid=group_id)
        thread_create_val = request.POST.get("thread_create",'')
        course_tab_title = request.POST.get("course_tab_title",'')
        # help_info_page = request.POST.getlist('help_info_page','')
        help_info_page = request.POST['help_info_page']
        if help_info_page:
            help_info_page = json.loads(help_info_page)
        
        discussion_enable_at = node_collection.one({"_type": "AttributeType", "name": "discussion_enable"})
        if thread_create_val == "Yes":
            create_gattribute(vid_node._id, discussion_enable_at, True)
            return_status = create_thread_for_node(request,group_id, vid_node)
        else:
            create_gattribute(vid_node._id, discussion_enable_at, False)

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

            # Check if node had has_help RT
            grel_dict = get_relation_value(vid_node._id,"has_help")
            # print "\n\n grel_dict ==== ", grel_dict
            if grel_dict:
                grel_id = grel_dict.get("grel_id","")
                if grel_id:
                    for each_grel_id in grel_id:
                        del_status, del_status_msg = delete_grelation(
                            subject_id=vid_node._id,
                            node_id=each_grel_id,
                            deletion_type=0
                        )
                        # print "\n\n del_status == ",del_status
                        # print "\n\n del_status_msg == ",del_status_msg
        if "CourseEventGroup" not in group_obj.member_of_names_list:
            get_node_metadata(request,vid_node)
            teaches_list = request.POST.get('teaches_list', '')  # get the teaches list
            assesses_list = request.POST.get('assesses_list', '')  # get the teaches list
            if teaches_list !='':
                teaches_list=teaches_list.split(",")
            create_grelation_list(vid_node._id,"teaches",teaches_list)
            if assesses_list !='':
                assesses_list=assesses_list.split(",")
            create_grelation_list(vid_node._id,"assesses",assesses_list)
            return HttpResponseRedirect(reverse('video_detail', kwargs={'group_id': group_id, '_id': vid_node._id}))
        else:
            vid_node.status = u"PUBLISHED"
            vid_node.save()
            if course_tab_title:
                if course_tab_title == "raw material":
                    course_tab_title = "raw_material"
                return HttpResponseRedirect(reverse('course_'+course_tab_title + '_detail', kwargs={'group_id': group_id, 'node_id': str(vid_node._id)}))
            return HttpResponseRedirect(reverse('course_about', kwargs={'group_id': group_id}))
            # url = "/"+ str(group_id) +"/?selected="+str(vid_node._id)+"#view_page"
            # return HttpResponseRedirect(url)

    else:
        vid_col = node_collection.find({'member_of': GST_VIDEO._id,'group_set': ObjectId(group_id)})
        nodes_list = []
        for each in vid_col:
          nodes_list.append(str((each.name).strip().lower()))

        return render_to_response("ndf/video_edit.html",
                                  { 'node': vid_node, 'title': title,
                                    'group_id': group_id,
                                    'groupid':group_id,
                                    'video_obj':video_obj,
                                    'nodes_list':nodes_list,
                                    'ce_id': ce_id,
                                    'res': res, 'course_tab_title':course_tab_title
                                },
                                  context_instance=RequestContext(request)
                              )
示例#3
0
文件: page.py 项目: g66shivam/gstudio
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)
                              )