Example #1
0
def add_reply ( request, object_id, type ):
    from django.utils.simplejson import dumps as _j
    if not request.user.is_authenticated ():
        return HttpResponse ( _j ( { 'error_code' : 4 } ), mimetype = 'application/json' )
    try:
        object = meta_get_object ( object_id, type )
    except:
        # object does not exist
        return HttpResponse ( _j ( { 'error_code' : 1 } ), mimetype = 'application/json' )
    form = AddReplyForm ( request.POST )
#    print "!!!!!!!!!!!=)", request.method, request.POST 
    if form.is_valid ():
#        print form.cleaned_data
        if form.cleaned_data [ "body" ].strip ():
            # save new reply
            new_reply        = meta_create_reply ( object, type )
            new_reply.author = request.user
            new_reply.body   = form.cleaned_data [ "body" ]
            new_reply.save ()
            last_page        = get_last_page_num ( object )
            # fetch replies
            return HttpResponse ( _j ( fetch_replies ( object, last_page, type, request ) ), mimetype = 'application/json' )
#    else:
#        print form.errors
    
    return HttpResponse ( _j ( { 'error_code' : 3 } ), mimetype = 'application/json' )
Example #2
0
def get_replies ( request, object_id, type ):
    from django.utils.simplejson import dumps as _j
    try:
        object = meta_get_object ( object_id, type )
    except:
        # object does not exist
        return HttpResponse ( _j ( { 'error_code' : 1 } ), mimetype = 'application/json' )
    try:
        page_num = int ( request.GET [ 'page_num' ] )
        if page_num == 0:
            page_num = get_last_page_num ( object )
    except:
        page_num = get_last_page_num ( object )
    
    # fetch replies
    return HttpResponse ( _j ( fetch_replies ( object, page_num, type, request ) ), mimetype = 'application/json' )