Example #1
0
def new_post(request, forum_id):
    
    member = request.user.get_profile()
    forum = get_object_or_404(Forum, id=forum_id)
    
    if request.method == "POST":
        
        title = request.POST.get("title")
        content = request.POST.get("content")
        subscribe = {"true": True, "false": False, False: False}.get(request.POST.get("subscribe", False), True)
        
        thread = ForumThread(forum=forum, title=title, content=content, author=request.user)
        thread.save()
        
        # subscribe the poster to the thread if requested (default value is True)
        if subscribe:
            thread.subscribe(thread.author, "email")
        
        # all users are automatically subscribed to onsite
        thread.subscribe(thread.author, "onsite")
        
        return HttpResponseRedirect(reverse("agora_thread", args=[thread.id]))
    
    return render_to_response("agora/new_post.html", {
        "member": member,
        "forum_id": forum_id,
    }, context_instance=RequestContext(request))
Example #2
0
 def restore(cls, in_):
     data = json.load(open(in_))
     forum = Forum(**dict(id=data["self"]["id"],
                          title=data["self"]["title"],
                          description=data["self"]["description"],
                          parent_id=data["self"]["parent"],
                          category_id=data["self"]["category"],
                          last_modified=data["self"]["last_modified"],
                          view_count=data["self"]["view_count"],
                          post_count=data["self"]["post_count"]))
     forum._importing = True
     forum.save()
     for thread_data in data["threads"]:
         thread = ForumThread(
             **dict(id=thread_data["id"],
                    author_id=thread_data["author"],
                    content=thread_data["content"],
                    created=thread_data["created"],
                    forum_id=thread_data["forum"],
                    title=thread_data["title"],
                    last_modified=thread_data["last_modified"],
                    view_count=thread_data["view_count"],
                    reply_count=thread_data["reply_count"],
                    subscriber_count=thread_data["subscriber_count"]))
         thread._importing = True
         thread.save()
         for reply_data in thread_data["replies"]:
             reply = ForumReply(**dict(
                 id=reply_data["id"],
                 author_id=reply_data["author"],
                 content=reply_data["content"],
                 created=reply_data["created"],
                 thread_id=reply_data["thread"],
             ))
             reply._importing = True
             reply.save()
         for subscriber_data in thread_data["subscriptions"]:
             ThreadSubscription(**dict(
                 id=subscriber_data["id"],
                 user_id=subscriber_data["user"],
                 thread_id=subscriber_data["thread"],
                 kind=subscriber_data["kind"],
             )).save()
         thread.last_reply_id = thread_data["last_reply"]
         thread.save()
     forum.last_thread_id = data["self"]["last_thread"]
     forum.save()
Example #3
0
 def restore(cls, in_):
     data = json.load(open(in_))
     forum = Forum(**dict(
         id=data["self"]["id"],
         title=data["self"]["title"],
         description=data["self"]["description"],
         parent_id=data["self"]["parent"],
         category_id=data["self"]["category"],
         last_modified=data["self"]["last_modified"],
         view_count=data["self"]["view_count"],
         post_count=data["self"]["post_count"]
     ))
     forum._importing = True
     forum.save()
     for thread_data in data["threads"]:
         thread = ForumThread(**dict(
             id=thread_data["id"],
             author_id=thread_data["author"],
             content=thread_data["content"],
             created=thread_data["created"],
             forum_id=thread_data["forum"],
             title=thread_data["title"],
             last_modified=thread_data["last_modified"],
             view_count=thread_data["view_count"],
             reply_count=thread_data["reply_count"],
             subscriber_count=thread_data["subscriber_count"]
         ))
         thread._importing = True
         thread.save()
         for reply_data in thread_data["replies"]:
             reply = ForumReply(**dict(
                 id=reply_data["id"],
                 author_id=reply_data["author"],
                 content=reply_data["content"],
                 created=reply_data["created"],
                 thread_id=reply_data["thread"],
             ))
             reply._importing = True
             reply.save()
         for subscriber_data in thread_data["subscriptions"]:
             ThreadSubscription(**dict(
                 id=subscriber_data["id"],
                 user_id=subscriber_data["user"],
                 thread_id=subscriber_data["thread"],
                 kind=subscriber_data["kind"],
             )).save()
         thread.last_reply_id = thread_data["last_reply"]
         thread.save()
     forum.last_thread_id = data["self"]["last_thread"]
     forum.save()