def render_attrs(attrs, **kwargs): ret = AttributeDict(kwargs) if attrs is not None: ret.update(attrs) return ret.as_html()
def __init__(self, id, source=None, params=(), sortable=None, empty_text=None, attrs=None, template=None, data=None): """Initialize the table. Options that Table supports that affect the data presented are not supported in this subclass. Extra paramters are: :param id: The id of the table in the resulting HTML. You just need to provide something that will be unique in the generated page. :param source: The URL to get json data from. :param params: A tuple of arguments to pass to the get_queryset() method. :param data: The data to base the table on, if any. """ if data is not None: if source is not None or self.source is not None: raise AssertionError( "Do not specify both data and source when building a " "DataTablesTable") self.params = params data_backed_table = True else: data_backed_table = False data = [] if source is not None: self.source = source if template is None: template = 'ajax_table.html' # Even if this is an ajax backed table, we pass data here and patch # the queryset in below because of a bootstrapping issue: we want to # sort the initial queryset, and this is much cleaner if the table has # has its .columns set up which is only done in Table.__init__... super(DataTablesTable, self).__init__(data=data, sortable=sortable, empty_text=empty_text, attrs=attrs, template=template) self._full_length = None if not data_backed_table: self._compute_queryset(params) # We are careful about modifying the attrs here -- if it comes from # class Meta:-type options, we don't want to modify the original # value! if self.attrs: attrs = AttributeDict(self.attrs) else: attrs = AttributeDict() attrs.update({ 'id': id, # Forcing class to display here is a bit specific really. 'class': 'display', }) self.attrs = attrs
def __init__(self, id, source=None, params=(), sortable=None, empty_text=None, attrs=None, template=None, data=None): """Initialize the table. Options that Table supports that affect the data presented are not supported in this subclass. Extra paramters are: :param id: The id of the table in the resulting HTML. You just need to provide something that will be unique in the generated page. :param source: The URL to get json data from. :param params: A tuple of arguments to pass to the get_queryset() method. :param data: The data to base the table on, if any. """ if data is not None: if source is not None or self.source is not None: raise AssertionError( "Do not specify both data and source when building a " "DataTablesTable") self.params = params data_backed_table = True else: data_backed_table = False data = [] if source is not None: self.source = source if template is None: template = 'ajax_table.html' # Even if this is an ajax backed table, we pass data here and patch # the queryset in below because of a bootstrapping issue: we want to # sort the initial queryset, and this is much cleaner if the table has # has its .columns set up which is only done in Table.__init__... super(DataTablesTable, self).__init__( data=data, sortable=sortable, empty_text=empty_text, attrs=attrs, template=template) self._full_length = None if not data_backed_table: self._compute_queryset(params) # We are careful about modifying the attrs here -- if it comes from # class Meta:-type options, we don't want to modify the original # value! if self.attrs: attrs = AttributeDict(self.attrs) else: attrs = AttributeDict() attrs.update({ 'id': id, # Forcing class to display here is a bit specific really. 'class': 'display', }) self.attrs = attrs