Beispiel #1
0
 def get_help_text(self):
     extra = {}
     try:
         extra["usages"] = api.nova.tenant_quota_usages(self.request)
         extra["usages_json"] = jsonutils.dumps(extra["usages"])
         flavors = jsonutils.dumps([f._info for f in api.nova.flavor_list(self.request)])
         extra["flavors"] = flavors
     except:
         exceptions.handle(self.request, _("Unable to retrieve quota information."))
     return super(SetInstanceDetailsAction, self).get_help_text(extra)
Beispiel #2
0
 def get_help_text(self):
     extra = {}
     try:
         extra['usages'] = api.nova.tenant_quota_usages(self.request)
         extra['usages_json'] = jsonutils.dumps(extra['usages'])
         flavors = jsonutils.dumps(
             [f._info for f in api.nova.flavor_list(self.request)])
         extra['flavors'] = flavors
     except:
         exceptions.handle(self.request)
     return super(SetInstanceDetailsAction, self).get_help_text(extra)
Beispiel #3
0
 def get_help_text(self):
     extra = {}
     try:
         extra['usages'] = api.nova.tenant_quota_usages(self.request)
         extra['usages_json'] = jsonutils.dumps(extra['usages'])
         flavors = jsonutils.dumps([f._info for f in
                                    api.nova.flavor_list(self.request)])
         extra['flavors'] = flavors
     except:
         exceptions.handle(self.request)
     return super(SetInstanceDetailsAction, self).get_help_text(extra)
Beispiel #4
0
    def form_valid(self, form):
        try:
            handled = form.handle(self.request, form.cleaned_data)
        except:
            handled = None
            exceptions.handle(self.request)

        if handled:
            if ADD_TO_FIELD_HEADER in self.request.META:
                field_id = self.request.META[ADD_TO_FIELD_HEADER]
                data = [self.get_object_id(handled),
                        self.get_object_display(handled)]
                response = http.HttpResponse(jsonutils.dumps(data))
                response["X-Horizon-Add-To-Field"] = field_id
            else:
                success_url = self.get_success_url()
                response = http.HttpResponseRedirect(success_url)
                # TODO(gabriel): This is not a long-term solution to how
                # AJAX should be handled, but it's an expedient solution
                # until the blueprint for AJAX handling is architected
                # and implemented.
                response['X-Horizon-Location'] = success_url
            return response
        else:
            # If handled didn't return, we can assume something went
            # wrong, and we should send back the form as-is.
            return self.form_invalid(form)
Beispiel #5
0
    def form_valid(self, form):
        try:
            handled = form.handle(self.request, form.cleaned_data)
        except:
            handled = None
            exceptions.handle(self.request)

        if handled:
            if ADD_TO_FIELD_HEADER in self.request.META:
                field_id = self.request.META[ADD_TO_FIELD_HEADER]
                data = [
                    self.get_object_id(handled),
                    self.get_object_display(handled)
                ]
                response = http.HttpResponse(jsonutils.dumps(data))
                response["X-Horizon-Add-To-Field"] = field_id
            else:
                success_url = self.get_success_url()
                response = http.HttpResponseRedirect(success_url)
                # TODO(gabriel): This is not a long-term solution to how
                # AJAX should be handled, but it's an expedient solution
                # until the blueprint for AJAX handling is architected
                # and implemented.
                response['X-Horizon-Location'] = success_url
            return response
        else:
            # If handled didn't return, we can assume something went
            # wrong, and we should send back the form as-is.
            return self.form_invalid(form)
Beispiel #6
0
    def process_response(self, request, response):
        """
        Convert HttpResponseRedirect to HttpResponse if request is via ajax
        to allow ajax request to redirect url
        """
        #if request.is_ajax():
        if request.is_ajax() and request.GET.get('query') is None and request.POST.get('query') is None:
	    queued_msgs = request.horizon['async_messages']
            if type(response) == http.HttpResponseRedirect:
                # Drop our messages back into the session as per usual so they
                # don't disappear during the redirect. Not that we explicitly
                # use django's messages methods here.
                for tag, message in queued_msgs:
                    getattr(django_messages, tag)(request, message)
                redirect_response = http.HttpResponse()
                redirect_response['X-Horizon-Location'] = response['location']
                return redirect_response
            if queued_msgs:
               	# TODO(gabriel): When we have an async connection to the
	        # client (e.g. websockets) this should be pushed to the
                # socket queue rather than being sent via a header.
               	# The header method has notable drawbacks (length limits,
	        # etc.) and is not meant as a long-term solution.
                response['X-Horizon-Messages'] = jsonutils.dumps(queued_msgs)
        return response
Beispiel #7
0
    def post(self, request, *args, **kwargs):
        """ Handler for HTTP POST requests. """
        context = self.get_context_data(**kwargs)
        workflow = context[self.context_object_name]
        if workflow.is_valid():
            try:
                success = workflow.finalize()
            except:
                success = False
                exceptions.handle(request)
            next = self.request.REQUEST.get(workflow.redirect_param_name, None)
            if success:
                msg = workflow.format_status_message(workflow.success_message)
                messages.success(request, msg)
            else:
                msg = workflow.format_status_message(workflow.failure_message)
                messages.error(request, msg)

            if "HTTP_X_HORIZON_ADD_TO_FIELD" in self.request.META:
                field_id = self.request.META["HTTP_X_HORIZON_ADD_TO_FIELD"]
                data = [self.get_object_id(workflow.object),
                        self.get_object_display(workflow.object)]
                response = http.HttpResponse(jsonutils.dumps(data))
                response["X-Horizon-Add-To-Field"] = field_id
                return response
            else:
                return shortcuts.redirect(next or workflow.get_success_url())
        else:
            return self.render_to_response(context)
Beispiel #8
0
    def post(self, request, *args, **kwargs):
        """ Handler for HTTP POST requests. """
        context = self.get_context_data(**kwargs)
        workflow = context[self.context_object_name]
        if workflow.is_valid():
            try:
                success = workflow.finalize()
            except:
                success = False
                exceptions.handle(request)
            next = self.request.REQUEST.get(workflow.redirect_param_name, None)
            if success:
                msg = workflow.format_status_message(workflow.success_message)
                messages.success(request, msg)
            else:
                msg = workflow.format_status_message(workflow.failure_message)
                messages.error(request, msg)

            if "HTTP_X_HORIZON_ADD_TO_FIELD" in self.request.META:
                field_id = self.request.META["HTTP_X_HORIZON_ADD_TO_FIELD"]
                data = [
                    self.get_object_id(workflow.object),
                    self.get_object_display(workflow.object)
                ]
                response = http.HttpResponse(jsonutils.dumps(data))
                response["X-Horizon-Add-To-Field"] = field_id
                return response
            else:
                return shortcuts.redirect(next or workflow.get_success_url())
        else:
            return self.render_to_response(context)
Beispiel #9
0
 def get_help_text(self):
     extra = {}
     try:
         flavors = jsonutils.dumps([f._info for f in
                                    api.nova.flavor_list(self.request)])
         extra['flavors'] = flavors
     except:
         exceptions.handle(self.request,
                           _("Unable to retrieve quota information."))
     return super(ResizeInstanceDetailsAction, self).get_help_text(extra)
Beispiel #10
0
 def test_middleware_header(self):
     req = self.request
     expected = ["error", "Giant ants are attacking San Francisco!"]
     self.assertTrue("async_messages" in req.horizon)
     self.assertItemsEqual(req.horizon['async_messages'], [])
     req.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
     messages.error(req, expected[1])
     self.assertItemsEqual(req.horizon['async_messages'], [expected])
     res = http.HttpResponse()
     res = middleware.HorizonMiddleware().process_response(req, res)
     self.assertEqual(res['X-Horizon-Messages'],
                      jsonutils.dumps([expected]))
Beispiel #11
0
 def process_response(self, request, response):
     """
     Convert HttpResponseRedirect to HttpResponse if request is via ajax
     to allow ajax request to redirect url
     """
     if request.is_ajax():
         if type(response) == http.HttpResponseRedirect:
             redirect_response = http.HttpResponse()
             redirect_response['X-Horizon-Location'] = response['location']
             return redirect_response
         if request.horizon['async_messages']:
             messages = request.horizon['async_messages']
             # TODO(gabriel): When we have an async connection to the
             # client (e.g. websockets) this should be pushed to the
             # socket queue rather than being sent via a header.
             # The header method has notable drawbacks (length limits,
             # etc.) and is not meant as a long-term solution.
             response['X-Horizon-Messages'] = jsonutils.dumps(messages)
     return response
Beispiel #12
0
 def process_response(self, request, response):
     """
     Convert HttpResponseRedirect to HttpResponse if request is via ajax
     to allow ajax request to redirect url
     """
     if request.is_ajax():
         if type(response) == http.HttpResponseRedirect:
             redirect_response = http.HttpResponse()
             redirect_response['X-Horizon-Location'] = response['location']
             return redirect_response
         if request.horizon['async_messages']:
             messages = request.horizon['async_messages']
             # TODO(gabriel): When we have an async connection to the
             # client (e.g. websockets) this should be pushed to the
             # socket queue rather than being sent via a header.
             # The header method has notable drawbacks (length limits,
             # etc.) and is not meant as a long-term solution.
             response['X-Horizon-Messages'] = jsonutils.dumps(messages)
     return response
Beispiel #13
0
 def process_response(self, request, response):
     """
     Convert HttpResponseRedirect to HttpResponse if request is via ajax
     to allow ajax request to redirect url
     """
     if request.is_ajax():
         queued_msgs = request.horizon['async_messages']
         if type(response) == http.HttpResponseRedirect:
             # Drop our messages back into the session as per usual so they
             # don't disappear during the redirect. Not that we explicitly
             # use django's messages methods here.
             for tag, message in queued_msgs:
                 getattr(django_messages, tag)(request, message)
             redirect_response = http.HttpResponse()
             redirect_response['X-Horizon-Location'] = response['location']
             return redirect_response
         if queued_msgs:
             # TODO(gabriel): When we have an async connection to the
             # client (e.g. websockets) this should be pushed to the
             # socket queue rather than being sent via a header.
             # The header method has notable drawbacks (length limits,
             # etc.) and is not meant as a long-term solution.
             response['X-Horizon-Messages'] = jsonutils.dumps(queued_msgs)
     return response