def json_response(self, model_or_query, strategy=None, status_code=200, status_text='OK', errors=None, context=None): """ Fills in the `webapp2.Response`_ with the contents of the passed model or query serialized using the :py:mod:`restler` library. :param model_or_query: The `Model`_ or `Query`_ to serialize. :param strategy: The :py:class:`~restler.serializers.SerializationStrategy` to use to serialize. :param status_code: The HTTP status code to set in the `webapp2.Response`_. :param status_text: A text description of the status code. :param errors: A dictionary of errors to add to the response. :param context: The context to be used when serializing. :return: The serialized text to be used as the HTTP response data. """ context = self._setup_context(context) data = self._setup_data(model_or_query, status_code, status_text, errors=errors) return restler_json_response(self.response, data, strategy=strategy, status_code=status_code, context=context)
def json_response(self, model_or_query, strategy=None, status_code=200, status_text='OK', errors=None, context=None): context = self._setup_context(context) data = self._setup_data(model_or_query, status_code, status_text, errors=errors) origin = self.request.headers.get('Origin', '') if origin: self.response.headers['Access-Control-Allow-Origin'] = origin else: self.response.headers['Access-Control-Allow-Origin'] = "/".join( self.request.headers.get("Referer", "").split("/")[0:3]) self.response.headers['Access-Control-Allow-Headers'] = "true" self.response.headers['Access-Control-Allow-Credentials'] = "true" return restler_json_response(self.response, data, strategy=strategy, status_code=status_code, context=context)
def json_response(self, model_or_query, strategy=None, status_code=200, status_text='OK', errors=None, context=None): context = self._setup_context(context) data = self._setup_data(model_or_query, status_code, status_text, errors=errors) origin = self.request.headers.get('Origin', '') if origin: self.response.headers['Access-Control-Allow-Origin'] = origin else: self.response.headers['Access-Control-Allow-Origin'] = "/".join(self.request.headers.get("Referer", "").split("/")[0:3]) self.response.headers['Access-Control-Allow-Headers'] = "true" self.response.headers['Access-Control-Allow-Credentials'] = "true" return restler_json_response(self.response, data, strategy=strategy, status_code=status_code, context=context)
def json_response(self, model_or_query, strategy=None, status_code=200, errors=None, context=None): context = self._setup_context(context) data = self._setup_data(model_or_query, errors=errors) return restler_json_response(self.response, data, strategy=strategy, status_code=status_code, context=context)