예제 #1
0
파일: forum.py 프로젝트: 91ranjan/gstudio
def delete_thread(request,group_id,forum_id,node_id):
    """ Changing status of thread to HIDDEN
    """
    ins_objectid  = ObjectId()
    if ins_objectid.is_valid(node_id) : 
        thread=node_collection.one({'_id':ObjectId(node_id)})
    else:
        return
    forum = node_collection.one({'_id': ObjectId(forum_id)})
    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
    op = node_collection.collection.update({'_id': ObjectId(node_id)}, {'$set': {'status': u"HIDDEN"}})

    node=node_collection.one({'_id':ObjectId(node_id)})
    forum_threads = []
    exstng_reply = node_collection.find({'$and':[{'_type':'GSystem'},{'prior_node':ObjectId(forum._id)}],'status':{'$nin':['HIDDEN']}})
    exstng_reply.sort('created_at')
    forum_node=node_collection.one({'_id':ObjectId(forum_id)})
    for each in exstng_reply:
        forum_threads.append(each.name)
    #send notifications to all group members
    colg=node_collection.one({'_id':ObjectId(group_id)})
    for each in colg.author_set:
        if each != colg.created_by:
            bx=get_userobject(each)
            if bx:
                activity=request.user.username+" -deleted thread "
                prefix=" in the forum "+forum_node.name
                link="http://"+sitename+"/"+str(colg._id)+"/forum/"+str(forum_node._id)
                msg=activity+"-"+node.name+prefix+"- in the group '"+colg.name+"' created by you."+"'\n"+"Please visit "+link+" to see the forum."  
#                no_check=forum_notification_status(group_id,auth._id)
#                if no_check:
                ret = set_notif_val(request,group_id,msg,activity,bx)
    activity=request.user.username+" -deleted thread "    
    prefix=" in the forum "+forum_node.name
    bx=get_userobject(colg.created_by)
    if bx:
        link="http://"+sitename+"/"+str(colg._id)+"/forum/"+str(forum_node._id)
        msg=activity+"-"+node.name+prefix+"- in the group '"+colg.name+"' created by you."+"'\n"+"Please visit "+link+" to see the forum."  
#        no_check=forum_notification_status(group_id,auth._id)
#        if no_check:
        ret = set_notif_val(request,group_id,msg,activity,bx)
    #send notification code ends here
    variables = RequestContext(request,{
                                        'forum':forum,
                                        'groupid':group_id,'group_id':group_id,
                                        'forum_created_by':User.objects.get(id=forum.created_by).username
                                        })

    return render_to_response("ndf/forumdetails.html",variables)
예제 #2
0
파일: forum.py 프로젝트: 91ranjan/gstudio
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 }))
예제 #3
0
def delete_forum(request, group_id, node_id, relns=None):
    """ Changing status of forum to HIDDEN
    """
    # 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"
                                           }})

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

    #send notifications to all group members
    colg = node_collection.one({'_id': ObjectId(group_id)})
    for each in colg.author_set:
        if each != colg.created_by:
            bx = get_userobject(each)
            if bx:
                activity = request.user.username + " -deleted forum "
                msg = activity + "-" + node.name + "- in the group '" + colg.name
                #                no_check=forum_notification_status(group_id,auth._id)
                #                if no_check:
                ret = set_notif_val(request, group_id, msg, activity, bx)
    activity = request.user.username + " -deleted forum "
    bx = get_userobject(colg.created_by)
    if bx:
        msg = activity + "-" + node.name + "- in the group '" + colg.name + "' created by you"
        #        no_check=forum_notification_status(group_id,auth._id)
        #        if no_check:
        ret = set_notif_val(request, group_id, msg, activity, bx)
    return HttpResponseRedirect(reverse('forum', kwargs={'group_id':
                                                         group_id}))
예제 #4
0
파일: forum.py 프로젝트: 91ranjan/gstudio
def delete_forum(request,group_id,node_id,relns=None):
    """ Changing status of forum to HIDDEN
    """
    # 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"}})
    
    node=node_collection.one({'_id':ObjectId(node_id)})
    
    #send notifications to all group members
    colg=node_collection.one({'_id':ObjectId(group_id)})
    for each in colg.author_set:
        if each != colg.created_by:
            bx=get_userobject(each)
            if bx:
                activity=request.user.username+" -deleted forum "
                msg=activity+"-"+node.name+"- in the group '"+ colg.name
#                no_check=forum_notification_status(group_id,auth._id)
#                if no_check:
                ret = set_notif_val(request,group_id,msg,activity,bx)
    activity=request.user.username+" -deleted forum "    
    bx=get_userobject(colg.created_by)
    if bx:
        msg=activity+"-"+node.name+"- in the group '"+colg.name+"' created by you"  
#        no_check=forum_notification_status(group_id,auth._id)
#        if no_check:
        ret = set_notif_val(request,group_id,msg,activity,bx)
    return HttpResponseRedirect(reverse('forum', kwargs={'group_id': group_id}))
예제 #5
0
파일: forum.py 프로젝트: 91ranjan/gstudio
def edit_thread(request,group_id,forum_id,thread_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)

    forum=node_collection.one({'_id':ObjectId(forum_id)})
    thread=node_collection.one({'_id':ObjectId(thread_id)}) 
    exstng_reply = node_collection.find({'$and':[{'_type':'GSystem'},{'prior_node':ObjectId(forum._id)}]})
    nodes=[]
    exstng_reply.sort('created_at')
    for each in exstng_reply:
        nodes.append(each.name)
    request.session['nodes']=json.dumps(nodes)
    colg=node_collection.one({'_id':ObjectId(group_id)})   
    if request.method == 'POST':
        name = unicode(request.POST.get('thread_name',"")) # thread name
        thread.name = name
        
        content_org = request.POST.get('content_org',"") # thread content
        # print "content=",content_org
        if content_org:
            thread.content_org = unicode(content_org)
            usrname = request.user.username
            filename = slugify(name) + "-" + usrname + "-"
            thread.content = content_org

        thread.save(groupid=group_id) 

        link="http://"+sitename+"/"+str(colg._id)+"/forum/thread/"+str(thread._id)
        for each in colg.author_set:
            if each != colg.created_by:
                bx=get_userobject(each)
                if bx:
                    msg=request.user.username+" has edited thread- "+thread.name+"- in the forum " + forum.name + " in the group -'" + colg.name+"'\n"+"Please visit "+link+" to see the thread."
                    activity="Edited thread"
                    #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)
        activity=request.user.username+" edited thread -"
        bx=get_userobject(colg.created_by)
        prefix="-in the forum -"+forum.name
        if bx:
            msg=activity+"-"+thread.name+prefix+" in the group '"+colg.name+"' created by you"+"\n"+"Please visit "+link+" to see the thread"   
#            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,{'group_id':group_id,'thread_id': thread._id,'nodes':json.dumps(nodes)})
        return HttpResponseRedirect(reverse('thread', kwargs={'group_id':group_id,'thread_id': thread._id }))    
    else:
        return render_to_response("ndf/edit_thread.html",
                                    {   'group_id':group_id,
                                        'groupid':group_id,
                                        'forum': forum,
                                        'thread':thread,
                                        'forum_created_by':User.objects.get(id=forum.created_by).username
                                    },
                              RequestContext(request))
예제 #6
0
def delete_thread(request, group_id, forum_id, node_id):
    """ Changing status of thread to HIDDEN
    """
    ins_objectid = ObjectId()
    if ins_objectid.is_valid(node_id):
        thread = node_collection.one({'_id': ObjectId(node_id)})
    else:
        return
    forum = node_collection.one({'_id': ObjectId(forum_id)})
    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
    op = node_collection.collection.update({'_id': ObjectId(node_id)},
                                           {'$set': {
                                               'status': u"HIDDEN"
                                           }})

    node = node_collection.one({'_id': ObjectId(node_id)})
    forum_threads = []
    exstng_reply = node_collection.find({
        '$and': [{
            '_type': 'GSystem'
        }, {
            'prior_node': ObjectId(forum._id)
        }],
        'status': {
            '$nin': ['HIDDEN']
        }
    })
    exstng_reply.sort('created_at')
    forum_node = node_collection.one({'_id': ObjectId(forum_id)})
    for each in exstng_reply:
        forum_threads.append(each.name)
    #send notifications to all group members
    colg = node_collection.one({'_id': ObjectId(group_id)})
    for each in colg.author_set:
        if each != colg.created_by:
            bx = get_userobject(each)
            if bx:
                activity = request.user.username + " -deleted thread "
                prefix = " in the forum " + forum_node.name
                link = "http://" + sitename + "/" + str(
                    colg._id) + "/forum/" + str(forum_node._id)
                msg = activity + "-" + node.name + prefix + "- in the group '" + colg.name + "' created by you." + "'\n" + "Please visit " + link + " to see the forum."
                #                no_check=forum_notification_status(group_id,auth._id)
                #                if no_check:
                ret = set_notif_val(request, group_id, msg, activity, bx)
    activity = request.user.username + " -deleted thread "
    prefix = " in the forum " + forum_node.name
    bx = get_userobject(colg.created_by)
    if bx:
        link = "http://" + sitename + "/" + str(colg._id) + "/forum/" + str(
            forum_node._id)
        msg = activity + "-" + node.name + prefix + "- in the group '" + colg.name + "' created by you." + "'\n" + "Please visit " + link + " to see the forum."
        #        no_check=forum_notification_status(group_id,auth._id)
        #        if no_check:
        ret = set_notif_val(request, group_id, msg, activity, bx)
    #send notification code ends here
    variables = RequestContext(
        request, {
            'forum': forum,
            'groupid': group_id,
            'group_id': group_id,
            'forum_created_by': User.objects.get(id=forum.created_by).username
        })

    return render_to_response("ndf/forumdetails.html", variables)
예제 #7
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
                }))
예제 #8
0
def edit_thread(request, group_id, forum_id, thread_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)

    forum = node_collection.one({'_id': ObjectId(forum_id)})
    thread = node_collection.one({'_id': ObjectId(thread_id)})
    exstng_reply = node_collection.find(
        {'$and': [{
            '_type': 'GSystem'
        }, {
            'prior_node': ObjectId(forum._id)
        }]})
    nodes = []
    exstng_reply.sort('created_at')
    for each in exstng_reply:
        nodes.append(each.name)
    request.session['nodes'] = json.dumps(nodes)
    colg = node_collection.one({'_id': ObjectId(group_id)})
    if request.method == 'POST':
        name = unicode(request.POST.get('thread_name', ""))  # thread name
        thread.name = name

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

        thread.save(groupid=group_id)

        link = "http://" + sitename + "/" + str(
            colg._id) + "/forum/thread/" + str(thread._id)
        for each in colg.author_set:
            if each != colg.created_by:
                bx = get_userobject(each)
                if bx:
                    msg = request.user.username + " has edited thread- " + thread.name + "- in the forum " + forum.name + " in the group -'" + colg.name + "'\n" + "Please visit " + link + " to see the thread."
                    activity = "Edited thread"
                    #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)
        activity = request.user.username + " edited thread -"
        bx = get_userobject(colg.created_by)
        prefix = "-in the forum -" + forum.name
        if bx:
            msg = activity + "-" + thread.name + prefix + " in the group '" + colg.name + "' created by you" + "\n" + "Please visit " + link + " to see the thread"
            #            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, {
                'group_id': group_id,
                'thread_id': thread._id,
                'nodes': json.dumps(nodes)
            })
        return HttpResponseRedirect(
            reverse('thread',
                    kwargs={
                        'group_id': group_id,
                        'thread_id': thread._id
                    }))
    else:
        return render_to_response(
            "ndf/edit_thread.html", {
                'group_id': group_id,
                'groupid': group_id,
                'forum': forum,
                'thread': thread,
                'forum_created_by':
                User.objects.get(id=forum.created_by).username
            }, RequestContext(request))