コード例 #1
0
ファイル: views.py プロジェクト: ugik/Blitz
def user_thread(request, urlkey):
    thread = get_object_or_404(Thread, urlkey=urlkey)

    current_user_threads = UserThread.objects.filter(thread=thread,
                                                     user=request.user)
    if current_user_threads:
        current_user_thread = current_user_threads[0]
    else:
        return redirect('/inbox')


#    current_user_thread = get_object_or_404(UserThread, thread=thread, user=request.user)
    current_user_thread.last_read_date = timezone_now()
    current_user_thread.save()

    if request.method == 'POST':
        form = NewMessageForm(request.POST)
        if form.is_valid():
            message = create_new_message(thread, request.user,
                                         form.cleaned_data['message_content'])
    else:
        form = NewMessageForm()
    # TODO: authX - can user see thread
    user_threads = UserThread.objects.filter(
        user=request.user).order_by('-thread__last_message_date')
    return render(
        request, 'messages/thread.html', {
            'thread': thread,
            'current_user_thread': current_user_thread,
            'user_threads': user_threads,
            'form': form,
        })
コード例 #2
0
ファイル: views.py プロジェクト: romanvlasiuk/MyNetwork
def new_message(request):
    user = User.objects.get(id=request.session["current_user"])
    form = NewMessageForm()
    if request.method == "POST":
        form = NewMessageForm(request.POST)
        if form.is_valid():
            form.save(request.user, user)
            return HttpResponseRedirect("/main/display/")
        else:
            return render(request, "add_message.html", content_creator(request, user, form=form))
    else:
        return render(request, "add_message.html", content_creator(request, user, form=form))
コード例 #3
0
ファイル: views.py プロジェクト: ugik/Blitz
def new_message(request):
    if request.method == 'GET':
        return inbox(request)
    form = NewMessageForm(request.POST)
    if form.is_valid():
        thread = get_thread_for_users(request.user,
                                      form.cleaned_data['to_user'])
        message = create_new_message(thread, request.user,
                                     form.cleaned_data['message_content'])
        return redirect('user_thread', urlkey=thread.urlkey)
    else:
        return redirect('/inbox')
コード例 #4
0
ファイル: Eclectic.py プロジェクト: Cassandra-Fu/electic
def ticket_detail(id):
    if is_authenticated(request):
        user = get_user(request)
        form = NewMessageForm()
        ticket_list = dat_loader.load_data("Tickets")["data"]
        if request.method == "GET":
            count = 0
            for ticket in ticket_list:
                if ticket.get_id() == id:
                    if ticket.get_staff_usr_id() == user.get_id(
                    ) or ticket.created_by.get_id() == user.get_id():
                        return render_template("pages/ticket_detail.html",
                                               ticket=ticket,
                                               user=user,
                                               staff=is_staff(request),
                                               form=form)
                    else:
                        return abort(403)
                else:
                    count += 1
            if count == len(ticket_list):
                return abort(404)
        elif request.method == "POST" and form.validate_on_submit():
            for ticket in ticket_list:
                if ticket.get_id() == int(form.id.data):
                    files = form.files.data
                    uploaded_files = []
                    if files[0].filename != "":
                        for x in files:
                            try:
                                uploaded_files.append(upload(x, False, user))
                            except ValueError:
                                return abort(400)
                        m1 = Message(user, uploaded_files, None)
                    else:
                        m1 = Message(user, [], form.message.data)
                    ticket.add_new_reply(m1)
                    dat_loader.write_data("Tickets", ticket_list, False)
                    return redirect(
                        url_for("ticket_detail", id=ticket.get_id()))
    else:
        return redirect("/login/")
コード例 #5
0
ファイル: views.py プロジェクト: pilamb/simple-django-chat
def newMessageView(request, pk):
    """
    View handling new message.
    TODO: quit from receivers the user who writes. Sorry but time is up.
    """
    sender = User_model.objects.get(pk=pk)
    if request.method == 'POST':
        form = NewMessageForm(request.POST)
        if form.is_valid():
            receiver_id = request.POST['receiver']
            receiver_object = User_model.objects.get(pk=receiver_id)
            receiver_object.notified = True # Notify the user
            receiver_object.seen = False
            receiver_object.save()
            text = request.POST['text']
            message = Message(sender=sender, text=text, receiver=receiver_object)
            message.save()
            return HttpResponseRedirect(reverse('chat' , args=[pk,receiver_id]))
    else:
        form = NewMessageForm(initial={})
    return render(request, 'chat/new_message.html', {'form':form, 'sender':sender})
コード例 #6
0
ファイル: views.py プロジェクト: juliuxu/EscapeDJSystem
def newmessage(request):

    c = {}

    if request.method == 'POST':
        newMessageForm = NewMessageForm(request.POST)
        if newMessageForm.is_valid():
            newMessageForm.save()
            response = alerthtml('alert-success', 'Success!', 'Your message was sent to the DJ')
        else:
            response = alerthtml('alert-error', 'Error!', 'Please fill in all fields!')

        if request.is_ajax():
            return HttpResponse(simplejson.dumps({'html': response}), content_type="application/json")
        else:
            c['newmessage_result'] = response

    c['title'] = 'Send a message to the DJ'

    c['newMessageForm'] = NewMessageForm()
    return render_helper('esc_newmessage.html', c, request)
コード例 #7
0
ファイル: views.py プロジェクト: katajakasa/Raidcal
def thread(request, thread_id):
    # Make sure we are in a valid topic
    topic = get_object_or_404(Topic, pk=thread_id)

    # Handle new message form input
    if request.method == 'POST':
        message_form = NewMessageForm(request.POST)
        if message_form.is_valid():
            message = message_form.save(topic, request.user)
            return HttpResponseRedirect(u'{}#msg_{}'.format(reverse('thread', args=[topic.pk]), message.pk))
    else:
        message_form = NewMessageForm()

    # Get all messages in the thread
    # TODO: Add pagination... maybe ?
    messages = Message.objects.filter(topic=topic)

    return render_to_response('maincal/thread.html', {
        'page': 'forum',
        'topic': topic,
        'messages': messages,
        'message_form': message_form
    }, context_instance=RequestContext(request))