Example #1
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 #2
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")