Exemple #1
0
def new_message(request, template):
    """Send a new private message."""
    to = request.GET.get('to')
    if to:
        try:
            User.objects.get(username=to)
        except User.DoesNotExist:
            contrib_messages.add_message(
                request, contrib_messages.ERROR,
                _('Invalid username provided. Enter a new username below.'))
            return HttpResponseRedirect(reverse('messages.new'))

    form = MessageForm(request.POST or None, initial={'to': to})

    if request.method == 'POST' and form.is_valid():
        send_message(form.cleaned_data['to'], form.cleaned_data['message'],
                     request.user)
        if form.cleaned_data['in_reply_to']:
            irt = form.cleaned_data['in_reply_to']
            try:
                m = InboxMessage.objects.get(pk=irt, to=request.user)
                m.update(replied=True)
            except InboxMessage.DoesNotExist:
                pass
        contrib_messages.add_message(request, contrib_messages.SUCCESS,
                                     _('Your message was sent!'))
        return HttpResponseRedirect(reverse('messages.inbox'))

    return render(request, template, {'form': form})
Exemple #2
0
def new_message(request, template):
    """Send a new private message."""
    to = request.GET.get('to')
    if to:
        try:
            User.objects.get(username=to)
        except User.DoesNotExist:
            contrib_messages.add_message(
                request, contrib_messages.ERROR,
                _('Invalid username provided. Enter a new username below.'))
            return HttpResponseRedirect(reverse('messages.new'))

    form = MessageForm(request.POST or None, initial={'to': to})

    if request.method == 'POST' and form.is_valid():
        send_message(form.cleaned_data['to'], form.cleaned_data['message'],
                     request.user)
        if form.cleaned_data['in_reply_to']:
            irt = form.cleaned_data['in_reply_to']
            try:
                m = InboxMessage.objects.get(pk=irt, to=request.user)
                m.update(replied=True)
            except InboxMessage.DoesNotExist:
                pass
        contrib_messages.add_message(request, contrib_messages.SUCCESS,
                                     _('Your message was sent!'))
        return HttpResponseRedirect(reverse('messages.inbox'))

    return render(request, template, {'form': form})
Exemple #3
0
def new_message(request):
    user = request.user
    profile = Profile.objects.get(user=user)
    try:
        ganaderia = Ganaderia.objects.get(perfil=user)
    except ObjectDoesNotExist:
        return redirect(reverse('agrega_ganaderia_config'))

    number_message = Message.objects.filter(Q(receiver_id=user.id), Q(front=True), Q(read_at=False)).count()
    msg_complete = Message.objects.all().order_by('sent_at')

    date_now = datetime.datetime.today()
    if request.method == 'POST':
        form_message = MessageForm(request.POST)
        if form_message.is_valid():
            form_message = form_message.save(commit=False)
            form_message.sender = profile
            form_message.sent_at = date_now
            form_message.read_at = False
            for i in msg_complete:
                if ((i.receiver_id == form_message.receiver_id) & (i.sender_id == form_message.sender_id)) | ((i.sender_id == form_message.receiver_id) & (i.receiver_id == form_message.sender_id)):
                    i.front = False
                    i.save()
            form_message.front = True
            form_message.save()

            number_message = number_messages(request, str(form_message.receiver_id))
            data = serializers.serialize("json", User.objects.all())

            ishout_client.emit(
                    form_message.receiver_id,
                    'alertchannel',
                    data = {'msg': data,
                        'number_messages': number_message,}
                    )

            return HttpResponseRedirect(reverse('messages_list'))
            # return redirect(reverse('messages_list'))

    else:
        form_message = MessageForm()
        profile_model = get_profile_model()
        ganaderia = Ganaderia.objects.get(perfil=user)
        receivers = profile_model.objects.get_visible_profiles(user).select_related().exclude(id=user.id).filter(ganaderia_perfil=ganaderia)
    return render_to_response('new_message.html',
            {'form': form_message,
                'number_messages': number_message,
                'receivers': receivers,
                },
            context_instance=RequestContext(request))
Exemple #4
0
def new_message(request):
    form = MessageForm(request.POST or None)

    if request.method == 'POST' and form.is_valid():
        send_message(form.cleaned_data['to'], form.cleaned_data['message'],
                     request.user)
        if form.cleaned_data['in_reply_to']:
            irt = form.cleaned_data['in_reply_to']
            try:
                m = InboxMessage.objects.get(pk=irt, to=request.user)
                m.update(replied=True)
            except InboxMessage.DoesNotExist:
                pass
        contrib_messages.add_message(request, contrib_messages.SUCCESS,
                                     _('Your message was sent!'))
        return HttpResponseRedirect(reverse('messages.inbox'))

    return jingo.render(request, 'messages/new.html', {'form': form})
Exemple #5
0
def new_message(request):
    form = MessageForm(request.POST or None)

    if request.method == 'POST' and form.is_valid():
        send_message(form.cleaned_data['to'], form.cleaned_data['message'],
                     request.user)
        if form.cleaned_data['in_reply_to']:
            irt = form.cleaned_data['in_reply_to']
            try:
                m = InboxMessage.objects.get(pk=irt, to=request.user)
                m.update(replied=True)
            except InboxMessage.DoesNotExist:
                pass
        contrib_messages.add_message(request, contrib_messages.SUCCESS,
                                     _('Your message was sent!'))
        return HttpResponseRedirect(reverse('messages.inbox'))

    return jingo.render(request, 'messages/new.html', {'form': form})