Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions api/sales_dashboard/templates/sales_dashboard/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ <h1 class="h2">Organisations</h1>
<label for="include-deleted" class="mr-1">Include deleted:</label>
<input type="checkbox" name="include_deleted" id="include-deleted" class="mr-1" {% if include_deleted %}checked{% endif %}>
<label for="filter-plan">Filter: </label>
<select name="filter_plan" id="filter-plan" class="custom-select m-1">
<option value="" {% if not filter_plan %}selected{% endif %}>Filter Plan</option>
<option value="free" {% if filter_plan == "free" %}selected{% endif %}>Free</option>
<option value="start" {% if filter_plan == "start" %}selected{% endif %}>Start Up</option>
<option value="scale" {% if filter_plan == "scale" %}selected{% endif %}>Scale Up</option>
<select name="filter_plan" id="filter-plan" class="custom-select m-1" multiple>
<option value="free" {% if "free" in filter_plan %}selected{% endif %}>Free</option>
<option value="start" {% if "start" in filter_plan %}selected{% endif %}>Start Up</option>
<option value="scale" {% if "scale" in filter_plan %}selected{% endif %}>Scale Up</option>
<option value="enterprise" {% if "enterprise" in filter_plan %}selected{% endif %}>Enterprise</option>
</select>
<label for="sort-field">Sort: </label>
<select name="sort_field" id="sort-field" class="custom-select m-1" value="{{ sort_field }}">
Expand Down
15 changes: 11 additions & 4 deletions api/sales_dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
OBJECTS_PER_PAGE = 50
DEFAULT_ORGANISATION_SORT = "subscription_information_cache__api_calls_30d"
DEFAULT_ORGANISATION_SORT_DIRECTION = "DESC"
DEFAULT_PLAN_FILTER = ["start", "scale", "enterprise"]

email_regex = re.compile(r"^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$")
domain_regex = re.compile(r"^[a-z0-9.-]+\.[a-z]{2,}$")
Expand Down Expand Up @@ -91,9 +92,13 @@ def get_queryset(self): # type: ignore[no-untyped-def]
if search_term := self.request.GET.get("search"):
queryset = queryset.filter(self._build_search_query(search_term))

if self.request.GET.get("filter_plan"):
filter_plan = self.request.GET["filter_plan"]
queryset = queryset.filter(subscription__plan__icontains=filter_plan)
plan_filter = Q()
for plan in self.request.GET.getlist(
"filter_plan", default=DEFAULT_PLAN_FILTER
):
plan_filter |= Q(subscription__plan__icontains=plan)

queryset = queryset.filter(plan_filter)

sort_field = self.request.GET.get("sort_field") or DEFAULT_ORGANISATION_SORT
sort_direction = (
Expand All @@ -112,7 +117,9 @@ def get_context_data(self, **kwargs): # type: ignore[no-untyped-def]
data = super().get_context_data(**kwargs)

data["search"] = self.request.GET.get("search", "")
data["filter_plan"] = self.request.GET.get("filter_plan")
data["filter_plan"] = self.request.GET.getlist(
"filter_plan", default=DEFAULT_PLAN_FILTER
)
data["sort_field"] = self.request.GET.get("sort_field")
data["sort_direction"] = self.request.GET.get("sort_direction")
data["include_deleted"] = self.request.GET.get("include_deleted", "off") == "on"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from environments.dynamodb.migrator import IdentityMigrator
from organisations.models import Organisation
from organisations.subscriptions.constants import ENTERPRISE


def test_sales_dashboard_index( # type: ignore[no-untyped-def]
Expand All @@ -15,9 +16,11 @@ def test_sales_dashboard_index( # type: ignore[no-untyped-def]
# Given
url = reverse("sales_dashboard:index")

# create some organisations so we can ensure there aren't any N+1 issues
# create some organisations, so we can ensure there aren't any N+1 issues
for i in range(10):
Organisation.objects.create(name=f"Test organisation {i}")
organisation = Organisation.objects.create(name=f"Test organisation {i}")
organisation.subscription.plan = ENTERPRISE
organisation.subscription.save()

# When
with django_assert_num_queries(5):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
)
def test_organisation_subscription_get_api_call_overage(
organisation: Organisation,
enterprise_subscription: Subscription,
allowed_calls_30d: int,
actual_calls_30d: int,
expected_overage: int,
Expand Down Expand Up @@ -82,6 +83,7 @@ def test_get_organisation_info__get_event_list_for_organisation(

def test_list_organisations_search_by_name(
organisation: Organisation,
enterprise_subscription: Subscription,
superuser_client: Client,
) -> None:
# Given
Expand Down Expand Up @@ -119,6 +121,7 @@ def test_list_organisations_search_by_subscription_id(

def test_list_organisations_search_by_user_email(
organisation: Organisation,
enterprise_subscription: Subscription,
superuser_client: Client,
admin_user: FFAdminUser,
) -> None:
Expand Down Expand Up @@ -157,6 +160,7 @@ def test_list_organisations_search_by_user_email_for_non_existent_user(

def test_list_organisations_search_by_domain(
organisation: Organisation,
enterprise_subscription: Subscription,
superuser_client: Client,
) -> None:
# Given
Expand Down
Loading