Ejemplo n.º 1
0
def create_thread(request, group_id, forum_id):
    '''
    Method to create thread
    '''

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

    # forum_data = {
    #                 'name':forum.name,
    #                 'content':forum.content,
    #                 'created_by':User.objects.get(id=forum.created_by).username
    #             }
    # print forum_data

    forum_threads = []
    exstng_reply = node_collection.find({'$and':[{'_type':'GSystem'},{'prior_node':ObjectId(forum._id)}],'status':{'$nin':['HIDDEN']}})
    exstng_reply.sort('created_at')
    for each in exstng_reply:
        forum_threads.append((each.name).strip().lower())

    if request.method == "POST":

        colg = node_collection.one({'_id':ObjectId(group_id)})

        name = unicode(request.POST.get('thread_name',""))
        content_org = request.POST.get('content_org',"")

        # -------------------
        colrep = node_collection.collection.GSystem()
        colrep.member_of.append(twist_gst._id)
        # ADDED ON 14th July
        colrep.access_policy = u"PUBLIC"
        colrep.url = set_all_urls(colrep.member_of)
        colrep.prior_node.append(forum._id)
        colrep.name = name
        if content_org:
            colrep.content_org = unicode(content_org)
            # Required to link temporary files with the current user who is modifying this document
            usrname = request.user.username
            filename = slugify(name) + "-" + usrname + "-"
            colrep.content = content_org

        usrid = int(request.user.id)
        colrep.created_by = usrid
        colrep.modified_by = usrid

        if usrid not in colrep.contributors:
            colrep.contributors.append(usrid)

        colrep.group_set.append(colg._id)
        colrep.save(groupid=group_id)
        has_thread_rt = node_collection.one({"_type": "RelationType", "name": u"has_thread"})
        gr = create_grelation(forum._id, has_thread_rt, colrep._id)

        
        '''Code to send notification to all members of the group except those whose notification preference is turned OFF'''
        link="http://"+sitename+"/"+str(colg._id)+"/forum/thread/"+str(colrep._id)
        for each in colg.author_set:
            bx=User.objects.filter(id=each)
            if bx:
                bx=User.objects.get(id=each)
            else:
                continue
            activity="Added thread"
            msg=request.user.username+" has added a thread in the forum " + forum.name + " in the group -'" + colg.name+"'\n"+"Please visit "+link+" to see the thread."
            if bx:
                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)
        url_name = "/" + group_id + "/forum/thread/" + str(colrep._id)
        return HttpResponseRedirect(url_name)
        # variables = RequestContext(request,
        #                              {  'forum':forum,
        #                                 'thread':colrep,
        #                                 'eachrep':colrep,
        #                                 'groupid':group_id,
        #                                 'group_id':group_id,
        #                                 'user': request.user,
        #                                 'reply_count':0,
        #                                 'forum_threads': json.dumps(forum_threads),
        #                                 'forum_created_by':User.objects.get(id=forum.created_by).username
        #                             })
        # print "\n\n renedering to thread_details"
        # return render_to_response("ndf/thread_details.html",variables)

    else:
        return render_to_response("ndf/create_thread.html",
                                    {   'group_id':group_id,
                                        'groupid':group_id,
                                        'forum': forum,
                                        'forum_threads': json.dumps(forum_threads),
                                        'forum_created_by':User.objects.get(id=forum.created_by).username
                                    },
                              RequestContext(request))
Ejemplo n.º 2
0
def create_thread(request, group_id, forum_id):
    '''
    Method to create thread
    '''

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

    # forum_data = {
    #                 'name':forum.name,
    #                 'content':forum.content,
    #                 'created_by':User.objects.get(id=forum.created_by).username
    #             }
    # print forum_data

    forum_threads = []
    exstng_reply = node_collection.find({
        '$and': [{
            '_type': 'GSystem'
        }, {
            'prior_node': ObjectId(forum._id)
        }],
        'status': {
            '$nin': ['HIDDEN']
        }
    })
    exstng_reply.sort('created_at')
    for each in exstng_reply:
        forum_threads.append((each.name).strip().lower())

    if request.method == "POST":

        colg = node_collection.one({'_id': ObjectId(group_id)})

        name = unicode(request.POST.get('thread_name', ""))
        content_org = request.POST.get('content_org', "")

        # -------------------
        colrep = node_collection.collection.GSystem()
        colrep.member_of.append(twist_gst._id)
        # ADDED ON 14th July
        colrep.access_policy = u"PUBLIC"
        colrep.url = set_all_urls(colrep.member_of)
        colrep.prior_node.append(forum._id)
        colrep.name = name
        if content_org:
            colrep.content_org = unicode(content_org)
            # Required to link temporary files with the current user who is modifying this document
            usrname = request.user.username
            filename = slugify(name) + "-" + usrname + "-"
            colrep.content = content_org

        usrid = int(request.user.id)
        colrep.created_by = usrid
        colrep.modified_by = usrid

        if usrid not in colrep.contributors:
            colrep.contributors.append(usrid)

        colrep.group_set.append(colg._id)
        colrep.save(groupid=group_id)
        has_thread_rt = node_collection.one({
            "_type": "RelationType",
            "name": u"has_thread"
        })
        gr = create_grelation(forum._id, has_thread_rt, [colrep._id])

        try:
            '''Code to send notification to all members of the group except those whose notification preference is turned OFF'''
            link = "http://" + sitename + "/" + str(
                colg._id) + "/forum/thread/" + str(colrep._id)
            for each in colg.author_set:
                bx = User.objects.filter(id=each)
                if bx:
                    bx = User.objects.get(id=each)
                else:
                    continue
                activity = "Added thread"
                msg = request.user.username + " has added a thread in the forum " + forum.name + " in the group -'" + colg.name + "'\n" + "Please visit " + link + " to see the thread."
                if bx:
                    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)
        except Exception, e:
            print e

        url_name = "/" + group_id + "/forum/thread/" + str(colrep._id)
        return HttpResponseRedirect(url_name)
Ejemplo n.º 3
0
def edit_forum(request,group_id,forum_id):    
    '''
    Method to create forum and Retrieve all the forums
    '''
    forum = node_collection.one({ '_id': ObjectId(forum_id) })

    # # method to convert group_id to ObjectId if it is groupname
    # 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)

    # getting all the values from submitted form
    if request.method == "POST":

        colg = node_collection.one({'_id':ObjectId(group_id)}) # getting group ObjectId

        colf = node_collection.one({'_id':ObjectId(forum_id)}) # creating new/empty GSystem object

        name = unicode(request.POST.get('forum_name',"")).strip() # forum name
        colf.name = name
        
        content_org = request.POST.get('content_org',"") # forum content
        if content_org:
            colf.content_org = unicode(content_org)
            usrname = request.user.username
            filename = slugify(name) + "-" + usrname + "-"
            colf.content = content_org
        
        usrid = int(request.user.id)
        usrname = unicode(request.user.username)
        
        colf.modified_by = usrid

        if usrid not in colf.contributors:
            colf.contributors.append(usrid)
        

        ################# ADDED 14th July.Its done!
        colf.access_policy = u"PUBLIC"
        colf.url = set_all_urls(colf.member_of)

        ### currently timed forum feature is not in use ###
        # sdate=request.POST.get('sdate',"")
        # shrs= request.POST.get('shrs',"") 
        # smts= request.POST.get('smts',"")
        
        # edate= request.POST.get('edate',"")
        # ehrs= request.POST.get('ehrs',"")
        # emts=request.POST.get('emts',"")
        
        # start_dt={}
        # end_dt={}
        
        # if not shrs:
        #     shrs=0
        # if not smts:
        #     smts=0
        # if sdate:
        #     sdate1=sdate.split("/") 
        #     st_date = datetime.datetime(int(sdate1[2]),int(sdate1[0]),int(sdate1[1]),int(shrs),int(smts))
        #     start_dt[start_time.name]=st_date
        
        # if not ehrs:
        #     ehrs=0
        # if not emts:
        #     emts=0
        # if edate:
        #     edate1=edate.split("/")
        #     en_date= datetime.datetime(int(edate1[2]),int(edate1[0]),int(edate1[1]),int(ehrs),int(emts))
        #     end_dt[end_time.name]=en_date
       # colf.attribute_set.append(start_dt)
       # colf.attribute_set.append(end_dt)
        colf.save(groupid=group_id)
        '''Code to send notification to all members of the group except those whose notification preference is turned OFF'''
        link="http://"+sitename+"/"+str(colg._id)+"/forum/"+str(colf._id)
        for each in colg.author_set:
            bx=User.objects.get(id=each)
            activity="Edited forum"
            msg=usrname+" has edited forum -" +colf.name+" in the group -'"+colg.name+"'\n"+"Please visit "+link+" to see the forum."
            if bx:
                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)

        # returning response to ndf/forumdetails.html
        return HttpResponseRedirect(reverse('show', kwargs={'group_id':group_id,'forum_id': colf._id }))

        # variables=RequestContext(request,{'forum':colf})
        # return render_to_response("ndf/forumdetails.html",variables)

    # getting all the GSystem of forum to provide autocomplete/intellisence of forum names
    available_nodes = node_collection.find({'_type': u'GSystem', 'member_of': ObjectId(forum_gst._id),'group_set': ObjectId(group_id) })

    nodes_list = []
    for each in available_nodes:
      nodes_list.append(str((each.name).strip().lower()))

    return render_to_response("ndf/edit_forum.html",{'group_id':group_id,'groupid':group_id, 'nodes_list': nodes_list,'forum':forum},RequestContext(request))
Ejemplo n.º 4
0
def edit_forum(request, group_id, forum_id):
    '''
    Method to create forum and Retrieve all the forums
    '''
    forum = node_collection.one({'_id': ObjectId(forum_id)})

    # # method to convert group_id to ObjectId if it is groupname
    # 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)

    # getting all the values from submitted form
    if request.method == "POST":

        colg = node_collection.one({'_id': ObjectId(group_id)
                                    })  # getting group ObjectId

        colf = node_collection.one({'_id': ObjectId(forum_id)
                                    })  # creating new/empty GSystem object

        name = unicode(request.POST.get('forum_name',
                                        "")).strip()  # forum name
        colf.name = name

        content_org = request.POST.get('content_org', "")  # forum content
        if content_org:
            colf.content_org = unicode(content_org)
            usrname = request.user.username
            filename = slugify(name) + "-" + usrname + "-"
            colf.content = content_org

        usrid = int(request.user.id)
        usrname = unicode(request.user.username)

        colf.modified_by = usrid

        if usrid not in colf.contributors:
            colf.contributors.append(usrid)

        ################# ADDED 14th July.Its done!
        colf.access_policy = u"PUBLIC"
        colf.url = set_all_urls(colf.member_of)

        ### currently timed forum feature is not in use ###
        # sdate=request.POST.get('sdate',"")
        # shrs= request.POST.get('shrs',"")
        # smts= request.POST.get('smts',"")

        # edate= request.POST.get('edate',"")
        # ehrs= request.POST.get('ehrs',"")
        # emts=request.POST.get('emts',"")

        # start_dt={}
        # end_dt={}

        # if not shrs:
        #     shrs=0
        # if not smts:
        #     smts=0
        # if sdate:
        #     sdate1=sdate.split("/")
        #     st_date = datetime.datetime(int(sdate1[2]),int(sdate1[0]),int(sdate1[1]),int(shrs),int(smts))
        #     start_dt[start_time.name]=st_date

        # if not ehrs:
        #     ehrs=0
        # if not emts:
        #     emts=0
        # if edate:
        #     edate1=edate.split("/")
        #     en_date= datetime.datetime(int(edate1[2]),int(edate1[0]),int(edate1[1]),int(ehrs),int(emts))
        #     end_dt[end_time.name]=en_date
        # colf.attribute_set.append(start_dt)
        # colf.attribute_set.append(end_dt)
        colf.save(groupid=group_id)
        '''Code to send notification to all members of the group except those whose notification preference is turned OFF'''
        try:
            link = "http://" + sitename + "/" + str(
                colg._id) + "/forum/" + str(colf._id)
            for each in colg.author_set:
                bx = User.objects.get(id=each)
                activity = "Edited forum"
                msg = usrname + " has edited forum -" + colf.name + " in the group -'" + colg.name + "'\n" + "Please visit " + link + " to see the forum."
                if bx:
                    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)

        except Exception as e:
            print e
        # returning response to ndf/forumdetails.html
        return HttpResponseRedirect(
            reverse('show',
                    kwargs={
                        'group_id': group_id,
                        'forum_id': colf._id
                    }))

        # variables=RequestContext(request,{'forum':colf})
        # return render_to_response("ndf/forumdetails.html",variables)

    # getting all the GSystem of forum to provide autocomplete/intellisence of forum names
    available_nodes = node_collection.find({
        '_type': u'GSystem',
        'member_of': ObjectId(forum_gst._id),
        'group_set': ObjectId(group_id)
    })

    nodes_list = []
    for each in available_nodes:
        nodes_list.append(str((each.name).strip().lower()))

    return render_to_response(
        "ndf/edit_forum.html", {
            'group_id': group_id,
            'groupid': group_id,
            'nodes_list': nodes_list,
            'forum': forum
        }, RequestContext(request))