Compare commits

...

4 commits

Author SHA1 Message Date
faa07a8b4d
overhaul service list filtering
All checks were successful
Build and Deploy / build (push) Successful in 35s
Build and Deploy / deploy (push) Successful in 4s
2025-03-10 15:03:20 +01:00
38ab1f3b2a
link to offering when filter for cloud provider 2025-03-10 14:54:48 +01:00
ac19c4cd25
show coming soon when no plan available 2025-03-10 14:42:40 +01:00
1a26d459f6
better scroll margin and anchor for interest 2025-03-10 14:39:48 +01:00
4 changed files with 113 additions and 75 deletions

View file

@ -142,7 +142,7 @@
{% endif %}
<!-- Plans -->
<div class="pt-24" id="plans" style="scroll-margin-top: 100px;">
<div class="pt-24" id="plans" style="scroll-margin-top: 30px;">
<h3 class="fs-24 fw-semibold lh-1 mb-12">Available Plans</h3>
<div class="row">
{% for plan in offering.plans.all %}
@ -169,7 +169,7 @@
</div>
</div>
{% empty %}
<div class="col-12">
<div class="col-12" id="interest" style="scroll-margin-top: 30px;">
<div class="alert alert-info">
<p>No plans available yet.</p>
<h4 class="mb-3">I'm interested in this offering</h4>

View file

@ -157,6 +157,11 @@
</a>
</div>
{% endif %}
{% if not offering.plans.all %}
<div>
<a class="btn btn-secondary btn-sm" href="">Coming Soon</a>
</div>
{% endif %}
</div>
{% endif %}
<div class="card__content d-flex flex-column flex-grow-1">

View file

@ -155,9 +155,19 @@
<div class="d-flex justify-content-between">
{% if service.logo %}
<div class="card__image flex-shrink-0">
{% if request.GET.cloud_provider %}
{% for offering in service.offerings.all %}
{% if offering.cloud_provider.id|stringformat:'i' == request.GET.cloud_provider %}
<a href="{% url 'services:offering_detail' offering.cloud_provider.slug service.slug %}">
<img src="{{ service.logo.url }}" alt="{{ service.name }} logo" class="img-fluid">
</a>
{% endif %}
{% endfor %}
{% else %}
<a href="{{ service.get_absolute_url }}">
<img src="{{ service.logo.url }}" alt="{{ service.name }} logo" class="img-fluid">
</a>
{% endif %}
</div>
{% endif %}
{% if service.is_featured %}
@ -173,7 +183,17 @@
{% endif %}
<div class="card__content d-flex flex-column flex-grow-1">
<div class="card__header">
<h3 class="card__title"><a href="{{ service.get_absolute_url }}" class="text-decoration-none {% if service.is_coming_soon %}text-black-50{% endif %}">{{ service.name }}</a></h3>
<h3 class="card__title">
{% if request.GET.cloud_provider %}
{% for offering in service.offerings.all %}
{% if offering.cloud_provider.id|stringformat:'i' == request.GET.cloud_provider %}
<a href="{% url 'services:offering_detail' offering.cloud_provider.slug service.slug %}" class="text-decoration-none {% if service.is_coming_soon %}text-black-50{% endif %}">{{ service.name }}</a>
{% endif %}
{% endfor %}
{% else %}
<a href="{{ service.get_absolute_url }}" class="text-decoration-none {% if service.is_coming_soon %}text-black-50{% endif %}">{{ service.name }}</a>
{% endif %}
</h3>
<p class="card__subtitle">
{% for category in service.categories.all %}
<span>{{ category.full_path }}</span>

View file

@ -17,7 +17,8 @@ def service_list(request):
# Start with all active services
# Filter out services with disable_listing=True
services = Service.objects.filter(disable_listing=False)
all_services = Service.objects.filter(disable_listing=False)
services = all_services
# Apply filters based on request parameters
if search_query:
@ -42,86 +43,98 @@ def service_list(request):
"name", # Alphabetically within each group
)
# Get all available categories from filtered services
available_category_ids = services.values_list(
"categories__id", flat=True
).distinct()
available_categories = Category.objects.filter(
id__in=available_category_ids, parent=None
# Create base querysets for each filter type that apply all OTHER current filters
# This way, each filter shows options that would return results if selected
# For category filter options, apply all other filters except category
category_filter_base = all_services
if search_query:
category_filter_base = category_filter_base.filter(
Q(name__icontains=search_query) | Q(description__icontains=search_query)
)
if consulting_partner_id:
category_filter_base = category_filter_base.filter(
consulting_partners__id=consulting_partner_id
)
if cloud_provider_id:
category_filter_base = category_filter_base.filter(
offerings__cloud_provider__id=cloud_provider_id
)
# For consulting partner filter options, apply all other filters except consulting_partner
cp_filter_base = all_services
if search_query:
cp_filter_base = cp_filter_base.filter(
Q(name__icontains=search_query) | Q(description__icontains=search_query)
)
if category_id:
cp_filter_base = cp_filter_base.filter(categories__id=category_id)
if cloud_provider_id:
cp_filter_base = cp_filter_base.filter(
offerings__cloud_provider__id=cloud_provider_id
)
# For cloud provider filter options, apply all other filters except cloud_provider
cloud_filter_base = all_services
if search_query:
cloud_filter_base = cloud_filter_base.filter(
Q(name__icontains=search_query) | Q(description__icontains=search_query)
)
if category_id:
cloud_filter_base = cloud_filter_base.filter(categories__id=category_id)
if consulting_partner_id:
cloud_filter_base = cloud_filter_base.filter(
consulting_partners__id=consulting_partner_id
)
# Get available categories that would return results if selected
available_parent_categories = Category.objects.filter(
parent=None,
id__in=category_filter_base.values_list(
"categories__parent__id", flat=True
).distinct(),
).distinct()
# Add categories that are direct matches (not children)
direct_categories = Category.objects.filter(
parent=None,
id__in=category_filter_base.values_list("categories__id", flat=True).distinct(),
).distinct()
available_parent_categories = (
available_parent_categories | direct_categories
).distinct()
# For each parent category, get available children
for category in available_categories:
child_ids = (
services.filter(categories__parent=category)
.values_list("categories__id", flat=True)
.distinct()
)
category.available_children = Category.objects.filter(id__in=child_ids)
# Get available consulting partners from filtered services
# Excluding partners with disable_listing=True
available_consulting_partner_ids = services.values_list(
"consulting_partners__id", flat=True
for parent_category in available_parent_categories:
parent_category.available_children = Category.objects.filter(
parent=parent_category,
id__in=category_filter_base.values_list(
"categories__id", flat=True
).distinct(),
).distinct()
# Get available consulting partners and cloud providers that would return results if selected
available_consulting_partners = ConsultingPartner.objects.filter(
id__in=available_consulting_partner_ids, disable_listing=False
)
# Get available cloud providers from filtered services via offerings
# Excluding providers with disable_listing=True
available_cloud_provider_ids = services.values_list(
"offerings__cloud_provider__id", flat=True
disable_listing=False,
id__in=cp_filter_base.values_list(
"consulting_partners__id", flat=True
).distinct(),
).distinct()
available_cloud_providers = CloudProvider.objects.filter(
id__in=available_cloud_provider_ids, disable_listing=False
)
# For the current selection, we need to make sure we include the selected items
# even if they don't match other filters
if category_id:
try:
selected_category = Category.objects.get(id=category_id)
if selected_category.parent:
parent_category = selected_category.parent
if parent_category not in available_categories:
available_categories = list(available_categories)
available_categories.append(parent_category)
parent_category.available_children = [selected_category]
elif selected_category not in available_categories:
available_categories = list(available_categories)
available_categories.append(selected_category)
except Category.DoesNotExist:
pass
if consulting_partner_id:
try:
cp_id = int(consulting_partner_id)
if cp_id not in available_consulting_partner_ids:
selected_partner = ConsultingPartner.objects.get(id=cp_id)
available_consulting_partners = list(available_consulting_partners)
available_consulting_partners.append(selected_partner)
except (ValueError, ConsultingPartner.DoesNotExist):
pass
if cloud_provider_id:
try:
cp_id = int(cloud_provider_id)
if cp_id not in available_cloud_provider_ids:
selected_provider = CloudProvider.objects.get(id=cp_id)
available_cloud_providers = list(available_cloud_providers)
available_cloud_providers.append(selected_provider)
except (ValueError, CloudProvider.DoesNotExist):
pass
disable_listing=False,
id__in=cloud_filter_base.values_list(
"offerings__cloud_provider__id", flat=True
).distinct(),
).distinct()
context = {
"services": services,
"categories": Category.objects.filter(parent=None),
"consulting_partners": ConsultingPartner.objects.filter(disable_listing=False),
"cloud_providers": CloudProvider.objects.filter(disable_listing=False),
"available_categories": available_categories,
"available_categories": available_parent_categories,
"available_consulting_partners": available_consulting_partners,
"available_cloud_providers": available_cloud_providers,
"search_query": search_query,
}
return render(request, "services/service_list.html", context)