Пример #1
0
def response(request, mess_id):
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/welcome/')


    if request.method == 'POST':
        parent = Message.objects.get(id=mess_id)
        messageform = MessageForm(request.POST)
        if messageform.is_valid():
            text = messageform.cleaned_data.get('Text', None)
            mess = Message(User=request.user, Create_date=datetime.datetime.now(), Change_date=datetime.datetime.now(),
                           Text=text, Parent=parent)
            mess.save()
            messages.success(request, _(u'Ответ добавлен'))
    return HttpResponseRedirect(request.META['HTTP_REFERER'])
Пример #2
0
def newquest(request):
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/welcome/')

    if request.method == 'POST':
        link = Links_Tables.objects.get(Src_name="QUESTIONS", Dst_name="MESSAGES")

        messageform = MessageForm(request.POST)
        if messageform.is_valid():
            text = messageform.cleaned_data.get('Text', None)
            mess = Message(User=request.user, Create_date=datetime.datetime.now(), Change_date=datetime.datetime.now(), Text=text)
            mess.save()
            metalink = Metalinks(Link_tables=link, Src_id=None, Dst_id=mess.id)
            metalink.save()
            #messages.success(request, 'Вопрос было добавлено')
    else:
        messageform = MessageForm(None)

    return HttpResponseRedirect(request.META['HTTP_REFERER'])
Пример #3
0
def newmessage(request, src_name, src_id):
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/welcome/')

    if src_id == 0:
        src_id == None

    if request.method == 'POST':
        link = Links_Tables.objects.get(Src_name=src_name.upper(), Dst_name="MESSAGES")
        metalink = Metalinks.objects.filter(Link_tables=link, Src_id=src_id)
        if metalink:
            parent_id = metalink[0].Dst_id
        else:
            parent_id = 0

        messageform = MessageForm(request.POST)
        if messageform.is_valid():
            text = messageform.cleaned_data.get('Text', None)
            if parent_id:
                mess = Message(User=request.user, Create_date=datetime.datetime.now(), Change_date=datetime.datetime.now(), Text=text, Parent_id=parent_id)
                mess.save()
            else:
                mess = Message(User=request.user, Create_date=datetime.datetime.now(), Change_date=datetime.datetime.now(), Text=text)
                mess.save()
                metalink = Metalinks(Link_tables=link, Src_id=src_id, Dst_id=mess.id)
                metalink.save()
            messages.success(request, _(u'Сообщение было добавлено'))
    else:
        messageform = MessageForm(None)
    
    return HttpResponseRedirect(request.META['HTTP_REFERER'])