def report_quick(self, request):
        fields = list(getattr(self, 'list_display', ('__unicode__', )))
        filters = Q()
        ordering = self.ordering
        if request.GET.get('q', None):
            filters = set_filters_search_fields(self, request, filters, self.model)
        if request.GET.get('o', None):
            ordering = list(fields)[int(request.GET.get('o', None))]
            if request.GET.get('ot', None) and request.GET.get('ot') == 'desc':
                ordering = '-%s' % ordering
            ordering = (ordering, )
        queryset = self.queryset(request)

        try:
            try:
                cl = ChangeList(request, self.model, self.list_display, self.list_display_links, self.list_filter,
                    self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self)
            except TypeError:
                cl = ChangeList(request, self.model, self.list_display, self.list_display_links, self.list_filter,
                    self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self.list_editable, self)
            headers = list(result_headers(cl))
            j = 0
            for i, header in enumerate(headers):
                if not header.get('url', None) and isinstance(fields[i - j], basestring) and not getattr(self.model, fields[i - j], None):
                    del fields[i - j]
                    j = j + 1
        except IncorrectLookupParameters:
            pass

        return reports_view(request, self.model._meta.app_label, self.model._meta.module_name,
                            fields=fields, list_headers=None, ordering=ordering, filters=filters,
                            api=self, queryset=queryset,
                            report_to='csv')
 def get_report(self, request, queryset, form_display, report, report_to, api=None):
     list_headers = []
     report_display_fields = form_display.cleaned_data.get('__report_display_fields_choices', [])
     choices_display_fields = dict(form_display.fields['__report_display_fields_choices'].choices)
     for key in report_display_fields:
         label = choices_display_fields[key]
         list_headers.append(unicode(label).encode('utf-8'))
     return reports_view(request,
              self._meta.model._meta.app_label,
              self._meta.model._meta.module_name,
              fields=report_display_fields,
              list_headers=list_headers,
              queryset=queryset,
              report=report,
              report_to=report_to,
              api=api)
示例#3
0
 def get_report(self, request, queryset, form_display, report, report_to, api=None):
     list_headers = []
     report_display_fields = form_display.cleaned_data.get("__report_display_fields_choices", [])
     choices_display_fields = dict(form_display.fields["__report_display_fields_choices"].choices)
     for key in report_display_fields:
         label = choices_display_fields[key]
         list_headers.append(unicode(label).encode("utf-8"))
     return reports_view(
         request,
         self._meta.model._meta.app_label,
         self._meta.model._meta.module_name,
         fields=report_display_fields,
         list_headers=list_headers,
         queryset=queryset,
         report=report,
         report_to=report_to,
         api=api,
     )