manager: export all user attributes (fixes #13587)
This commit is contained in:
parent
7a6ce74d94
commit
19b00d8ac5
|
@ -1,4 +1,5 @@
|
|||
import uuid
|
||||
import collections
|
||||
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _, ugettext
|
||||
|
@ -14,6 +15,8 @@ from django.http import HttpResponseRedirect, QueryDict
|
|||
from django.views.generic.detail import SingleObjectMixin
|
||||
from django.views.generic import View
|
||||
|
||||
from import_export.fields import Field
|
||||
|
||||
from authentic2.constants import SWITCH_USER_SESSION_KEY
|
||||
from authentic2.models import Attribute, PasswordReset
|
||||
from authentic2.utils import switch_user, send_password_reset_mail, redirect, send_email_change_email
|
||||
|
@ -303,6 +306,19 @@ class UsersExportView(ExportMixin, UsersView):
|
|||
resource_class = UserResource
|
||||
export_prefix = 'users-'
|
||||
|
||||
def get_resource(self):
|
||||
'''Subclass default UserResource class to dynamically add field for extra attributes'''
|
||||
attrs = collections.OrderedDict()
|
||||
for attribute in Attribute.objects.all():
|
||||
attrs['attribute_%s' % attribute.name] = Field(attribute='attributes__%s' % attribute.name)
|
||||
custom_class = type('UserResourceClass', (self.resource_class,), attrs)
|
||||
return custom_class()
|
||||
|
||||
def get_queryset(self):
|
||||
'''Prefetch attribute values.'''
|
||||
qs = super(UsersExportView, self).get_queryset()
|
||||
return qs.prefetch_related('attribute_values', 'attribute_values__attribute')
|
||||
|
||||
users_export = UsersExportView.as_view()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue