Skip to content
Browse files

Handle ajax requests

  • Loading branch information...
1 parent 04135c2 commit e8f15f7b7a84d698f3cfea4597685b9c32bef5d4 @paltman paltman committed
Showing with 16 additions and 1 deletion.
  1. +16 −1 boxes/views.py
View
17 boxes/views.py
@@ -1,7 +1,11 @@
import datetime
+import json
-from django.http import HttpResponseForbidden
+from django.core.urlresolvers import reverse
+from django.http import HttpResponse, HttpResponseForbidden
from django.shortcuts import redirect
+from django.template import RequestContext
+from django.template.loader import render_to_string
from django.views.decorators.http import require_POST
from boxes.forms import BoxForm
@@ -33,4 +37,15 @@ def box_edit(request, label):
box.save()
else:
form.save()
+
+ if request.is_ajax():
+ data = {
+ "html": render_to_string("boxes/box.html", {
+ "label": label,
+ "form": BoxForm(instance=box, prefix=label),
+ "box": box,
+ "form_action": reverse("box_edit", args=[label])
+ }, context_instance=RequestContext(request))
+ }
+ return HttpResponse(json.dumps(data), mimetype="application/json")
return redirect(next)

0 comments on commit e8f15f7

Please sign in to comment.
Something went wrong with that request. Please try again.