Example #1
0
File: views.py Project: HiPiH/life
def new(req, to_user_id=None):
    out = {}
    out['to_user'] = to_user = get_object_or_404(User, pk=to_user_id)
    if to_user == req.user:
        return HttpResponseRedirect('/')

    # НОВОЕ СООБЩЕНИЕ
    if req.POST:
        if 'action' in req.POST:
            if req.POST['action'] == 'send' and 'text' in req.POST:
                text = req.POST['text']
                if len(text) == 0:
                    out['textarea_error'] = _(u'введите текст сообщения!')
                else:
                    AuthorOrRecipient = Q(
                        author=req.user, recipient=to_user) | Q(
                            author=to_user, recipient=req.user)
                    try:
                        c = UsersCommunication.objects.get(AuthorOrRecipient)
                    except:
                        c = UsersCommunication(author=req.user,
                                               recipient=to_user)
                        c.save()
                    new_message = MessageCommunication(
                        communication_to=c,
                        text=text,
                        recipient=c.author
                        if c.recipient == req.user else c.recipient)
                    new_message.save()
                    return HttpResponseRedirect('/messages/%s/index.html' %
                                                c.id)

    return render_to_response('messages/new.html',
                              out,
                              context_instance=RequestContext(req))
Example #2
0
File: views.py Project: HiPiH/life
def new(req, to_user_id=None):
    out = {}
    out["to_user"] = to_user = get_object_or_404(User, pk=to_user_id)
    if to_user == req.user:
        return HttpResponseRedirect("/")

    # НОВОЕ СООБЩЕНИЕ
    if req.POST:
        if "action" in req.POST:
            if req.POST["action"] == "send" and "text" in req.POST:
                text = req.POST["text"]
                if len(text) == 0:
                    out["textarea_error"] = _(u"введите текст сообщения!")
                else:
                    AuthorOrRecipient = Q(author=req.user, recipient=to_user) | Q(author=to_user, recipient=req.user)
                    try:
                        c = UsersCommunication.objects.get(AuthorOrRecipient)
                    except:
                        c = UsersCommunication(author=req.user, recipient=to_user)
                        c.save()
                    new_message = MessageCommunication(
                        communication_to=c, text=text, recipient=c.author if c.recipient == req.user else c.recipient
                    )
                    new_message.save()
                    return HttpResponseRedirect("/messages/%s/index.html" % c.id)

    return render_to_response("messages/new.html", out, context_instance=RequestContext(req))
Example #3
0
File: views.py Project: HiPiH/life
def generator(req):
    out = {}
    for i in range(50000):
        c = UsersCommunication.objects.all().order_by("?")[0]
        new_message = MessageCommunication(
            communication_to=c, text=u"Текст №%s" % i, recipient=c.author if i < 25000 else c.recipient
        )
        new_message.save()
        print u"%s из %s" % (i, 50000)
    return HttpResponseRedirect("/messages/")
Example #4
0
File: views.py Project: HiPiH/life
def generator(req):
    out = {}
    for i in range(50000):
        c = UsersCommunication.objects.all().order_by('?')[0]
        new_message = MessageCommunication(
            communication_to=c,
            text=u'Текст №%s' % i,
            recipient=c.author if i < 25000 else c.recipient)
        new_message.save()
        print u'%s из %s' % (i, 50000)
    return HttpResponseRedirect('/messages/')
Example #5
0
File: views.py Project: HiPiH/life
def list(req, communication_id=None):
    out = {}
    out['LIMIT_SHOW'] = LIMIT_SHOW = 10
    # ВЫТАСКИВАЕМ СВЯЗКУ ЮЗЕРОВ ДЛЯ ОБЩЕНИЯ
    out['c'] = c = get_object_or_404(UsersCommunication,
                                     pk=int(communication_id))

    if c.author != req.user and c.recipient != req.user:
        return HttpResponseRedirect('/')

    can_sent = True
    can_sent_error = ''
    if c.author == req.user:
        if c.folder_r == 2:
            can_sent = False
            can_sent_error = u'Вы не можете написать сообщение, потому что Вас добавили в черный список'
        elif c.folder_r == 3:
            can_sent = False
            can_sent_error = u'Вы не можете написать сообщение, потому что Вас удалили из контактов'
        else:
            pass
    else:
        if c.folder_a == 2:
            can_sent = False
            can_sent_error = u'Вы не можете написать сообщение, потому что Вас добавили в черный список'
        elif c.folder_a == 3:
            can_sent = False
            can_sent_error = u'Вы не можете написать сообщение, потому что Вас удалили из контактов'
        else:
            pass
    out['can_sent'] = can_sent
    out['can_sent_error'] = can_sent_error

    # СПИСОК СООБЩЕНИЙ
    messages_list = MessageCommunication.objects.filter(
        communication_to=c)[:LIMIT_SHOW]

    # НОВОЕ СООБЩЕНИЕ
    if req.POST:
        if 'action' in req.POST:
            if req.POST['action'] == 'send' and 'text' in req.POST:
                text = req.POST['text']
                if len(text) == 0:
                    out['textarea_error'] = _(u'введите текст сообщения!')
                else:
                    new_message = MessageCommunication(
                        communication_to=c,
                        text=text,
                        recipient=c.author
                        if c.recipient == req.user else c.recipient)
                    new_message.save()
                    return HttpResponseRedirect('/messages/%s/index.html' %
                                                communication_id)

    # ЧТОБЫ БЫЛО ВИДНО КАКОЕ ПРОЧИТАНО КАКОЕ НЕТ :)
    for m in messages_list:
        m.is_new = m.is_read

    out['messages_list'] = messages_list

    # ИДЕМ ПО СПИСКУ НЕ ПРОЧИТАННЫХ И ДЕЛАЕМ ИХ ПРОЧИТАННЫМИ
    for m in MessageCommunication.objects.filter(communication_to=c,
                                                 is_read=False,
                                                 recipient=req.user):
        m.is_new = m.is_read
        if m.recipient == req.user and m.is_read == False:
            m.is_read = True
            m.save()
            if c.author == req.user:
                if c.count_mes_a_new > 0:
                    c.count_mes_a_new = c.count_mes_a_new - 1
                    c.save()
            elif c.recipient == req.user:
                if c.count_mes_r_new > 0:
                    c.count_mes_r_new = c.count_mes_r_new - 1
                    c.save()
            else:
                pass

    return render_to_response('messages/list.html',
                              out,
                              context_instance=RequestContext(req))
Example #6
0
File: views.py Project: HiPiH/life
def list(req, communication_id=None):
    out = {}
    out["LIMIT_SHOW"] = LIMIT_SHOW = 10
    # ВЫТАСКИВАЕМ СВЯЗКУ ЮЗЕРОВ ДЛЯ ОБЩЕНИЯ
    out["c"] = c = get_object_or_404(UsersCommunication, pk=int(communication_id))

    if c.author != req.user and c.recipient != req.user:
        return HttpResponseRedirect("/")

    can_sent = True
    can_sent_error = ""
    if c.author == req.user:
        if c.folder_r == 2:
            can_sent = False
            can_sent_error = u"Вы не можете написать сообщение, потому что Вас добавили в черный список"
        elif c.folder_r == 3:
            can_sent = False
            can_sent_error = u"Вы не можете написать сообщение, потому что Вас удалили из контактов"
        else:
            pass
    else:
        if c.folder_a == 2:
            can_sent = False
            can_sent_error = u"Вы не можете написать сообщение, потому что Вас добавили в черный список"
        elif c.folder_a == 3:
            can_sent = False
            can_sent_error = u"Вы не можете написать сообщение, потому что Вас удалили из контактов"
        else:
            pass
    out["can_sent"] = can_sent
    out["can_sent_error"] = can_sent_error

    # СПИСОК СООБЩЕНИЙ
    messages_list = MessageCommunication.objects.filter(communication_to=c)[:LIMIT_SHOW]

    # НОВОЕ СООБЩЕНИЕ
    if req.POST:
        if "action" in req.POST:
            if req.POST["action"] == "send" and "text" in req.POST:
                text = req.POST["text"]
                if len(text) == 0:
                    out["textarea_error"] = _(u"введите текст сообщения!")
                else:
                    new_message = MessageCommunication(
                        communication_to=c, text=text, recipient=c.author if c.recipient == req.user else c.recipient
                    )
                    new_message.save()
                    return HttpResponseRedirect("/messages/%s/index.html" % communication_id)

    # ЧТОБЫ БЫЛО ВИДНО КАКОЕ ПРОЧИТАНО КАКОЕ НЕТ :)
    for m in messages_list:
        m.is_new = m.is_read

    out["messages_list"] = messages_list

    # ИДЕМ ПО СПИСКУ НЕ ПРОЧИТАННЫХ И ДЕЛАЕМ ИХ ПРОЧИТАННЫМИ
    for m in MessageCommunication.objects.filter(communication_to=c, is_read=False, recipient=req.user):
        m.is_new = m.is_read
        if m.recipient == req.user and m.is_read == False:
            m.is_read = True
            m.save()
            if c.author == req.user:
                if c.count_mes_a_new > 0:
                    c.count_mes_a_new = c.count_mes_a_new - 1
                    c.save()
            elif c.recipient == req.user:
                if c.count_mes_r_new > 0:
                    c.count_mes_r_new = c.count_mes_r_new - 1
                    c.save()
            else:
                pass

    return render_to_response("messages/list.html", out, context_instance=RequestContext(req))