Exemple #1
0
    def get_context_data(self, **kwargs):
        context = super(ChatView, self).get_context_data(**kwargs)
        allowed_rooms = self.request.user.get_rooms(self.request.org).order_by('name')

        if 'room' in self.kwargs:
            try:
                initial_room = allowed_rooms.get(pk=self.kwargs['room'])
            except Room.DoesNotExist:
                raise PermissionDenied()
        else:
            initial_room = allowed_rooms.first()

        msg_text_chars = MESSAGE_MAX_LEN - len(Message.get_user_prefix(self.request.user))

        context['rooms'] = allowed_rooms
        context['initial_room'] = initial_room
        context['msg_text_chars'] = msg_text_chars
        return context
Exemple #2
0
    def get_context_data(self, **kwargs):
        context = super(ChatView, self).get_context_data(**kwargs)
        allowed_rooms = self.request.user.get_rooms(
            self.request.org).order_by('name')

        if 'room' in self.kwargs:
            try:
                initial_room = allowed_rooms.get(pk=self.kwargs['room'])
            except Room.DoesNotExist:
                raise PermissionDenied()
        else:
            initial_room = allowed_rooms.first()

        msg_text_chars = MESSAGE_MAX_LEN - len(
            Message.get_user_prefix(self.request.user))

        context['rooms'] = allowed_rooms
        context['initial_room'] = initial_room
        context['msg_text_chars'] = msg_text_chars
        return context
Exemple #3
0
 def test_get_user_prefix(self):
     self.assertEqual(Message.get_user_prefix(self.superuser), '')
     self.assertEqual(Message.get_user_prefix(self.user1), 'sammy: ')