Ejemplo n.º 1
0
def update_messages(request, socket, context, message):
    u = User.objects.get(username=red.get_user(socket.session.session_id))
    chat = Chat.objects.get(id=1)
    q = Message(text_chat=message['newmessage'], date_chat=timezone.now(), user=u, chat=chat)
    q.save()
    serialized = MessageSerializer(q)
    socket.send_and_broadcast(dict(action='chatBackEndOneMessage', chat_field=serialized.data))
Ejemplo n.º 2
0
def update_messages(request, socket, context, message):
    u = User.objects.get(username=red.get_user(socket.session.session_id))
    chat = Chat.objects.get(id=1)
    q = Message(text_chat=message['newmessage'],
                date_chat=timezone.now(),
                user=u,
                chat=chat)
    q.save()
    serialized = MessageSerializer(q)
    socket.send_and_broadcast(
        dict(action='chatBackEndOneMessage', chat_field=serialized.data))
Ejemplo n.º 3
0
 def handle(self, *args, **options):
     """
     ...
     """
     # rooms
     rooms_instances = [Room(name=f"name_{number}") for number in range(4)]
     Room.objects.bulk_create(rooms_instances)
     # messages
     messages_room_1_instances = [
         Message(text=f"text{number}", room_id=1,) for number in range(4)
     ]
     messages_room_2_instances = [
         Message(text=f"text{number}", room_id=2,) for number in range(3)
     ]
     Message.objects.bulk_create(messages_room_1_instances)
     Message.objects.bulk_create(messages_room_2_instances)
Ejemplo n.º 4
0
def join(request):
    chat_id = request.POST.get("chat_id", "")

    storage = ChatStorage(chat_id)
    user = User.objects.get(pk=request.user.pk)
    text = u"%s входит в чат." % user.get_full_name()
    message = Message(request.user.pk, text, type=Message.TYPE_SYSTEM)
    storage.put(message)
    return HttpResponse('')
Ejemplo n.º 5
0
def send(request):
    chat_id = request.POST.get("chat_id", "")
    message = request.POST.get("message", "")
    message = clean_message(message)

    storage = ChatStorage(chat_id)
    message = Message(request.user.pk, message)
    storage.put(message)
    return HttpResponse('')
Ejemplo n.º 6
0
 def test_storage_poinert_overflow(self):
     chat = self.chat
     storage = ChatStorage(chat.id)
     user_id = self.test_user.id
     text = "test message %d"
     messages = deque([], settings.CHAT_MAX_ITEMS)
     for i in range(settings.CHAT_MAX_ITEMS + 7):
         message = Message(user_id, text % i)
         messages.append(message)
         storage.put(message)
     #time.sleep(2)
     storage = ChatStorage(chat.id)
     self.failUnlessEqual(list(messages), storage.all())
Ejemplo n.º 7
0
    def test_storage_poinert(self):
        chat = self.chat
        storage = ChatStorage(chat.id)
        user_id = self.test_user.id
        text = "test message %d"
        messages = []
        for i in range(2):
            message = Message(user_id, text % i)
            messages.append(message)
            storage.put(message)

        storage = ChatStorage(chat.id)
        self.failUnlessEqual(messages, storage.all())
Ejemplo n.º 8
0
    def test_storage(self):
        chat = self.chat
        storage = ChatStorage(chat.id)
        self.failUnlessEqual([], storage.all())

        user_id = self.test_user.id
        text = "test message"

        message = Message(user_id, text)
        storage.put(message)

        storage = ChatStorage(chat.id)
        self.failUnlessEqual([message], storage.all())