Пример #1
0
def new_post(request,
             forum_id=None,
             topic_id=None,
             form_class=NewPostForm,
             template_name='lbforum/post.html'):
    user = request.user
    if not user.lbforum_profile.nickname:
        return redirect('lbforum_change_profile')
    qpost = topic = forum = first_post = preview = None
    post_type = _('topic')
    topic_post = True
    initial = {}
    if forum_id:
        forum = get_object_or_404(Forum, pk=forum_id)
    if topic_id:
        post_type = _('reply')
        topic_post = False
        topic = get_object_or_404(Topic, pk=topic_id)
        if not topic_can_post(topic, user):
            return HttpResponse(_("you can't reply, this topic closed."))
        forum = topic.forum
        first_post = topic.posts.order_by('created_on').first()
    initial['forum'] = forum
    if request.method == "POST":
        form = form_class(request.POST,
                          user=user,
                          forum=forum,
                          initial=initial,
                          topic=topic,
                          ip=get_client_ip(request))
        preview = request.POST.get('preview', '')
        if form.is_valid() and request.POST.get('submit', ''):
            post = form.save()
            forum = post.topic.forum
            if topic:
                return HttpResponseRedirect(post.get_absolute_url_ext())
            else:
                return HttpResponseRedirect(
                    reverse("lbforum_forum", args=[forum.slug]))
    else:
        qid = request.GET.get('qid', '')
        if qid:
            qpost = get_object_or_404(Post, id=qid)
            initial['message'] = "[quote=%s]%s[/quote]" % (
                qpost.posted_by.lbforum_profile, qpost.message)
        form = form_class(initial=initial, forum=forum)
    ext_ctx = {
        'forum': forum,
        'show_forum_field': topic_post,
        'form': form,
        'topic': topic,
        'first_post': first_post,
        'post_type': post_type,
        'preview': preview
    }
    ext_ctx['attachments'] = user.lbattachment_set.filter(
        pk__in=request.POST.getlist('attachments'))
    ext_ctx['is_new_post'] = True
    ext_ctx['topic_post'] = topic_post
    return render(request, template_name, ext_ctx)
Пример #2
0
def new_post(
        request, forum_id=None, topic_id=None, form_class=NewPostForm,
        template_name='lbforum/post.html'):
    user = request.user
    if not user.lbforum_profile.nickname:
        return redirect('lbforum_change_profile')
    qpost = topic = forum = first_post = preview = None
    post_type = _('topic')
    topic_post = True
    initial = {}
    if forum_id:
        forum = get_object_or_404(Forum, pk=forum_id)
    if topic_id:
        post_type = _('reply')
        topic_post = False
        topic = get_object_or_404(Topic, pk=topic_id)
        if not topic_can_post(topic, user):
            return HttpResponse(_("you can't reply, this topic closed."))
        forum = topic.forum
        first_post = topic.posts.order_by('created_on').first()
    initial['forum'] = forum
    if request.method == "POST":
        form = form_class(
            request.POST, user=user, forum=forum,
            initial=initial,
            topic=topic, ip=get_client_ip(request))
        preview = request.POST.get('preview', '')
        if form.is_valid() and request.POST.get('submit', ''):
            post = form.save()
            forum = post.topic.forum
            if topic:
                return HttpResponseRedirect(post.get_absolute_url_ext())
            else:
                return HttpResponseRedirect(reverse("lbforum_forum",
                                                    args=[forum.slug]))
    else:
        qid = request.GET.get('qid', '')
        if qid:
            qpost = get_object_or_404(Post, id=qid)
            initial['message'] = "[quote=%s]%s[/quote]" % (
                qpost.posted_by.lbforum_profile, qpost.message)
        form = form_class(initial=initial, forum=forum)
    ext_ctx = {
        'forum': forum,
        'show_forum_field': topic_post,
        'form': form,
        'topic': topic,
        'first_post': first_post,
        'post_type': post_type,
        'preview': preview
    }
    ext_ctx['attachments'] = user.lbattachment_set.filter(
        pk__in=request.POST.getlist('attachments'))
    ext_ctx['is_new_post'] = True
    ext_ctx['topic_post'] = topic_post
    return render(request, template_name, ext_ctx)
Пример #3
0
def new_chat_post(request,
                  user_id=None,
                  forum_id=None,
                  topic_id=None,
                  form_class=NewPostForm,
                  template_name='lbforum/post.html'):

    user = request.user

    if user_id:
        profile = LBForumUserProfile.objects.get(id=user.id)
        chat_list = profile.get_chat_list()
        print(chat_list)
        print(user_id)
        print(type(user_id))
        if user_id in chat_list.keys():
            return HttpResponseRedirect(
                reverse("lbforum_chat", args=[chat_list[user_id]]))

    if not user.lbforum_profile.nickname:
        return redirect('lbforum_change_profile')
    qpost = topic = forum = first_post = preview = None
    post_type = _('topic')
    topic_post = True
    initial = {}
    forum = Forum.objects.get(id=1)
    if forum_id:
        forum = get_object_or_404(Forum, pk=forum_id)
    if topic_id:
        print(topic_id)
        print("ASDASD")
        post_type = _('reply')
        topic_post = False
        topic = get_object_or_404(Topic, pk=topic_id)
        if not topic_can_post(topic, user):
            return HttpResponse(_("you can't reply, this topic closed."))
        forum = topic.forum
        first_post = topic.posts.order_by('created_on').first()
    initial['forum'] = forum
    if request.method == "POST":
        form = form_class(request.POST,
                          user=user,
                          forum=forum,
                          initial=initial,
                          topic=topic,
                          ip=get_client_ip(request))
        preview = request.POST.get('preview', '')
        print(form.is_bound)
        print(form.errors)
        print(form.is_valid())
        print("asdasd")
        if form.is_valid() and request.POST.get('submit', ''):
            post = form.save()
            forum = post.topic.forum
            if topic:
                return HttpResponseRedirect(
                    post.get_absolute_url_ext().replace("topic", "chat"))
            else:
                return HttpResponseRedirect(
                    reverse("lbforum_forum", args=[forum.slug]))
    else:
        topic = Topic(forum=forum,
                      posted_by=user,
                      subject="chat",
                      need_replay=False,
                      need_reply_attachments=False,
                      topic_type=TopicType.objects.get(name="test"),
                      owns1=user_id,
                      owns2=user.id,
                      is_chat=True)
        topic_post = True
        topic.save()
        profile1 = LBForumUserProfile.objects.get(id=user.id)
        profile2 = LBForumUserProfile.objects.get(id=user_id)
        profile1.add_chat(user_id, topic.id)
        profile2.add_chat(user.id, topic.id)
        posts = get_all_posts(user)
        posts = posts.filter(topic=topic)
        posts = posts.filter(topic_post=False)
        posts = posts.order_by('created_on')
        ext_ctx = {
            'request': request,
            'topic': topic,
            'posts': posts,
            'has_replied': topic.has_replied(request.user),
            'can_admin': topic.forum.is_admin(user)
        }
        return HttpResponseRedirect(reverse("lbforum_chat", args=[topic.id]))