def handle_ajax(self, request):
     params = {}
     for name, value in request.GET.items():
         try:
             params[name] = hungarian_to_python(name, value)
         except NameError:
             pass
     qs = self.get_queryset()
     iTotalRecords = qs.count()
     qs = self._handle_ajax_sorting(qs, params)
     qs = self._handle_ajax_global_search(qs, params)
     qs = self._handle_ajax_column_specific_search(qs, params)
     iTotalDisplayRecords = qs.count()
     iDisplayStart = params.get('iDisplayStart', 0)
     iDisplayLength = params.get('iDisplayLength', -1)
     if iDisplayLength < 0:
         iDisplayLength = iTotalDisplayRecords
     qs = qs[iDisplayStart:(iDisplayStart + iDisplayLength)]
     aaData = []
     for result in qs:
         aData = []
         for bcol in self.bound_columns.values():
             aData.append(bcol.render_value(result, include_hidden=False))
         aaData.append(aData)
     data = {
         'iTotalRecords': iTotalRecords,
         'iTotalDisplayRecords': iTotalDisplayRecords,
         'sEcho': params.get('sEcho', ''),
         #'sColumns': ,
         'aaData': aaData,
     }
     #print qs.query
     s = dumpjs(data)
     return HttpResponse(s, content_type='application/json')
 def js_options(self):
     options = deepcopy(self._meta.options)
     columns = self.bound_columns
     aoColumnDefs = options.setdefault('aoColumnDefs', [])
     colopts = SortedDict()
     for index, name in enumerate(columns.keys()):
         column = columns[name]
         for key, value in column.options.items():
             if not (key, str(value)) in colopts.keys():
                 colopts[(key, str(value))] = {}
                 colopts[(key, str(value))]['targets'] = []
             colopts[(key, str(value))]['targets'] = colopts[(key, str(value))]['targets'] + [index]
             colopts[(key, str(value))]['key'] = key
             colopts[(key, str(value))]['value'] = value
         if column.sort_field != column.display_field and column.sort_field in columns:
             key = 'iDataSort'
             value = columns.keys().index(column.sort_field)
             if not (key, str(value)) in colopts.keys():
                 colopts[(key, str(value))] = {}
                 colopts[(key, str(value))]['targets'] = []
             colopts[(key, str(value))]['targets'] = colopts[(key, str(value))]['targets'] + [index]
             colopts[(key, str(value))]['key'] = key
             colopts[(key, str(value))]['value'] = value
     for kv, values in colopts.items():
         aoColumnDefs.append(dict([(values['key'], values['value']), ('aTargets', values['targets'])]))
     options['sAjaxSource'] = reverse_ajax_source(options.get('sAjaxSource'))
     return mark_safe(dumpjs(options, indent=4, sort_keys=True))
 def js_options(self):
     options = deepcopy(self._meta.options)
     columns = self.bound_columns
     aoColumnDefs = options.setdefault('aoColumnDefs', [])
     colopts = SortedDict()
     for index, name in enumerate(columns.keys()):
         column = columns[name]
         for key, value in column.options.items():
             if not (key, str(value)) in colopts.keys():
                 colopts[(key, str(value))] = {}
                 colopts[(key, str(value))]['targets'] = []
             colopts[(key, str(value))]['targets'] = colopts[
                 (key, str(value))]['targets'] + [index]
             colopts[(key, str(value))]['key'] = key
             colopts[(key, str(value))]['value'] = value
         if column.sort_field != column.display_field and column.sort_field in columns:
             key = 'iDataSort'
             value = columns.keys().index(column.sort_field)
             if not (key, str(value)) in colopts.keys():
                 colopts[(key, str(value))] = {}
                 colopts[(key, str(value))]['targets'] = []
             colopts[(key, str(value))]['targets'] = colopts[
                 (key, str(value))]['targets'] + [index]
             colopts[(key, str(value))]['key'] = key
             colopts[(key, str(value))]['value'] = value
     for kv, values in colopts.items():
         aoColumnDefs.append(
             dict([(values['key'], values['value']),
                   ('aTargets', values['targets'])]))
     return mark_safe(dumpjs(options, indent=4, sort_keys=True))
 def handle_ajax(self, request):
     data = self.prepare_ajax_data(request)
     #print qs.query
     s = dumpjs(data)
     return HttpResponse(s, content_type='application/json')