Пример #1
0
def reply_topic(request, cat, topic):
    """save new reply

    :param request: object contain context of request
    :type request: object
    :param cat: slug of categorie
    :type cat: slug
    :var topic: topic slug
    :type topic: slug
    :var form: form for topic reply
    :var top: get the new topic
    :return: HTTPResponse
    """
    logger_info.info(info_load_log_message(request))
    form = PostForm(request.POST)
    top = models.ForumTopic.objects.get(slug=topic)
    if form.is_valid():
        models.ForumPost(TopicParent=top, Autor=request.user, Message=form.cleaned_data["Message"]).save()
        models.ForumTopic.objects.filter(slug=topic).update(LastReply=timezone.now())
        return redirect(request.META["HTTP_REFERER"], permanent=True)
    else:
        if top.CatParent:
            return redirect(reverse("topic_cat", kwargs={"cat": cat.slug, "topic": topic.slug}), permanent=True)
        else:
            return display_all(request)
Пример #2
0
def edit_post(request, cat, topic, post):
    """display process for edit post

    :param request: object contain context of request
    :type request: object
    :param cat: slug of categorie
    :type cat: slug
    :var topic: topic slug
    :type topic: slug
    :var errors: dict of process error
    :var cat: select cat by slug
    :var form: form for edit post
    :var update: select post to update and update him
    :var post_sel: get the post
    :var context: define the context for display topic
    :return: HTTPResponse
    """
    error = {}
    logger_info.info(info_load_log_message(request))
    cat = models.ForumCat.objects.get(slug=cat)
    if request.POST:
        form = PostForm(request.POST)
        if request.POST["Message"] is not None and form.is_valid():
            try:
                update = models.ForumPost.objects.filter(pk=post).update(
                    Message=form.cleaned_data["Message"], LastModified=timezone.now()
                )
                if update is not None:
                    return redirect(reverse("topic_cat", kwargs={"cat": cat.slug, "topic": topic}), permanent=True)
            except:
                return display_topic(request, cat, topic)
        else:
            post_sel = models.ForumPost.objects.get(pk=post)
            error["Message"] = _("post_must_contain_message")
    else:
        post_sel = models.ForumPost.objects.get(pk=post)
    return render(
        request,
        "forum/edit_post.html",
        {"cat": cat, "topic": topic, "post": post, "error": error, "form": PostForm({"Message": post_sel.Message})},
    )