def render(self, obj=None, media_type=None): """ Renders *obj* using the :attr:`template` specified on the class. """ if obj is None: return '' listobj = obj if not isinstance(listobj, list): listobj = [obj] # create the dlist format with the columns in # given format columns = get_columns(self.view.request) dl = to_dlist(obj, columns) # order the elements with with request tuples # (orderIndex, reverse) sorting = get_sorting(self.view.request) sorteddl = multilistsort(dl, sorting) # # for order in sorting: # dl.sort(key=itemgetter(order[0]), reverse=order[1]) data = JSONRenderer(self.view).render(sorteddl) template = loader.get_template(self.template) context = RequestContext(self.view.request, { 'echo': self.view.request.GET.get('sEcho') or 0, 'request': self.view.request, 'response': self.view.response, 'totalcount': self.view.totalcount, 'maxcount': self.view.maxcount, 'object': listobj, 'data' : data}) return template.render(context)
def test_to_dlist(self): # GIVEN list with one dictionary # WHEN to_dlist is called # THEN list with one sub list is returned self.assertEquals(to_dlist([{'test': 1, 'two': 'foo'}]), [[1,'foo']])
def render(self, obj=None, media_type=None): """ Renders *obj* using the :attr:`template` specified on the class. """ if obj is None: return '' listobj = obj if not isinstance(listobj, list): listobj = [obj] # create the dlist format with the columns in # given format columns = get_columns(self.view.request) dl = to_dlist(obj, columns) # order the elements with with request tuples # (orderIndex, reverse) sorting = get_sorting(self.view.request) sorteddl = multilistsort(dl, sorting) # # for order in sorting: # dl.sort(key=itemgetter(order[0]), reverse=order[1]) data = JSONRenderer(self.view).render(sorteddl) template = loader.get_template(self.template) context = RequestContext( self.view.request, { 'echo': self.view.request.GET.get('sEcho') or 0, 'request': self.view.request, 'response': self.view.response, 'totalcount': self.view.totalcount, 'maxcount': self.view.maxcount, 'object': listobj, 'data': data }) return template.render(context)
def test_to_dlist_with_columns(self): # GIVEN list with one dictionary # WHEN to_dlist is called with columns # THEN list with one sub list is returned self.assertEquals(to_dlist([{'one': 1, 'two': 'foo', 'three': 4}], ['one']), [[1]])
def test_to_dlist_multiple_items(self): # GIVEN list with multi dictionary # WHEN to_dlist is called # THEN list with one sub list is returned self.assertEquals(to_dlist([{'test': 1, 'two': 'foo'}, {'test': 2, 'two': 'bar'}]), [[1,'foo'], [2,'bar']])
def test_to_dlist_with_columns(self): # GIVEN list with one dictionary # WHEN to_dlist is called with columns # THEN list with one sub list is returned self.assertEquals( to_dlist([{ 'one': 1, 'two': 'foo', 'three': 4 }], ['one']), [[1]])
def test_to_dlist_multiple_items(self): # GIVEN list with multi dictionary # WHEN to_dlist is called # THEN list with one sub list is returned self.assertEquals( to_dlist([{ 'test': 1, 'two': 'foo' }, { 'test': 2, 'two': 'bar' }]), [[1, 'foo'], [2, 'bar']])
def test_to_dlist_empty_list(self): # GIVEN empty list # WHEN to_dlist is called # THEN empty list is returned self.assertEquals(to_dlist([]), [])
def test_to_dlist(self): # GIVEN list with one dictionary # WHEN to_dlist is called # THEN list with one sub list is returned self.assertEquals(to_dlist([{'test': 1, 'two': 'foo'}]), [[1, 'foo']])