def _get_api_data(cls, req, handler_function_name):
        # Input argument `handler_function_name` must be one of defined in
        # settings.
        meta_name = '{}_data'.format(handler_function_name)
        if meta_name not in req.META:
            # Get and initialize handler.
            handler_class, model_class = get_page_lock_classes()
            lock_handler = handler_class(req, model_class)

            # Get and run handler function to get response data.
            handler_function = getattr(lock_handler, handler_function_name)
            req.META[meta_name] = handler_function(req)

        return req.META[meta_name]
Ejemplo n.º 2
0
    def post(self, req, *args, **kwargs):
        # Get and initialize handler.
        # TODO(vstefka) type of handler can depend on current page as well.
        try:
            # Get and initialize handler.
            handler_class, model_class = get_page_lock_classes()
            handler = handler_class(req, model_class)

            # Get and run handler function to get response data.
            handler_function = getattr(handler, self.HANDLER_FUNCTION)
            response_data = handler_function(req, *args, **kwargs)
        except Exception:
            logging.error(traceback.format_exc())
            return HttpResponseServerError(_('Some error occured.'))

        response = HttpResponse(json.dumps(response_data),
                                content_type='application/json')

        return response
Ejemplo n.º 3
0
    def post(self, req, *args, **kwargs):
        # Get and initialize handler.
        # TODO(vstefka) type of handler can depend on current page as well.
        try:
            # Get and initialize handler.
            handler_class, model_class = get_page_lock_classes()
            handler = handler_class(req, model_class)

            # Get and run handler function to get response data.
            handler_function = getattr(handler, self.HANDLER_FUNCTION)
            response_data = handler_function(req, *args, **kwargs)
        except Exception as e:
            # Propagate error to django in order to be able to log it.
            raise e

        response = HttpResponse(json.dumps(response_data),
                                content_type='application/json')

        return response