Пример #1
0
 def test_return_values(self):
     self.assertEqual(str(self.message_one), "A not that long message")
     self.assertEqual(self.message_one.message, "A not that long message")
     self.assertEqual(self.message_three.message, "A shorter message")
     self.assertEqual(
         Message.get_conversations(self.user)[0]['last'],
         self.message_two.date)
     self.assertEqual(
         Message.get_conversations(self.other_user)[0]['last'],
         self.message_three.date)
Пример #2
0
def new(request):
    if request.method == 'POST':
        from_user = request.user
        to_user_username = request.POST.get('to')
        try:
            to_user = User.objects.get(username=to_user_username)

        except Exception:
            try:
                to_user_username = to_user_username[
                    to_user_username.rfind('(') + 1:len(to_user_username) - 1]
                to_user = User.objects.get(username=to_user_username)

            except Exception:
                return redirect('/messages/new/')

        message = request.POST.get('message')
        if len(message.strip()) == 0:
            return redirect('/messages/new/')

        if from_user != to_user:
            Message.send_message(from_user, to_user, message)

        return redirect('/messages/{0}/'.format(to_user_username))

    else:
        conversations = Message.get_conversations(user=request.user)
        return render(request, 'messenger/new.html',
                      {'conversations': conversations})
Пример #3
0
def new(request):
    if not request.user.is_authenticated():
        return render(request, 'authentication/login.html')

    else:

        if request.method == 'POST':
            from_user = request.user
            to_user_username = request.POST.get('to')
            try:
                to_user = User.objects.get(username=to_user_username)

            except Exception:
                try:
                    to_user_username = to_user_username[
                        to_user_username.rfind('(') + 1:len(to_user_username) -
                        1]
                    to_user = User.objects.get(username=to_user_username)

                except Exception:
                    return redirect('/messages/new/')

            message = request.POST.get('message')
            objet = request.POST.get('objet')
            url = request.POST.get('url')

            if not url:
                produit = None
            else:
                produit = Produit.objects.get(pk=url)

            if len(message.strip()) == 0:
                return redirect('/messages/new/')

            if from_user != to_user:
                Message.send_message(from_user, to_user, message, objet,
                                     produit)

            id_boutique = request.GET.get('boutic')
            return redirect('/messages/{0}/?too={1}'.format(
                to_user_username, to_user_username))

        else:
            id_boutique = request.GET.get('boutic')

            conversations = Message.get_conversations(user=request.user)

            if not Utilisateur.objects.filter(user=request.user).exists():
                produituser = Produit.objects.filter(boutique_id=id_boutique)
                return render(request, 'messenger/new.html', {
                    'conversations': conversations,
                    'produituser': produituser
                })
            else:
                produituser = Produit.objects.filter(
                    boutique__user__username=request.user)
                return render(request, 'messenger/new.html', {
                    'conversations': conversations,
                    'produituser': produituser
                })
Пример #4
0
def messages(request, username):
    conversations = Message.get_conversations(user=request.user)
    active_conversation = username
    messages = Message.objects.filter(user=request.user,
                                      conversation__username=username)
    messages.update(is_read=True)

    for conversation in conversations:
        if conversation['user'].username == username:
            conversation['unread'] = 0

    boutique_use = request.GET.get('too')
    if not Utilisateur.objects.filter(user=request.user).exists():
        produituser = Produit.objects.filter(
            boutique__user__username=boutique_use)
        return render(
            request, 'messenger/inbox.html', {
                'messages': messages,
                'active': active_conversation,
                'conversations': conversations,
                'produituser': produituser
            })
    else:
        produituser = Produit.objects.filter(
            boutique__user__username=request.user)
        return render(
            request, 'messenger/inbox.html', {
                'messages': messages,
                'active': active_conversation,
                'conversations': conversations,
                'produituser': produituser
            })
Пример #5
0
 def test_sending_new_message(self):
     new_message = Message.send_message(self.other_user, self.user,
                                        "A short message")
     self.assertTrue(isinstance(new_message, Message))
     self.assertEqual(
         Message.get_conversations(self.other_user)[0]['last'],
         new_message.date)
     self.assertEqual(new_message.message, "A short message")
Пример #6
0
def u_messages(request, username):
    conversations = Message.get_conversations(user=request.user)
    active_conversation = username
    messages = Message.objects.filter(user=request.user,
                                      conversation__username=username)
    messages.update(is_read=True)
    for conversation in conversations:
        if conversation['user'].username == username:
            conversation['unread'] = 0

    return render(request, 'mentoring/profile.html', {
        'messages': messages,
        'conversations': conversations,
        'active': active_conversation
    })
Пример #7
0
def messages(request, username):
    conversations = Message.get_conversations(user=request.user)
    users_list = User.objects.filter(
        is_active=True).exclude(username=request.user).order_by('username')
    active_conversation = username
    messages = Message.objects.filter(user=request.user, conversation__username=username)
    messages.update(is_read=True)
    for conversation in conversations:
        if conversation['user'].username == username:
            conversation['unread'] = 0

    return render(request, 'messanger/inbox.html', {
        'messages': messages,
        'conversations': conversations,
        'users_list': users_list,
        'active': active_conversation
    })
Пример #8
0
def u_inbox(request):
    conversations = Message.get_conversations(user=request.user)
    active_conversation = None
    messages = None
    if conversations:
        conversation = conversations[0]
        active_conversation = conversation['user'].username
        messages = Message.objects.filter(user=request.user,
                                          conversation=conversation['user'])
        messages.update(is_read=True)
        for conversation in conversations:
            if conversation['user'].username == active_conversation:
                conversation['unread'] = 0

    return render(request, 'mentoring/profile.html', {
        'messages': messages,
        'conversations': conversations,
        'active': active_conversation
    })
Пример #9
0
def inbox2(request):
    conversations = Message.get_conversations(user=request.user)
    users_list = User.objects.filter()
    active_conversations = None
    messages = None
    if conversations:
        conversation = conversations[0]
        active_conversations = conversation['user'].username
        messages = Message.objects.filter(user=request.user, conversation=conversation['user'])
        messages.update(is_read=True)
        for conversation in conversations:
            if conversation in conversations:
                if conversation['user'].username == active_conversations:
                    conversation['unread'] = 0
    return render(request, 'messanger/inbox.html', {
        'messages': messages,
        'conversations': conversations,
        'users_list': users_list,
        'active': active_conversations
    })
Пример #10
0
def inbox(request):
    conversations = Message.get_conversations(user=request.user)
    active_conversation = None
    messages = None
    produituser = Produit.objects.filter(boutique__user_id=request.user.id)
    if conversations:
        conversation = conversations[0]
        active_conversation = conversation['user'].username
        messages = Message.objects.filter(user=request.user,
                                          conversation=conversation['user'])
        messages.update(is_read=True)
        for conversation in conversations:
            if conversation['user'].username == active_conversation:
                conversation['unread'] = 0

    return render(
        request, 'messenger/inbox.html', {
            'produituser': produituser,
            'messages': messages,
            'conversations': conversations,
            'active': active_conversation
        })
Пример #11
0
def messages(request, username):
    if request.method == 'GET':
        conversations = Message.get_conversations(user=request.user)
        users_list = User.objects.filter(is_active=True).exclude(
            username=request.user).order_by('username')
        active_conversation = username
        messages = Message.objects.filter(user=request.user,
                                          conversation__username=username)
        messages.update(is_read=True)
        for conversation in conversations:
            if conversation['user'].username == username:
                conversation['unread'] = 0

        return render(
            request, 'messenger/inbox.html', {
                'messages': messages,
                'conversations': conversations,
                'users_list': users_list,
                'active': active_conversation
            })
    else:
        from_user = request.user
        to_user = User.objects.get(username=username)
        message = request.POST.get('message')
        if request.POST.get("document") is None:
            save_path = os.path.join('sent_docs/',
                                     request.FILES['document'].name)
            doc = default_storage.save(save_path, request.FILES['document'])
            msg = Message.send_message(from_user, to_user, message, doc)
            conversations = Message.get_conversations(user=request.user)
            users_list = User.objects.filter(is_active=True).exclude(
                username=request.user).order_by('username')
            active_conversation = username
            messages = Message.objects.filter(user=request.user,
                                              conversation__username=username)
            messages.update(is_read=True)
            for conversation in conversations:
                if conversation['user'].username == username:
                    conversation['unread'] = 0

            return render(
                request, 'messenger/inbox.html', {
                    'messages': messages,
                    'conversations': conversations,
                    'users_list': users_list,
                    'active': active_conversation,
                })
        else:
            doc = None
            msg = Message.send_message(from_user, to_user, message, doc)
            conversations = Message.get_conversations(user=request.user)
            users_list = User.objects.filter(is_active=True).exclude(
                username=request.user).order_by('username')
            active_conversation = username
            messages = Message.objects.filter(user=request.user,
                                              conversation__username=username)
            messages.update(is_read=True)
            for conversation in conversations:
                if conversation['user'].username == username:
                    conversation['unread'] = 0

            return render(
                request, 'messenger/inbox.html', {
                    'messages': messages,
                    'conversations': conversations,
                    'users_list': users_list,
                    'active': active_conversation,
                })