mirror of
https://github.com/thecyberlearn/quantum-ai-v3.git
synced 2026-08-18 15:32:57 +00:00
ISSUE: Agent pages were not opening due to URL pattern conflict between agent_base/urls.py and individual agent app URLs. SOLUTION: - Remove conflicting 'agents/<slug:agent_slug>/' pattern from agent_base URLs - Add get_absolute_url() method to BaseAgent model for clean URL generation - Update marketplace template to use agent.get_absolute_url instead of URL reversal - Remove redundant agent_detail_view that was causing redirect loops RESULT: - Individual agent pages now load correctly (/agents/data-analyzer/, etc.) - Marketplace correctly links to individual agent pages - Authentication flow works as expected (login required for agent access) - No more URL conflicts or redirect loops 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
60 lines
1.9 KiB
Python
60 lines
1.9 KiB
Python
from django.shortcuts import render, redirect, get_object_or_404
|
|
from django.contrib import messages
|
|
from django.http import JsonResponse
|
|
from django.db.models import Q
|
|
from .models import BaseAgent
|
|
|
|
|
|
def marketplace_view(request):
|
|
"""Professional marketplace view with agent system"""
|
|
# Get all agents for marketplace with optimized query
|
|
agents_queryset = BaseAgent.objects.filter(is_active=True).select_related().order_by('category', 'name')
|
|
|
|
# Filter by category if specified
|
|
category = request.GET.get('category')
|
|
if category:
|
|
agents_queryset = agents_queryset.filter(category=category)
|
|
|
|
# Get agents and categories in single query
|
|
agents = list(agents_queryset)
|
|
categories = BaseAgent.objects.filter(is_active=True).values_list('category', 'category').distinct()
|
|
|
|
context = {
|
|
'user_balance': request.user.wallet_balance if request.user.is_authenticated else 0,
|
|
'agents': agents,
|
|
'categories': categories,
|
|
'selected_category': category,
|
|
}
|
|
|
|
return render(request, 'agent_base/marketplace.html', context)
|
|
|
|
|
|
|
|
def agents_api_view(request):
|
|
"""API endpoint for agents list"""
|
|
agents = BaseAgent.objects.filter(is_active=True)
|
|
|
|
# Filter by category if specified
|
|
category = request.GET.get('category')
|
|
if category:
|
|
agents = agents.filter(category=category)
|
|
|
|
agents_data = []
|
|
for agent in agents:
|
|
agents_data.append({
|
|
'id': str(agent.id),
|
|
'name': agent.name,
|
|
'slug': agent.slug,
|
|
'description': agent.description,
|
|
'category': agent.category,
|
|
'price': float(agent.price),
|
|
'icon': agent.icon,
|
|
'rating': float(agent.rating),
|
|
'review_count': agent.review_count,
|
|
'agent_type': agent.agent_type,
|
|
})
|
|
|
|
return JsonResponse({
|
|
'agents': agents_data,
|
|
'total_count': len(agents_data),
|
|
}) |