Example #1
0
 def render(self, request=None, **kwargs):
     '''Serialize ``self`` as a ``JSON`` string'''
     elem = maybe_async(self.serialize(request))
     if is_async(elem):
         return elem.add_callback(self.dump)
     else:
         return self.dump(elem)
Example #2
0
    def render(self, request=None, context=None):
        '''Render the widget. It accept two optional parameters, a http
request object and a dictionary for rendering children with a key.

:parameter request: Optional request object.
:parameter request: Optional context dictionary.
'''
        return maybe_async(StreamRenderer(self.stream(request, context)))
Example #3
0
 def render(self, request, **context):
     '''Default render method for this application.'''
     if 'query' not in context:
         context['query'] = self.query(request)
     return maybe_async(
                 StreamRenderer(
                     context,
                     renderer=lambda r: self.render_query(request, **r)))
Example #4
0
    def add_to_widget(self, widget, element, position=None):
        '''Called by *widget* to add a new *element* to its data stream.
 By default it simply append *element* to the :attr:`Widget.data_stream`
 attribute. It can be overwritten but call super for consistency.'''
        element = maybe_async(element)
        if element is not None:
            if isinstance(element, Widget):
                element.internal['parent'] = widget
            if position is not None:
                widget._data_stream.insert(position, element)
            else:
                widget._data_stream.append(element)