def render(self, result, mimetype, errors=None):
        """
        Render a model result into `mimetype` format.
        """
        available_mimetypes = [x for x in self.render_map.keys() if '/' in x]
        render_func = None

        if '/' not in mimetype:
            # naked superformat (does not correspond to a mimetype)
            render_func = self.reject_map.get(mimetype, None)
            if not render_func:
                raise NoViewMethod("Unknown Superformat: %s" % mimetype)

        if not render_func and available_mimetypes:
            target_mimetype = mimeparse.best_match(available_mimetypes, mimetype)
            render_func = self.render_map.get(target_mimetype, None)

        if not render_func:
            raise NoViewMethod("%s not supported for this program" % mimetype)

        principle_mimetype = render_func.mimetypes[0]

        if GiottoControl in render_func.__class__.mro():
            # redirection defined as view (not wrapped in lambda)
            return {'body': render_func, 'persist': render_func.persist}

        if callable(self.persist):
            # persist (cookie data) can be either an object, or a callable)
            persist = self.persist(result)
        else:
            persist = self.persist

        # render functins can take either one or two arguments, both are
        # supported by the API
        arg_names = inspect.getargspec(render_func).args
        num_args = len(set(arg_names) - set(['self', 'cls']))
        if num_args == 2:
            data = render_func(result, errors or Mock())
        else:
            # if the renderer only has one argument, don't pass in the 2nd arg.
            data = render_func(result)

        if GiottoControl in data.__class__.mro():
            # render function returned a control object
            return {'body': data, 'persist': persist}

        if not hasattr(data, 'items'):
            # view returned string
            data = {'body': data, 'mimetype': principle_mimetype}
        else:
            # result is a dict in for form {body: XX, mimetype: xx}
            if not 'mimetype' in data and target_mimetype == '*/*':
                data['mimetype'] = ''

            if not 'mimetype' in data:
                data['mimetype'] = target_mimetype

        data['persist'] = persist
        return data
def render ( self , result , mimetype , errors = None ) : available_mimetypes = [ x for x in self . render_map . keys ( ) if '/' in x ] render_func = None if '/' not in mimetype : render_func = self . reject_map . get ( mimetype , None ) if not render_func : raise NoViewMethod ( "Unknown Superformat: %s" % mimetype ) if not render_func and available_mimetypes : target_mimetype = mimeparse . best_match ( available_mimetypes , mimetype ) render_func = self . render_map . get ( target_mimetype , None ) if not render_func : raise NoViewMethod ( "%s not supported for this program" % mimetype ) principle_mimetype = render_func . mimetypes [ 0 ] if GiottoControl in render_func . __class__ . mro ( ) : return { 'body' : render_func , 'persist' : render_func . persist } if callable ( self . persist ) : persist = self . persist ( result ) else : persist = self . persist arg_names = inspect . getargspec ( render_func ) . args num_args = len ( set ( arg_names ) - set ( [ 'self' , 'cls' ] ) ) if num_args == 2 : data = render_func ( result , errors or Mock ( ) ) else : data = render_func ( result ) if GiottoControl in data . __class__ . mro ( ) : return { 'body' : data , 'persist' : persist } if not hasattr ( data , 'items' ) : data = { 'body' : data , 'mimetype' : principle_mimetype } else : if not 'mimetype' in data and target_mimetype == '*/*' : data [ 'mimetype' ] = '' if not 'mimetype' in data : data [ 'mimetype' ] = target_mimetype data [ 'persist' ] = persist return data
Render a model result into `mimetype` format.