user export csv : exclude disabled attributes (#30103)
This commit is contained in:
parent
c7f80a61d2
commit
870bc65026
|
@ -355,7 +355,9 @@ class UsersExportView(ExportMixin, UsersView):
|
|||
|
||||
at_mapping = {a.id: a for a in Attribute.objects.all()}
|
||||
avs = AttributeValue.objects.filter(
|
||||
content_type=ContentType.objects.get_for_model(get_user_model())).values()
|
||||
content_type=ContentType.objects.get_for_model(get_user_model()))\
|
||||
.filter(attribute__disabled=False).values()
|
||||
|
||||
user_attrs = collections.defaultdict(dict)
|
||||
for av in avs:
|
||||
user_attrs[av['object_id']][at_mapping[av['attribute_id']].name] = av['content']
|
||||
|
|
|
@ -131,3 +131,27 @@ def test_export_csv(settings, app, superuser, django_assert_num_queries):
|
|||
assert len(table) == (user_count + 1)
|
||||
assert len(table[0]) == (15 + AT_COUNT)
|
||||
|
||||
|
||||
@skipif_sqlite
|
||||
def test_export_csv_disabled_attribute(settings, app, superuser):
|
||||
attr = Attribute.objects.create(name='attr', label='Attr', kind='string')
|
||||
attr_d = Attribute.objects.create(name='attrd', label='Attrd', kind='string')
|
||||
|
||||
user = User.objects.create(username='user-foo')
|
||||
AttributeValue.objects.create(owner=user, attribute=attr, content='attr-value')
|
||||
AttributeValue.objects.create(owner=user, attribute=attr_d, content='attrd-value')
|
||||
|
||||
attr_d.disabled = True
|
||||
attr_d.save()
|
||||
|
||||
response = login(app, superuser, reverse('a2-manager-users'))
|
||||
settings.A2_CACHE_ENABLED = True
|
||||
response = response.click('CSV')
|
||||
|
||||
user_count = User.objects.count()
|
||||
table = list(csv.reader(response.content.splitlines()))
|
||||
assert len(table) == (user_count + 1)
|
||||
num_col = 15 + 1 # 1 is the number active attributes,
|
||||
# disabled attribute should not show up
|
||||
for line in table:
|
||||
assert len(line) == num_col
|
||||
|
|
Loading…
Reference in New Issue