2025-01-30 09:49:27 +01:00
|
|
|
from django.shortcuts import render, get_object_or_404
|
|
|
|
from django.db.models import Q
|
2025-01-30 11:23:25 +01:00
|
|
|
from hub.services.models import (
|
2025-01-30 09:49:27 +01:00
|
|
|
Service,
|
|
|
|
ConsultingPartner,
|
|
|
|
CloudProvider,
|
|
|
|
Category,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def service_list(request):
|
2025-03-03 17:28:38 +01:00
|
|
|
# Get basic filter parameters
|
|
|
|
search_query = request.GET.get("search", "")
|
|
|
|
category_id = request.GET.get("category", "")
|
|
|
|
consulting_partner_id = request.GET.get("consulting_partner", "")
|
|
|
|
cloud_provider_id = request.GET.get("cloud_provider", "")
|
|
|
|
|
|
|
|
# Start with all active services
|
|
|
|
# Filter out services with disable_listing=True
|
2025-03-10 15:03:20 +01:00
|
|
|
all_services = Service.objects.filter(disable_listing=False)
|
|
|
|
services = all_services
|
2025-03-03 17:28:38 +01:00
|
|
|
|
|
|
|
# Apply filters based on request parameters
|
|
|
|
if search_query:
|
|
|
|
services = services.filter(
|
|
|
|
Q(name__icontains=search_query) | Q(description__icontains=search_query)
|
2025-02-26 10:39:23 +01:00
|
|
|
)
|
2025-03-03 17:28:38 +01:00
|
|
|
|
|
|
|
if category_id:
|
|
|
|
services = services.filter(categories__id=category_id)
|
|
|
|
|
|
|
|
if consulting_partner_id:
|
|
|
|
services = services.filter(consulting_partners__id=consulting_partner_id)
|
|
|
|
|
|
|
|
if cloud_provider_id:
|
|
|
|
# Filter through offerings instead of direct cloud_providers relation
|
|
|
|
services = services.filter(offerings__cloud_provider__id=cloud_provider_id)
|
|
|
|
|
2025-03-03 17:45:28 +01:00
|
|
|
# Order services: featured first, then regular services, then coming soon
|
|
|
|
services = services.order_by(
|
|
|
|
"-is_featured", # Featured first (True before False)
|
|
|
|
"is_coming_soon", # Coming soon last (False before True)
|
|
|
|
"name", # Alphabetically within each group
|
|
|
|
)
|
|
|
|
|
2025-03-10 15:03:20 +01:00
|
|
|
# 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
|
2025-03-03 17:28:38 +01:00
|
|
|
|
2025-03-10 15:03:20 +01:00
|
|
|
# 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
|
2025-03-03 17:28:38 +01:00
|
|
|
)
|
|
|
|
|
2025-03-10 15:03:20 +01:00
|
|
|
# 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(),
|
2025-03-03 17:28:38 +01:00
|
|
|
).distinct()
|
|
|
|
|
2025-03-10 15:03:20 +01:00
|
|
|
# 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(),
|
2025-03-03 17:28:38 +01:00
|
|
|
).distinct()
|
|
|
|
|
2025-03-10 15:03:20 +01:00
|
|
|
available_parent_categories = (
|
|
|
|
available_parent_categories | direct_categories
|
|
|
|
).distinct()
|
2025-03-03 17:28:38 +01:00
|
|
|
|
2025-03-10 15:03:20 +01:00
|
|
|
# For each parent category, get available children
|
|
|
|
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(
|
|
|
|
disable_listing=False,
|
|
|
|
id__in=cp_filter_base.values_list(
|
|
|
|
"consulting_partners__id", flat=True
|
|
|
|
).distinct(),
|
|
|
|
).distinct()
|
2025-03-03 17:28:38 +01:00
|
|
|
|
2025-03-10 15:03:20 +01:00
|
|
|
available_cloud_providers = CloudProvider.objects.filter(
|
|
|
|
disable_listing=False,
|
|
|
|
id__in=cloud_filter_base.values_list(
|
|
|
|
"offerings__cloud_provider__id", flat=True
|
|
|
|
).distinct(),
|
|
|
|
).distinct()
|
2025-01-30 09:49:27 +01:00
|
|
|
|
|
|
|
context = {
|
|
|
|
"services": services,
|
2025-03-10 15:03:20 +01:00
|
|
|
"available_categories": available_parent_categories,
|
2025-03-03 17:28:38 +01:00
|
|
|
"available_consulting_partners": available_consulting_partners,
|
|
|
|
"available_cloud_providers": available_cloud_providers,
|
2025-03-10 15:03:20 +01:00
|
|
|
"search_query": search_query,
|
2025-01-30 09:49:27 +01:00
|
|
|
}
|
2025-03-03 17:28:38 +01:00
|
|
|
|
2025-01-30 09:49:27 +01:00
|
|
|
return render(request, "services/service_list.html", context)
|
|
|
|
|
|
|
|
|
|
|
|
def service_detail(request, slug):
|
|
|
|
service = get_object_or_404(
|
|
|
|
Service.objects.prefetch_related(
|
|
|
|
"categories",
|
|
|
|
"offerings",
|
|
|
|
"offerings__cloud_provider",
|
|
|
|
"offerings__plans",
|
|
|
|
"consulting_partners",
|
|
|
|
"external_links",
|
|
|
|
),
|
|
|
|
slug=slug,
|
|
|
|
)
|
|
|
|
|
|
|
|
context = {
|
|
|
|
"service": service,
|
|
|
|
}
|
|
|
|
return render(request, "services/service_detail.html", context)
|