Skip to content

Commit

Permalink
Fix add_response
Browse files Browse the repository at this point in the history
  • Loading branch information
issackelly committed Mar 30, 2011
1 parent e39ecd4 commit 170ef22
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion servee/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VERSION = (0, 6, 0, "a", 1) # following PEP 386
DEV_N = "13"
DEV_N = "14"


# cribbed from pinax
Expand Down
22 changes: 22 additions & 0 deletions servee/frontendadmin/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,28 @@ def __init__(self, *args, **kwargs):
"admin/object_history.html",
]


def response_add(self, request, obj):
"""
Act differently during frontendadmin(ajax) just reload the page.
"""

# in these cases, the redirect is good
if list(set(request.POST.keys()) & set(["_addanother", "_continue"])):
return super(ServeeModelAdmin, self).response_change(request, obj)

# we want to override the default save case in the frontend
ref = request.META.get("HTTP_REFERER")
if ref and (ref.find("/servee/") == -1):
if request.is_ajax():
return HttpResponse("<script type='text/javascript'>window.location.reload(true);</script>")
else:
return HttpResponseRedirect(ref)

# fallback to normal functionality
return super(ServeeModelAdmin, self).response_add(request, obj)


def response_change(self, request, obj):
"""
Act differently during frontendadmin(ajax) just reload the page.
Expand Down

0 comments on commit 170ef22

Please sign in to comment.