示例#1
0
文件: views.py 项目: woostersoz/3m
def user_create_room(request):
    try:
        post_data = json.loads(request.body)
        user_id = post_data['user_id']
        nickname = post_data['nickname'] #redundant but needed
        room_name = post_data['room_name']
        room_description = post_data['room_description']
        company_id = post_data['company_id'] 
        
        company = Company.objects(company_id=company_id).first()
        company_id = company.id
    
        chatRoom = ChatRoom(owner=user_id, name=room_name, description=room_description, company=company_id, nickname=nickname)
        chatRoom.save()
        serializer = ChatroomSerializer(chatRoom, many=False) 
        chatUser = ChatUser(user=user_id, room=chatRoom.id, company=company_id, nickname=nickname)
        chatUser.save()
        return JsonResponse({"message": "Channel created and you have joined it", "room" : serializer.data}, safe=False)
    except Exception as e:
        return JsonResponse({'Error' : str(e)})
示例#2
0
文件: views.py 项目: woostersoz/3m
def rooms(request, company_id):
    """
    Homepage - lists all rooms
    """
    #company_id = request.user.company
    company = Company.objects(company_id=company_id).first()
    company_id = company.id
    rooms = []
    rooms = ChatRoom.objects(company=company_id).all()
    serializer = ChatroomSerializer(rooms, many=True) 
    return Response(serializer.data)  
示例#3
0
文件: views.py 项目: woostersoz/3m
def getUserNotJoinedRooms(request, company_id):
    try:
        #print 'in user room'
        user_id = request.user.id
        #company_id = request.user.company
        company = Company.objects(company_id=company_id).first()
        company_id = company.id
        #print ' user id is ' + str(user_id)
        roomIds = []
        chatUsers = ChatUser.objects(Q(user=user_id) & Q(company=company_id)).all()
        for chatUser in chatUsers:
            roomIds.append(chatUser.room.id)
        #print 'rooms1 are ' + str(len(chatUsersRoomIds))
        notJoinedRooms = ChatRoom.objects(Q(id__nin=roomIds)  & Q(company=company_id))
        #print 'rooms are ' + str(len(subscribedRooms))
        serializer = ChatroomSerializer(notJoinedRooms, many=True) 
        return Response(serializer.data)  
    except Exception as e:
        return Response(str(e)) 
示例#4
0
文件: views.py 项目: woostersoz/3m
def create(request):
    name = request.POST.get("name")
    if name:
        room, created = ChatRoom.objects(name=name).update(upsert=True)
        return redirect(room)
    return redirect(room)