예제 #1
0
def sample_object_view_model():
    return Model(
        format='json',
        data=SampleClass(),
        renderer_args={'mapping': {
            SampleClass: {
                'attributes': ('name', )
            }
        }})
예제 #2
0
def sample_view_model():
    return Model(
        format='html',
        template=None,
        data={"test": {
            "nodes": {
                "node": ["Testing", "Another node"]
            }
        }})
예제 #3
0
 def get_returned_controller_data(self, controller, event):
     context = event.params['context']
     route_match = context['route_match']
     try:
         execute_params = route_match.params
         model_data = controller.execute(**execute_params)
         if model_data is None:
             raise InternalServerError(
                 'The controller {0} did not return any data.'.format(
                     controller))
         if isinstance(model_data, controllers.ACCEPTABLE_RETURN_TYPES):
             model_data = {'content': model_data}
         elif isinstance(model_data, Response):
             # Short circuited, skip any templating
             controller.response = context['response'] = model_data
             return model_data, model_data
         path = controller.get_execute_method_path(**route_match.params)
         controller_template = os.path.join(*path)
         view_template = self.templates.get(controller_template,
                                            controller_template)
         format = route_match.params.get('format', 'html')
         if isinstance(model_data, Model):
             if not model_data.template:
                 model_data.template = view_template
             else:
                 overridden_template = path[:-1] + [model_data.template]
                 model_data.template = os.path.join(*overridden_template)
             if not model_data.format:
                 model_data.format = format
             view_model = model_data
         else:
             view_model = Model(format=format,
                                template=view_template,
                                data=model_data)
         context['response'] = controller.response
         return controller.response, view_model
     except (ApplicationError, NotFoundError, InternalServerError) as exc:
         raise
     except Exception as exc:
         raise InternalServerError(
             'An error occurred executing controller: {0}'.format(
                 get_qualified_name(controller))) from exc
예제 #4
0
 def convert_to_view_model(self, exception, exc_data):
     str_status_code = str(exception.status_code)
     return Model(format=exception.format,
                  template=self.templates.get(
                      str_status_code, self.templates[str_status_code]),
                  data=exc_data)
예제 #5
0
 def view_model_template_action(self, **kwargs):
     return Model(data='test', template='404')
예제 #6
0
 def view_model_action(self, **kwargs):
     return Model(data='test')