Skip to content

Commit

Permalink
Merge pull request #440 from projectcaluma/fix-filter-export
Browse files Browse the repository at this point in the history
feat(export): add filtering support
  • Loading branch information
winged authored Oct 12, 2023
2 parents c28ba8e + 7830dc3 commit ce50b4c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion emeis/core/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,12 @@ def test_user_export(client, user_factory, acl_factory, snapshot):
user = user_factory()
acl_factory.create_batch(9)
acl_factory.create_batch(2, user=user)
# this user should not be exported
user_factory(is_active=False)

url = reverse("user-export")

response = client.get(url)
response = client.get(url, {"filter[isActive]": "true"})

assert response.status_code == HTTP_200_OK

Expand Down
2 changes: 1 addition & 1 deletion emeis/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def get_queryset(self):
@action(methods=["get"], detail=False)
def export(self, request):
"""Export user list as excel table."""
queryset = self.get_queryset()
queryset = self.filter_queryset(self.get_queryset())

# we use a template to set the headers to bold and align the columns to fit on a DIN-A4 page
workbook = openpyxl.load_workbook(settings.USER_EXPORT_TEMPLATE_PATH)
Expand Down
9 changes: 8 additions & 1 deletion emeis/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ def default(default_dev=env.NOTSET, default_prod=env.NOTSET):
]

if ENV == "dev":
INSTALLED_APPS.append("django_extensions")
try:
__import__("django_extensions")
INSTALLED_APPS.append("django_extensions")
except ImportError: # pragma: no cover
# Nothing bad, just won't have django-extensions
# niceties installed (Most likely Emeis was built
# without dev dependencies)
pass

MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
Expand Down

0 comments on commit ce50b4c

Please sign in to comment.