Permalink
Browse files

Render some snippets if ajax

  • Loading branch information...
1 parent 799e760 commit 13f4be9aefb504cd558e5e46c6776dbdd2059392 @paltman paltman committed Feb 12, 2013
Showing with 11 additions and 2 deletions.
  1. +11 −2 dialogos/views.py
View
@@ -4,6 +4,8 @@
from django.views.decorators.http import require_POST
from django.shortcuts import get_object_or_404, redirect
+from django.template import RequestContext
+from django.template.loader import render_to_string
from django.contrib.auth.decorators import login_required
from django.contrib.contenttypes.models import ContentType
@@ -41,13 +43,20 @@ def post_comment(request, content_type_id, object_id, form_class=CommentForm):
if request.is_ajax():
return HttpResponse(json.dumps({
"status": "OK",
- "comment": dehydrate_comment(comment)
+ "comment": dehydrate_comment(comment),
+ "html": render_to_string("dialogos/_comment.html", {
+ "comment": comment
+ }, context_instance=RequestContext(request))
}), mimetype="application/json")
else:
if request.is_ajax():
return HttpResponse(json.dumps({
"status": "ERROR",
- "errors": form.errors
+ "errors": form.errors,
+ "html": render_to_string("dialogos/_form.html", {
+ "form": form,
+ "obj": obj
+ }, context_instance=RequestContext(request))
}), mimetype="application/json")
redirect_to = request.POST.get("next")
# light security check -- make sure redirect_to isn't garbage.

0 comments on commit 13f4be9

Please sign in to comment.