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 parse_params(self, request): params = {} for name, value in request.GET.items(): try: params[name] = hungarian_to_python(name, value) except NameError: pass return params
def __init__(self, **kwargs): self.options = {} for key, value in kwargs.items(): try: self.options[key] = hungarian_to_python(key, value) kwargs.pop(key) except NameError: pass for key, value in self.DEFAULTS.items(): setattr(self, key, kwargs.get(key, value)) self.classes = set(self.classes or []) if self.value_renderer is None: self.value_renderer = getattr(self, 'render_value', None) if self.label_renderer is None: self.label_renderer = getattr(self, 'render_label', None) # Increase the creation counter, and save our local copy. self.creation_counter = Column.creation_counter Column.creation_counter += 1
def update(self, options=None): self.id = getattr(options, 'id', getattr(self, 'id', 'datatable_%d' % id(self))) self.var = getattr(options, 'var', getattr(self, 'var', None)) self.classes = getattr(options, 'classes', getattr(self, 'classes', [])) if isinstance(self.classes, basestring): self.classes = self.classes.split() self.classes = set(self.classes) self.width = str( getattr(options, 'width', getattr(self, 'width', '100%'))) self.border = str( getattr(options, 'border', getattr(self, 'border', '0'))) self.cellpadding = str( getattr(options, 'cellpadding', getattr(self, 'cellpadding', '0'))) self.cellspacing = str( getattr(options, 'cellspacing', getattr(self, 'cellspacing', '0'))) self.model = getattr(options, 'model', getattr(self, 'model', None)) self.options = getattr(self, 'options', {}) self.options.update(getattr(options, 'options', {})) for name in dir(options): if name.startswith('_'): continue value = getattr(options, name) try: self.options[name] = hungarian_to_python(name, value) except NameError: pass if self.options.has_key('fnClientTransformData' ) and not self.options.has_key('fnServerData'): self.options['fnServerData'] = u''' function( sSource, aoData, fnCallback, oSettings ) { oSettings.jqXHR = $.ajax( { "dataType": 'json', "type": "GET", "url": sSource, "data": aoData, "success": function( data, textStatus, jqXHR ) { %s(data, textStatus, jqXHR); fnCallback( data, textStatus, jqXHR ); }, }); }''' % self.options['fnClientTransformData']
def update(self, options=None): self.id = getattr(options, 'id', getattr(self, 'id', 'datatable_%d' % id(self))) self.var = getattr(options, 'var', getattr(self, 'var', None)) self.classes = getattr(options, 'classes', getattr(self, 'classes', [])) if isinstance(self.classes, basestring): self.classes = self.classes.split() self.classes = set(self.classes) self.width = str(getattr(options, 'width', getattr(self, 'width', '100%'))) self.border = str(getattr(options, 'border', getattr(self, 'border', '0'))) self.cellpadding = str(getattr(options, 'cellpadding', getattr(self, 'cellpadding', '0'))) self.cellspacing = str(getattr(options, 'cellspacing', getattr(self, 'cellspacing', '0'))) self.model = getattr(options, 'model', getattr(self, 'model', None)) self.options = getattr(self, 'options', {}) self.options.update(getattr(options, 'options', {})) for name in dir(options): if name.startswith('_'): continue value = getattr(options, name) try: self.options[name] = hungarian_to_python(name, value) except NameError: pass