def _get_field_aggregate(self, field_name, queryset, row): item = ResultItem(field_name, row) item.classes = ['aggregate', ] if field_name not in self.aggregate_queryset_fields: item.text = "" else: try: agg_method = self.aggregate_queryset_fields[field_name] key = '%s__%s' % (field_name, agg_method) all_values = [] for obj in queryset: v = getattr(obj, field_name) if callable(v): v = v() all_values.append(v) value = sum(all_values) if agg_method == 'min': value = min(all_values) elif agg_method == 'max': value = max(all_values) elif agg_method == 'avg': value = value / len(all_values) elif agg_method == 'count': value = len(all_values) item.text = value item.wraps.append('%%s<span class="aggregate_title label label-info">%s</span>' % AGGREGATE_TITLE[agg_method]) item.classes.append(agg_method) except FieldDoesNotExist: item.text = "" return item
def get_data(self): row = ResultRow() item1 = ResultItem("pin", row) item1.text = 1 row.cells.append(item1) item2 = ResultItem("EName", row) item2.text = 2 row.cells.append(item2) item3 = ResultItem("Card", row) item3.text = 2 row.cells.append(item3) return [row,row,row,row,row]
def _get_field_aggregate(self, field_name, obj, row): item = ResultItem(field_name, row) item.classes = ['aggregate', ] if field_name not in self.aggregate_fields: item.text = "" else: try: f = self.opts.get_field(field_name) agg_method = self.aggregate_fields[field_name] key = '%s__%s' % (field_name, agg_method) if key not in obj: item.text = "" else: item.text = display_for_field(obj[key], f) item.wraps.append('%%s<span class="aggregate_title label label-info">%s</span>' % AGGREGATE_TITLE[agg_method]) item.classes.append(agg_method) except FieldDoesNotExist: item.text = "" return item
def _get_field_aggregate(self, field_name, obj, row): item = ResultItem(field_name, row) item.classes = [ 'aggregate', ] if field_name not in self.aggregate_fields: item.text = "" else: try: f = self.opts.get_field(field_name) agg_method = self.aggregate_fields[field_name] key = '%s__%s' % (field_name, agg_method) if key not in obj: item.text = "" else: item.text = display_for_field(obj[key], f) item.wraps.append( '%%s<span class="aggregate_title label label-info">%s</span>' % AGGREGATE_TITLE[agg_method]) item.classes.append(agg_method) except FieldDoesNotExist: item.text = "" return item