quantum-ai-v3/data_analyzer/models.py
Claude bfdef5b658 Refactor: Complete architecture reorganization with proper separation of concerns
BREAKING CHANGES:
- Move marketplace and agent discovery views from core to agent_base app
- Transfer all wallet functionality from core to dedicated wallet app
- Move Stripe webhook handling to wallet app for better organization
- Consolidate payment system logic under single responsibility

NEW STRUCTURE:
- core app: Platform pages only (homepage, pricing)
- agent_base app: Complete agent marketplace and catalog system
- wallet app: Full payment system with Stripe integration
- Individual agent apps: Unchanged, self-contained

IMPROVEMENTS:
- Clean URL namespacing (agent_base:marketplace, wallet:wallet)
- Template organization by app responsibility
- Removed deprecated CSS files (header.css)
- Added utility classes (.hidden)
- Updated all template references to new URL structure
- Comprehensive CLAUDE.md documentation updates

TECHNICAL CHANGES:
- Templates moved: marketplace.html, agent_detail.html → agent_base/
- Templates moved: wallet*.html → wallet/
- New files: agent_base/views.py, agent_base/urls.py, wallet/urls.py
- Updated main urls.py routing configuration
- Fixed Django system checks and namespace conflicts
- Verified all functionality with test suite

This reorganization follows Django best practices with single responsibility
principle, making the codebase more maintainable and scalable.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-21 20:03:53 +05:30

80 lines
2.9 KiB
Python

from django.db import models
from decimal import Decimal
from agent_base.models import BaseAgentRequest, BaseAgentResponse
from django.db.models.signals import post_delete
from django.dispatch import receiver
import os
class DataAnalysisAgentRequest(BaseAgentRequest):
"""Data Analysis Agent request tracking"""
# Agent-specific request fields
data_file = models.FileField(upload_to='uploads/data_analyzer/', blank=True)
analysis_type = models.CharField(
max_length=50,
choices=[
('summary', 'Summary Analysis'),
('detailed', 'Detailed Analysis'),
('statistical', 'Statistical Analysis'),
],
default='summary'
)
# Legacy field (keeping for compatibility)
input_text = models.TextField(blank=True, null=True)
def delete(self, *args, **kwargs):
"""Custom delete method to clean up uploaded file"""
# Delete the file before deleting the database record
if self.data_file:
try:
if os.path.exists(self.data_file.path):
os.remove(self.data_file.path)
print(f"Deleted file during model deletion: {self.data_file.path}")
except Exception as e:
print(f"Warning - Failed to delete file during model deletion: {e}")
# Call the parent delete method
super().delete(*args, **kwargs)
class Meta:
db_table = 'data_analyzer_requests'
verbose_name = 'Data Analysis Agent Request'
verbose_name_plural = 'Data Analysis Agent Requests'
class DataAnalysisAgentResponse(BaseAgentResponse):
"""Data Analysis Agent response storage"""
request = models.OneToOneField(
DataAnalysisAgentRequest,
on_delete=models.CASCADE,
related_name='response'
)
# Agent-specific response fields
analysis_results = models.JSONField(default=dict, blank=True)
insights_summary = models.TextField(blank=True)
report_text = models.TextField(blank=True)
raw_response = models.JSONField(default=dict, blank=True)
# Legacy field (keeping for compatibility)
output_text = models.TextField(blank=True, null=True)
class Meta:
db_table = 'data_analyzer_responses'
verbose_name = 'Data Analysis Agent Response'
verbose_name_plural = 'Data Analysis Agent Responses'
@receiver(post_delete, sender=DataAnalysisAgentRequest)
def cleanup_data_file(sender, instance, **kwargs):
"""Signal handler to ensure uploaded files are deleted when request is deleted"""
if instance.data_file:
try:
if os.path.exists(instance.data_file.path):
os.remove(instance.data_file.path)
print(f"Signal cleanup: Deleted file {instance.data_file.path}")
except Exception as e:
print(f"Signal cleanup warning - Failed to delete file: {e}")