manager: add a default implementation of ExportMixin.get_data() (#13587)

It takes the default queryset and batches it using the new function
batch_queryset().
This commit is contained in:
Benjamin Dauvergne 2018-05-02 15:42:55 +02:00
parent 516cb4f890
commit cc101ea394
3 changed files with 5 additions and 22 deletions

View File

@ -92,9 +92,6 @@ add = RoleAddView.as_view()
class RolesExportView(views.ExportMixin, RolesView):
resource_class = resources.RoleResource
def get_data(self):
return self.get_queryset()
export = RolesExportView.as_view()

View File

@ -298,23 +298,11 @@ class UserEditView(OtherActionsMixin, ActionMixin, BaseEditView):
user_edit = UserEditView.as_view()
# Mock object to disable Queryset specialization by django-import-export
class IterateIterable(object):
def __init__(self, qs):
self.qs = qs
def __iter__(self):
return self.qs.__iter__()
class UsersExportView(ExportMixin, UsersView):
permissions = ['custom_user.view_user']
resource_class = UserResource
export_prefix = 'users-'
def get_data(self):
return IterateIterable(self.get_queryset())
users_export = UsersExportView.as_view()

View File

@ -22,7 +22,7 @@ from django_select2.views import AutoResponseView
from django_rbac.utils import get_ou_model
from authentic2.forms import modelform_factory
from authentic2.utils import redirect
from authentic2.utils import redirect, batch_queryset
from authentic2.decorators import json as json_view
from authentic2 import hooks
@ -131,12 +131,6 @@ class FilterTableQuerysetByPermMixin(object):
return qs
class FilterDatasetQuerysetByPermMixin(object):
def get_dataset(self):
qs = super(FilterDatasetQuerysetByPermMixin, self).get_dataset()
return filter_view(self.request, qs)
class TableQuerysetMixin(object):
def get_table_queryset(self):
return self.get_queryset()
@ -338,6 +332,10 @@ class ExportMixin(object):
def get_resource(self):
return self.resource_class()
def get_data(self):
qs = self.get_queryset()
return batch_queryset(qs)
def get_dataset(self):
return self.get_resource().export(self.get_data())