(request, uid)
Edit post content using ajax.
Edit post content using ajax.
Edit post content using ajax .
def ajax_edit(request, uid):
    """
    Edit post content using ajax.
    """

    post = Post.objects.filter(uid=uid).first()
    user = request.user
    can_edit = (user.profile.is_moderator or user == post.author)

    if not post:
        return ajax_error(msg="Post does not exist")

    if not can_edit:
        return ajax_error(msg="Only moderators or the author can edit posts.")

    # Get the fields found in the request
    fields = get_fields(request=request, post=post)

    # Pick the form
    if post.is_toplevel:
        form = forms.PostLongForm(post=post, user=user, data=fields)
    else:
        form = forms.PostShortForm(post=post, user=user, data=fields)

    if form.is_valid():
        form.edit()
        return ajax_success(msg='Edited post', redirect=post.get_absolute_url())
    else:
        msg = [field.errors for field in form if field.errors]
        return ajax_error(msg=msg)
def ajax_edit ( request , uid ) : post = Post . objects . filter ( uid = uid ) . first ( ) user = request . user can_edit = ( user . profile . is_moderator or user == post . author ) if not post : return ajax_error ( msg = "Post does not exist" ) if not can_edit : return ajax_error ( msg = "Only moderators or the author can edit posts." ) # Get the fields found in the request fields = get_fields ( request = request , post = post ) # Pick the form if post . is_toplevel : form = forms . PostLongForm ( post = post , user = user , data = fields ) else : form = forms . PostShortForm ( post = post , user = user , data = fields ) if form . is_valid ( ) : form . edit ( ) return ajax_success ( msg = 'Edited post' , redirect = post . get_absolute_url ( ) ) else : msg = [ field . errors for field in form if field . errors ] return ajax_error ( msg = msg )