Commit 4d19cb51 by Őry Máté Committed by Bach Dániel

dashboard: provide json response for

parent b96a124a
......@@ -490,6 +490,7 @@ class OperationView(RedirectToLoginMixin, DetailView):
template_name = 'dashboard/operate.html'
show_in_toolbar = True
effect = None
wait_for_result = None
def name(self):
......@@ -551,19 +552,37 @@ class OperationView(RedirectToLoginMixin, DetailView):
return super(OperationView, self).get(request, *args, **kwargs)
def get_response_data(self, result, extra=None, **kwargs):
"""Return serializable data to return to agents requesting json
response to POST"""
if extra is None:
extra = {}
extra["success"] = not isinstance(result, Exception)
extra["done"] = result is not None
return extra
def post(self, request, extra=None, *args, **kwargs):
self.object = self.get_object()
if extra is None:
extra = {}
result = None
self.get_op().async(user=request.user, **extra)
except Exception as e:
messages.error(request, _('Could not start operation.'))
result = e
messages.success(request, _('Operation is started.'))
return redirect("%s#activity" % self.object.get_absolute_url())
if "/json" in request.META.get("HTTP_ACCEPT", ""):
data = self.get_response_data(result, post_extra=extra, **kwargs)
return HttpResponse(json.dumps(data),
return redirect("%s#activity" % self.object.get_absolute_url())
def factory(cls, op, icon='cog', effect='info', extra_bases=(), **kwargs):
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment