コード例 #1
0
ファイル: views.py プロジェクト: caminus/caminus
def newTopic(request, forumID=None):
    parentForum = models.Forum.objects.get(id__exact=forumID)
    permitted = False
    postingRights = parentForum.acls.all()
    if len(postingRights) == 0:
        permitted = True
    for group in request.user.groups.all():
        if permitted:
            break
        for acl in postingRights:
            if group == acl.group:
                permitted = True
                break
    if not permitted:
        messages.error(request, "You are not permitted to post in this forum.")
        return HttpResponseRedirect(parentForum.get_absolute_url())
    if request.method == "POST":
        replyForm = forms.ReplyForm(request.POST, prefix="reply")
        topicForm = forms.TopicForm(request.POST, prefix="topic")
    else:
        replyForm = forms.ReplyForm(prefix="reply")
        topicForm = forms.TopicForm(prefix="topic")
    if replyForm.is_valid() and topicForm.is_valid():
        topic = models.Topic()
        topic.title = topicForm.cleaned_data["title"]
        topic.forum = parentForum
        reply = models.Post()
        reply.body = replyForm.cleaned_data["body"]
        reply.user = request.user
        reply.save()
        topic.rootPost = reply
        topic.save()
        messages.info(request, "Posting successful")
        server_broadcast("New forum topic: %s", topic.title)
        return HttpResponseRedirect(reverse("forums.views.post", kwargs={"id": reply.id}))
    return render_to_response(
        "forums/newTopic.html",
        {"forum": parentForum, "replyForm": replyForm, "topicForm": topicForm},
        context_instance=RequestContext(request),
    )