django-cfg 1.3.7__py3-none-any.whl → 1.3.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- django_cfg/__init__.py +1 -1
- django_cfg/apps/accounts/admin/__init__.py +24 -8
- django_cfg/apps/accounts/admin/activity_admin.py +146 -0
- django_cfg/apps/accounts/admin/filters.py +98 -22
- django_cfg/apps/accounts/admin/group_admin.py +86 -0
- django_cfg/apps/accounts/admin/inlines.py +42 -13
- django_cfg/apps/accounts/admin/otp_admin.py +115 -0
- django_cfg/apps/accounts/admin/registration_admin.py +173 -0
- django_cfg/apps/accounts/admin/resources.py +123 -19
- django_cfg/apps/accounts/admin/twilio_admin.py +327 -0
- django_cfg/apps/accounts/admin/user_admin.py +362 -0
- django_cfg/apps/agents/admin/__init__.py +17 -4
- django_cfg/apps/agents/admin/execution_admin.py +204 -183
- django_cfg/apps/agents/admin/registry_admin.py +230 -255
- django_cfg/apps/agents/admin/toolsets_admin.py +274 -321
- django_cfg/apps/agents/core/__init__.py +1 -1
- django_cfg/apps/agents/core/django_agent.py +221 -0
- django_cfg/apps/agents/core/exceptions.py +14 -0
- django_cfg/apps/agents/core/orchestrator.py +18 -3
- django_cfg/apps/knowbase/admin/__init__.py +1 -1
- django_cfg/apps/knowbase/admin/archive_admin.py +352 -640
- django_cfg/apps/knowbase/admin/chat_admin.py +258 -192
- django_cfg/apps/knowbase/admin/document_admin.py +269 -262
- django_cfg/apps/knowbase/admin/external_data_admin.py +271 -489
- django_cfg/apps/knowbase/config/settings.py +21 -4
- django_cfg/apps/knowbase/views/chat_views.py +3 -0
- django_cfg/apps/leads/admin/__init__.py +3 -1
- django_cfg/apps/leads/admin/leads_admin.py +235 -35
- django_cfg/apps/maintenance/admin/__init__.py +2 -2
- django_cfg/apps/maintenance/admin/api_key_admin.py +125 -63
- django_cfg/apps/maintenance/admin/log_admin.py +143 -61
- django_cfg/apps/maintenance/admin/scheduled_admin.py +212 -301
- django_cfg/apps/maintenance/admin/site_admin.py +213 -352
- django_cfg/apps/newsletter/admin/__init__.py +29 -2
- django_cfg/apps/newsletter/admin/newsletter_admin.py +531 -193
- django_cfg/apps/payments/admin/__init__.py +18 -27
- django_cfg/apps/payments/admin/api_keys_admin.py +179 -546
- django_cfg/apps/payments/admin/balance_admin.py +166 -632
- django_cfg/apps/payments/admin/currencies_admin.py +235 -607
- django_cfg/apps/payments/admin/endpoint_groups_admin.py +127 -0
- django_cfg/apps/payments/admin/filters.py +83 -3
- django_cfg/apps/payments/admin/networks_admin.py +258 -0
- django_cfg/apps/payments/admin/payments_admin.py +171 -461
- django_cfg/apps/payments/admin/subscriptions_admin.py +119 -636
- django_cfg/apps/payments/admin/tariffs_admin.py +248 -0
- django_cfg/apps/payments/admin_interface/serializers/payment_serializers.py +105 -34
- django_cfg/apps/payments/admin_interface/templates/payments/payment_form.html +12 -16
- django_cfg/apps/payments/admin_interface/views/__init__.py +2 -0
- django_cfg/apps/payments/admin_interface/views/api/webhook_admin.py +13 -18
- django_cfg/apps/payments/management/commands/manage_currencies.py +236 -274
- django_cfg/apps/payments/management/commands/manage_providers.py +4 -1
- django_cfg/apps/payments/middleware/api_access.py +32 -6
- django_cfg/apps/payments/migrations/0002_currency_usd_rate_currency_usd_rate_updated_at.py +26 -0
- django_cfg/apps/payments/migrations/0003_remove_provider_currency_fields.py +28 -0
- django_cfg/apps/payments/migrations/0004_add_reserved_usd_field.py +30 -0
- django_cfg/apps/payments/models/balance.py +12 -0
- django_cfg/apps/payments/models/currencies.py +106 -32
- django_cfg/apps/payments/models/managers/currency_managers.py +65 -0
- django_cfg/apps/payments/services/core/currency_service.py +35 -28
- django_cfg/apps/payments/services/core/payment_service.py +1 -1
- django_cfg/apps/payments/services/providers/__init__.py +3 -0
- django_cfg/apps/payments/services/providers/base.py +95 -39
- django_cfg/apps/payments/services/providers/models/__init__.py +40 -0
- django_cfg/apps/payments/services/providers/models/base.py +122 -0
- django_cfg/apps/payments/services/providers/models/providers.py +87 -0
- django_cfg/apps/payments/services/providers/models/universal.py +48 -0
- django_cfg/apps/payments/services/providers/nowpayments/__init__.py +31 -0
- django_cfg/apps/payments/services/providers/nowpayments/config.py +70 -0
- django_cfg/apps/payments/services/providers/nowpayments/models.py +150 -0
- django_cfg/apps/payments/services/providers/nowpayments/parsers.py +879 -0
- django_cfg/apps/payments/services/providers/{nowpayments.py → nowpayments/provider.py} +240 -209
- django_cfg/apps/payments/services/providers/nowpayments/sync.py +196 -0
- django_cfg/apps/payments/services/providers/registry.py +4 -32
- django_cfg/apps/payments/services/providers/sync_service.py +277 -0
- django_cfg/apps/payments/static/payments/js/api-client.js +23 -5
- django_cfg/apps/payments/static/payments/js/payment-form.js +65 -8
- django_cfg/apps/payments/tasks/__init__.py +39 -0
- django_cfg/apps/payments/tasks/types.py +73 -0
- django_cfg/apps/payments/tasks/usage_tracking.py +308 -0
- django_cfg/apps/payments/templates/admin/payments/_components/dashboard_header.html +23 -0
- django_cfg/apps/payments/templates/admin/payments/_components/stats_card.html +25 -0
- django_cfg/apps/payments/templates/admin/payments/_components/stats_grid.html +16 -0
- django_cfg/apps/payments/templates/admin/payments/apikey/change_list.html +39 -0
- django_cfg/apps/payments/templates/admin/payments/balance/change_list.html +50 -0
- django_cfg/apps/payments/templates/admin/payments/currency/change_list.html +40 -0
- django_cfg/apps/payments/templates/admin/payments/payment/change_list.html +48 -0
- django_cfg/apps/payments/templates/admin/payments/subscription/change_list.html +48 -0
- django_cfg/apps/payments/urls_admin.py +1 -1
- django_cfg/apps/payments/views/api/currencies.py +5 -5
- django_cfg/apps/payments/views/overview/services.py +2 -2
- django_cfg/apps/payments/views/serializers/currencies.py +4 -3
- django_cfg/apps/support/admin/__init__.py +10 -1
- django_cfg/apps/support/admin/support_admin.py +338 -141
- django_cfg/apps/tasks/admin/__init__.py +11 -0
- django_cfg/apps/tasks/admin/tasks_admin.py +430 -0
- django_cfg/config.py +1 -1
- django_cfg/core/config.py +10 -5
- django_cfg/core/generation.py +1 -1
- django_cfg/management/commands/__init__.py +13 -1
- django_cfg/management/commands/app_agent_diagnose.py +470 -0
- django_cfg/management/commands/app_agent_generate.py +342 -0
- django_cfg/management/commands/app_agent_info.py +308 -0
- django_cfg/management/commands/migrate_all.py +9 -3
- django_cfg/management/commands/migrator.py +11 -6
- django_cfg/management/commands/rundramatiq.py +3 -2
- django_cfg/middleware/__init__.py +0 -2
- django_cfg/models/api_keys.py +115 -0
- django_cfg/modules/django_admin/__init__.py +64 -0
- django_cfg/modules/django_admin/decorators/__init__.py +13 -0
- django_cfg/modules/django_admin/decorators/actions.py +106 -0
- django_cfg/modules/django_admin/decorators/display.py +106 -0
- django_cfg/modules/django_admin/mixins/__init__.py +14 -0
- django_cfg/modules/django_admin/mixins/display_mixin.py +81 -0
- django_cfg/modules/django_admin/mixins/optimization_mixin.py +41 -0
- django_cfg/modules/django_admin/mixins/standalone_actions_mixin.py +202 -0
- django_cfg/modules/django_admin/models/__init__.py +20 -0
- django_cfg/modules/django_admin/models/action_models.py +33 -0
- django_cfg/modules/django_admin/models/badge_models.py +20 -0
- django_cfg/modules/django_admin/models/base.py +26 -0
- django_cfg/modules/django_admin/models/display_models.py +31 -0
- django_cfg/modules/django_admin/utils/badges.py +159 -0
- django_cfg/modules/django_admin/utils/displays.py +247 -0
- django_cfg/modules/django_app_agent/__init__.py +87 -0
- django_cfg/modules/django_app_agent/agents/__init__.py +40 -0
- django_cfg/modules/django_app_agent/agents/base/__init__.py +24 -0
- django_cfg/modules/django_app_agent/agents/base/agent.py +354 -0
- django_cfg/modules/django_app_agent/agents/base/context.py +236 -0
- django_cfg/modules/django_app_agent/agents/base/executor.py +430 -0
- django_cfg/modules/django_app_agent/agents/generation/__init__.py +12 -0
- django_cfg/modules/django_app_agent/agents/generation/app_generator/__init__.py +15 -0
- django_cfg/modules/django_app_agent/agents/generation/app_generator/config_validator.py +147 -0
- django_cfg/modules/django_app_agent/agents/generation/app_generator/main.py +99 -0
- django_cfg/modules/django_app_agent/agents/generation/app_generator/models.py +32 -0
- django_cfg/modules/django_app_agent/agents/generation/app_generator/prompt_manager.py +290 -0
- django_cfg/modules/django_app_agent/agents/interfaces.py +376 -0
- django_cfg/modules/django_app_agent/core/__init__.py +33 -0
- django_cfg/modules/django_app_agent/core/config.py +300 -0
- django_cfg/modules/django_app_agent/core/exceptions.py +359 -0
- django_cfg/modules/django_app_agent/models/__init__.py +71 -0
- django_cfg/modules/django_app_agent/models/base.py +283 -0
- django_cfg/modules/django_app_agent/models/context.py +496 -0
- django_cfg/modules/django_app_agent/models/enums.py +481 -0
- django_cfg/modules/django_app_agent/models/requests.py +500 -0
- django_cfg/modules/django_app_agent/models/responses.py +585 -0
- django_cfg/modules/django_app_agent/pytest.ini +6 -0
- django_cfg/modules/django_app_agent/services/__init__.py +42 -0
- django_cfg/modules/django_app_agent/services/app_generator/__init__.py +30 -0
- django_cfg/modules/django_app_agent/services/app_generator/ai_integration.py +133 -0
- django_cfg/modules/django_app_agent/services/app_generator/context.py +40 -0
- django_cfg/modules/django_app_agent/services/app_generator/main.py +202 -0
- django_cfg/modules/django_app_agent/services/app_generator/structure.py +316 -0
- django_cfg/modules/django_app_agent/services/app_generator/validation.py +125 -0
- django_cfg/modules/django_app_agent/services/base.py +437 -0
- django_cfg/modules/django_app_agent/services/context_builder/__init__.py +34 -0
- django_cfg/modules/django_app_agent/services/context_builder/code_extractor.py +141 -0
- django_cfg/modules/django_app_agent/services/context_builder/context_generator.py +276 -0
- django_cfg/modules/django_app_agent/services/context_builder/main.py +272 -0
- django_cfg/modules/django_app_agent/services/context_builder/models.py +40 -0
- django_cfg/modules/django_app_agent/services/context_builder/pattern_analyzer.py +85 -0
- django_cfg/modules/django_app_agent/services/project_scanner/__init__.py +31 -0
- django_cfg/modules/django_app_agent/services/project_scanner/app_discovery.py +311 -0
- django_cfg/modules/django_app_agent/services/project_scanner/main.py +221 -0
- django_cfg/modules/django_app_agent/services/project_scanner/models.py +59 -0
- django_cfg/modules/django_app_agent/services/project_scanner/pattern_detection.py +94 -0
- django_cfg/modules/django_app_agent/services/questioning_service/__init__.py +28 -0
- django_cfg/modules/django_app_agent/services/questioning_service/main.py +273 -0
- django_cfg/modules/django_app_agent/services/questioning_service/models.py +111 -0
- django_cfg/modules/django_app_agent/services/questioning_service/question_generator.py +251 -0
- django_cfg/modules/django_app_agent/services/questioning_service/response_processor.py +347 -0
- django_cfg/modules/django_app_agent/services/questioning_service/session_manager.py +356 -0
- django_cfg/modules/django_app_agent/services/report_service.py +332 -0
- django_cfg/modules/django_app_agent/services/template_manager/__init__.py +18 -0
- django_cfg/modules/django_app_agent/services/template_manager/jinja_engine.py +236 -0
- django_cfg/modules/django_app_agent/services/template_manager/main.py +159 -0
- django_cfg/modules/django_app_agent/services/template_manager/models.py +36 -0
- django_cfg/modules/django_app_agent/services/template_manager/template_loader.py +100 -0
- django_cfg/modules/django_app_agent/services/template_manager/templates/admin.py.j2 +105 -0
- django_cfg/modules/django_app_agent/services/template_manager/templates/apps.py.j2 +31 -0
- django_cfg/modules/django_app_agent/services/template_manager/templates/cfg_config.py.j2 +44 -0
- django_cfg/modules/django_app_agent/services/template_manager/templates/cfg_module.py.j2 +81 -0
- django_cfg/modules/django_app_agent/services/template_manager/templates/forms.py.j2 +107 -0
- django_cfg/modules/django_app_agent/services/template_manager/templates/models.py.j2 +139 -0
- django_cfg/modules/django_app_agent/services/template_manager/templates/serializers.py.j2 +91 -0
- django_cfg/modules/django_app_agent/services/template_manager/templates/tests.py.j2 +195 -0
- django_cfg/modules/django_app_agent/services/template_manager/templates/urls.py.j2 +35 -0
- django_cfg/modules/django_app_agent/services/template_manager/templates/views.py.j2 +211 -0
- django_cfg/modules/django_app_agent/services/template_manager/variable_processor.py +200 -0
- django_cfg/modules/django_app_agent/services/validation_service/__init__.py +25 -0
- django_cfg/modules/django_app_agent/services/validation_service/django_validator.py +333 -0
- django_cfg/modules/django_app_agent/services/validation_service/main.py +242 -0
- django_cfg/modules/django_app_agent/services/validation_service/models.py +66 -0
- django_cfg/modules/django_app_agent/services/validation_service/quality_validator.py +352 -0
- django_cfg/modules/django_app_agent/services/validation_service/security_validator.py +272 -0
- django_cfg/modules/django_app_agent/services/validation_service/syntax_validator.py +203 -0
- django_cfg/modules/django_app_agent/ui/__init__.py +25 -0
- django_cfg/modules/django_app_agent/ui/cli.py +419 -0
- django_cfg/modules/django_app_agent/ui/rich_components.py +622 -0
- django_cfg/modules/django_app_agent/utils/__init__.py +38 -0
- django_cfg/modules/django_app_agent/utils/logging.py +360 -0
- django_cfg/modules/django_app_agent/utils/validation.py +417 -0
- django_cfg/modules/django_currency/__init__.py +2 -2
- django_cfg/modules/django_currency/clients/__init__.py +2 -2
- django_cfg/modules/django_currency/clients/hybrid_client.py +587 -0
- django_cfg/modules/django_currency/core/converter.py +12 -12
- django_cfg/modules/django_currency/database/__init__.py +2 -2
- django_cfg/modules/django_currency/database/database_loader.py +93 -42
- django_cfg/modules/django_llm/llm/client.py +10 -2
- django_cfg/modules/django_unfold/callbacks/actions.py +1 -1
- django_cfg/modules/django_unfold/callbacks/statistics.py +1 -1
- django_cfg/modules/django_unfold/dashboard.py +14 -13
- django_cfg/modules/django_unfold/models/config.py +1 -1
- django_cfg/registry/core.py +3 -0
- django_cfg/registry/third_party.py +2 -2
- django_cfg/template_archive/django_sample.zip +0 -0
- {django_cfg-1.3.7.dist-info → django_cfg-1.3.9.dist-info}/METADATA +2 -1
- {django_cfg-1.3.7.dist-info → django_cfg-1.3.9.dist-info}/RECORD +223 -117
- django_cfg/apps/accounts/admin/activity.py +0 -96
- django_cfg/apps/accounts/admin/group.py +0 -17
- django_cfg/apps/accounts/admin/otp.py +0 -59
- django_cfg/apps/accounts/admin/registration_source.py +0 -97
- django_cfg/apps/accounts/admin/twilio_response.py +0 -227
- django_cfg/apps/accounts/admin/user.py +0 -300
- django_cfg/apps/agents/core/agent.py +0 -281
- django_cfg/apps/payments/admin_interface/old/payments/base.html +0 -175
- django_cfg/apps/payments/admin_interface/old/payments/components/dev_tool_card.html +0 -125
- django_cfg/apps/payments/admin_interface/old/payments/components/loading_spinner.html +0 -16
- django_cfg/apps/payments/admin_interface/old/payments/components/ngrok_status_card.html +0 -113
- django_cfg/apps/payments/admin_interface/old/payments/components/notification.html +0 -27
- django_cfg/apps/payments/admin_interface/old/payments/components/provider_card.html +0 -86
- django_cfg/apps/payments/admin_interface/old/payments/components/status_card.html +0 -35
- django_cfg/apps/payments/admin_interface/old/payments/currency_converter.html +0 -382
- django_cfg/apps/payments/admin_interface/old/payments/payment_dashboard.html +0 -309
- django_cfg/apps/payments/admin_interface/old/payments/payment_form.html +0 -303
- django_cfg/apps/payments/admin_interface/old/payments/payment_list.html +0 -382
- django_cfg/apps/payments/admin_interface/old/payments/payment_status.html +0 -500
- django_cfg/apps/payments/admin_interface/old/payments/webhook_dashboard.html +0 -518
- django_cfg/apps/payments/admin_interface/old/static/payments/css/components.css +0 -619
- django_cfg/apps/payments/admin_interface/old/static/payments/css/dashboard.css +0 -188
- django_cfg/apps/payments/admin_interface/old/static/payments/js/components.js +0 -545
- django_cfg/apps/payments/admin_interface/old/static/payments/js/ngrok-status.js +0 -163
- django_cfg/apps/payments/admin_interface/old/static/payments/js/utils.js +0 -412
- django_cfg/apps/tasks/admin.py +0 -320
- django_cfg/middleware/static_nocache.py +0 -55
- django_cfg/modules/django_currency/clients/yahoo_client.py +0 -157
- /django_cfg/modules/{django_unfold → django_admin}/icons/README.md +0 -0
- /django_cfg/modules/{django_unfold → django_admin}/icons/__init__.py +0 -0
- /django_cfg/modules/{django_unfold → django_admin}/icons/constants.py +0 -0
- /django_cfg/modules/{django_unfold → django_admin}/icons/generate_icons.py +0 -0
- {django_cfg-1.3.7.dist-info → django_cfg-1.3.9.dist-info}/WHEEL +0 -0
- {django_cfg-1.3.7.dist-info → django_cfg-1.3.9.dist-info}/entry_points.txt +0 -0
- {django_cfg-1.3.7.dist-info → django_cfg-1.3.9.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,99 @@
|
|
1
|
+
"""
|
2
|
+
Main App Generator Agent class.
|
3
|
+
|
4
|
+
This module contains the primary agent class that orchestrates
|
5
|
+
Django application generation using AI.
|
6
|
+
"""
|
7
|
+
|
8
|
+
from typing import List
|
9
|
+
import asyncio
|
10
|
+
|
11
|
+
from pydantic_ai import Agent, RunContext
|
12
|
+
|
13
|
+
from ...base import DjangoAgent, AgentDependencies
|
14
|
+
from ....models.requests import AppGenerationRequest
|
15
|
+
from ....core.exceptions import GenerationError
|
16
|
+
|
17
|
+
from .models import FileGenerationRequest, GeneratedFileResponse
|
18
|
+
from .config_validator import ConfigValidator
|
19
|
+
from .prompt_manager import PromptManager
|
20
|
+
|
21
|
+
|
22
|
+
class AppGeneratorAgent(DjangoAgent):
|
23
|
+
"""AI agent for generating Django application files."""
|
24
|
+
|
25
|
+
def __init__(self, config):
|
26
|
+
"""Initialize the app generator agent."""
|
27
|
+
# Initialize components
|
28
|
+
self.config_validator = ConfigValidator()
|
29
|
+
self.prompt_manager = PromptManager()
|
30
|
+
|
31
|
+
# Validate API keys and configure model first
|
32
|
+
self.model = self.config_validator.validate_and_configure(config)
|
33
|
+
|
34
|
+
# Initialize Pydantic AI agent
|
35
|
+
self.pydantic_agent = Agent(
|
36
|
+
model=self.model,
|
37
|
+
retries=2
|
38
|
+
)
|
39
|
+
|
40
|
+
# Now call super init which will call _register_instructions
|
41
|
+
super().__init__("app_generator", config)
|
42
|
+
|
43
|
+
async def generate_file(
|
44
|
+
self,
|
45
|
+
request: FileGenerationRequest
|
46
|
+
) -> GeneratedFileResponse:
|
47
|
+
"""Generate a specific file for the Django application."""
|
48
|
+
try:
|
49
|
+
# Create detailed prompt for the specific feature
|
50
|
+
prompt = self.prompt_manager.create_feature_prompt(request)
|
51
|
+
|
52
|
+
# Run AI generation
|
53
|
+
result = await self.pydantic_agent.run(prompt)
|
54
|
+
|
55
|
+
return result.data
|
56
|
+
|
57
|
+
except Exception as e:
|
58
|
+
raise GenerationError(
|
59
|
+
f"Failed to generate {request.feature.value} file: {e}",
|
60
|
+
app_name=request.app_name,
|
61
|
+
generation_stage=f"generate_{request.feature.value}_file"
|
62
|
+
)
|
63
|
+
|
64
|
+
async def generate_multiple_files(
|
65
|
+
self,
|
66
|
+
app_request: AppGenerationRequest
|
67
|
+
) -> List[GeneratedFileResponse]:
|
68
|
+
"""Generate multiple files for an application."""
|
69
|
+
results = []
|
70
|
+
|
71
|
+
for feature in app_request.features:
|
72
|
+
request = FileGenerationRequest(
|
73
|
+
app_name=app_request.app_name,
|
74
|
+
description=app_request.description,
|
75
|
+
feature=feature,
|
76
|
+
app_type=app_request.app_type,
|
77
|
+
complexity=app_request.complexity
|
78
|
+
)
|
79
|
+
|
80
|
+
try:
|
81
|
+
result = await self.generate_file(request)
|
82
|
+
results.append(result)
|
83
|
+
except Exception as e:
|
84
|
+
self.logger.error(f"Failed to generate {feature.value}: {e}")
|
85
|
+
# Continue with other features
|
86
|
+
continue
|
87
|
+
|
88
|
+
return results
|
89
|
+
|
90
|
+
def _register_instructions(self) -> None:
|
91
|
+
"""Register agent instructions."""
|
92
|
+
@self.pydantic_agent.system_prompt
|
93
|
+
async def agent_instructions(ctx: RunContext[AgentDependencies]) -> str:
|
94
|
+
return self.prompt_manager.get_system_prompt()
|
95
|
+
|
96
|
+
def _register_tools(self) -> None:
|
97
|
+
"""Register agent tools."""
|
98
|
+
# No additional tools needed for basic file generation
|
99
|
+
pass
|
@@ -0,0 +1,32 @@
|
|
1
|
+
"""
|
2
|
+
Data models for the App Generator Agent.
|
3
|
+
|
4
|
+
This module contains Pydantic models used for request/response
|
5
|
+
handling in the AI agent.
|
6
|
+
"""
|
7
|
+
|
8
|
+
from typing import List, Dict, Any
|
9
|
+
from pydantic import BaseModel, Field
|
10
|
+
|
11
|
+
from ....models.enums import AppFeature, AppType, AppComplexity
|
12
|
+
|
13
|
+
|
14
|
+
class FileGenerationRequest(BaseModel):
|
15
|
+
"""Request for generating a specific file."""
|
16
|
+
|
17
|
+
app_name: str = Field(description="Name of the Django application")
|
18
|
+
description: str = Field(description="Application description")
|
19
|
+
feature: AppFeature = Field(description="Feature to generate")
|
20
|
+
app_type: AppType = Field(description="Type of Django application")
|
21
|
+
complexity: AppComplexity = Field(description="Application complexity level")
|
22
|
+
additional_context: Dict[str, Any] = Field(default_factory=dict, description="Additional context")
|
23
|
+
|
24
|
+
|
25
|
+
class GeneratedFileResponse(BaseModel):
|
26
|
+
"""Response containing generated file content."""
|
27
|
+
|
28
|
+
filename: str = Field(description="Name of the generated file")
|
29
|
+
content: str = Field(description="File content")
|
30
|
+
imports: List[str] = Field(default_factory=list, description="Required imports")
|
31
|
+
dependencies: List[str] = Field(default_factory=list, description="Package dependencies")
|
32
|
+
description: str = Field(description="File description")
|
@@ -0,0 +1,290 @@
|
|
1
|
+
"""
|
2
|
+
Prompt management for the App Generator Agent.
|
3
|
+
|
4
|
+
This module handles all AI prompts for different Django features
|
5
|
+
and provides intelligent prompt generation based on requirements.
|
6
|
+
"""
|
7
|
+
|
8
|
+
from .models import FileGenerationRequest
|
9
|
+
from ....models.enums import AppFeature
|
10
|
+
|
11
|
+
|
12
|
+
class PromptManager:
|
13
|
+
"""Manages AI prompts for different Django features."""
|
14
|
+
|
15
|
+
def get_system_prompt(self) -> str:
|
16
|
+
"""Get the system prompt for the AI agent."""
|
17
|
+
return """You are an expert Django developer with deep knowledge of Django best practices,
|
18
|
+
design patterns, and modern Python development.
|
19
|
+
|
20
|
+
Your task is to generate high-quality Django application files based on user requirements.
|
21
|
+
|
22
|
+
Guidelines:
|
23
|
+
1. Follow Django best practices and conventions
|
24
|
+
2. Use proper Python type hints
|
25
|
+
3. Include comprehensive docstrings
|
26
|
+
4. Add appropriate error handling
|
27
|
+
5. Follow PEP 8 style guidelines
|
28
|
+
6. Use modern Django features (Django 5.x)
|
29
|
+
7. Include proper imports and dependencies
|
30
|
+
8. Generate production-ready code
|
31
|
+
9. Add meaningful comments where needed
|
32
|
+
10. Consider security best practices
|
33
|
+
|
34
|
+
For django-cfg applications, also:
|
35
|
+
- Use django-cfg patterns and conventions
|
36
|
+
- Leverage django-cfg modules when appropriate
|
37
|
+
- Follow the infrastructural layer approach
|
38
|
+
- Use proper configuration management
|
39
|
+
|
40
|
+
Always generate complete, working code that can be used immediately."""
|
41
|
+
|
42
|
+
def create_feature_prompt(self, request: FileGenerationRequest) -> str:
|
43
|
+
"""Create a detailed prompt for generating a specific feature."""
|
44
|
+
feature_prompts = {
|
45
|
+
AppFeature.MODELS: self._get_models_prompt(request),
|
46
|
+
AppFeature.VIEWS: self._get_views_prompt(request),
|
47
|
+
AppFeature.ADMIN: self._get_admin_prompt(request),
|
48
|
+
AppFeature.URLS: self._get_urls_prompt(request),
|
49
|
+
AppFeature.FORMS: self._get_forms_prompt(request),
|
50
|
+
AppFeature.API: self._get_api_prompt(request),
|
51
|
+
AppFeature.TESTS: self._get_tests_prompt(request),
|
52
|
+
AppFeature.TASKS: self._get_tasks_prompt(request),
|
53
|
+
AppFeature.SIGNALS: self._get_signals_prompt(request),
|
54
|
+
}
|
55
|
+
|
56
|
+
return feature_prompts.get(request.feature, self._get_generic_prompt(request))
|
57
|
+
|
58
|
+
def _get_models_prompt(self, request: FileGenerationRequest) -> str:
|
59
|
+
"""Get prompt for generating models.py."""
|
60
|
+
return f"""Generate a Django models.py file for the '{request.app_name}' application.
|
61
|
+
|
62
|
+
Application Details:
|
63
|
+
- Name: {request.app_name}
|
64
|
+
- Description: {request.description}
|
65
|
+
- Type: {request.app_type.value}
|
66
|
+
- Complexity: {request.complexity.value}
|
67
|
+
|
68
|
+
Requirements:
|
69
|
+
1. Create relevant models based on the application description
|
70
|
+
2. Use appropriate field types and relationships
|
71
|
+
3. Include proper Meta classes with ordering, verbose names
|
72
|
+
4. Add __str__ methods for all models
|
73
|
+
5. Use abstract base models where appropriate
|
74
|
+
6. Include created_at/updated_at timestamps
|
75
|
+
7. Add proper model validation
|
76
|
+
8. Include relevant indexes for performance
|
77
|
+
9. Use proper related_name for relationships
|
78
|
+
10. Add comprehensive docstrings
|
79
|
+
|
80
|
+
For django-cfg apps, also consider:
|
81
|
+
- Using django-cfg base models if appropriate
|
82
|
+
- Following django-cfg naming conventions
|
83
|
+
- Including proper configuration fields
|
84
|
+
|
85
|
+
Generate complete, production-ready models with proper imports."""
|
86
|
+
|
87
|
+
def _get_views_prompt(self, request: FileGenerationRequest) -> str:
|
88
|
+
"""Get prompt for generating views.py."""
|
89
|
+
return f"""Generate a Django views.py file for the '{request.app_name}' application.
|
90
|
+
|
91
|
+
Application Details:
|
92
|
+
- Name: {request.app_name}
|
93
|
+
- Description: {request.description}
|
94
|
+
- Type: {request.app_type.value}
|
95
|
+
- Complexity: {request.complexity.value}
|
96
|
+
|
97
|
+
Requirements:
|
98
|
+
1. Create appropriate view classes/functions based on the app purpose
|
99
|
+
2. Use class-based views where appropriate
|
100
|
+
3. Include proper permission checks
|
101
|
+
4. Add error handling and validation
|
102
|
+
5. Use proper HTTP status codes
|
103
|
+
6. Include pagination for list views
|
104
|
+
7. Add proper context data
|
105
|
+
8. Use Django's built-in mixins
|
106
|
+
9. Include proper docstrings
|
107
|
+
10. Add type hints
|
108
|
+
|
109
|
+
Generate complete, secure views with proper imports and error handling."""
|
110
|
+
|
111
|
+
def _get_admin_prompt(self, request: FileGenerationRequest) -> str:
|
112
|
+
"""Get prompt for generating admin.py."""
|
113
|
+
return f"""Generate a Django admin.py file for the '{request.app_name}' application.
|
114
|
+
|
115
|
+
Application Details:
|
116
|
+
- Name: {request.app_name}
|
117
|
+
- Description: {request.description}
|
118
|
+
- Type: {request.app_type.value}
|
119
|
+
- Complexity: {request.complexity.value}
|
120
|
+
|
121
|
+
Requirements:
|
122
|
+
1. Register all models with appropriate admin classes
|
123
|
+
2. Configure list_display, list_filter, search_fields
|
124
|
+
3. Add proper fieldsets for complex models
|
125
|
+
4. Include inline admin for related models
|
126
|
+
5. Add custom admin actions where useful
|
127
|
+
6. Use proper admin permissions
|
128
|
+
7. Include admin-specific methods
|
129
|
+
8. Add proper docstrings
|
130
|
+
9. Configure admin ordering and pagination
|
131
|
+
10. Add custom admin templates if needed
|
132
|
+
|
133
|
+
Generate a complete admin configuration with good UX."""
|
134
|
+
|
135
|
+
def _get_urls_prompt(self, request: FileGenerationRequest) -> str:
|
136
|
+
"""Get prompt for generating urls.py."""
|
137
|
+
return f"""Generate a Django urls.py file for the '{request.app_name}' application.
|
138
|
+
|
139
|
+
Application Details:
|
140
|
+
- Name: {request.app_name}
|
141
|
+
- Description: {request.description}
|
142
|
+
- Type: {request.app_type.value}
|
143
|
+
- Complexity: {request.complexity.value}
|
144
|
+
|
145
|
+
Requirements:
|
146
|
+
1. Create appropriate URL patterns for the application
|
147
|
+
2. Use proper URL naming conventions
|
148
|
+
3. Include namespace for the app
|
149
|
+
4. Add URL patterns for all major views
|
150
|
+
5. Use path() instead of url() (modern Django)
|
151
|
+
6. Include proper parameter types in URLs
|
152
|
+
7. Add API endpoints if this is an API app
|
153
|
+
8. Consider SEO-friendly URLs
|
154
|
+
9. Include proper docstrings
|
155
|
+
10. Group related URLs logically
|
156
|
+
|
157
|
+
Generate complete URL configuration with proper imports."""
|
158
|
+
|
159
|
+
def _get_forms_prompt(self, request: FileGenerationRequest) -> str:
|
160
|
+
"""Get prompt for generating forms.py."""
|
161
|
+
return f"""Generate a Django forms.py file for the '{request.app_name}' application.
|
162
|
+
|
163
|
+
Application Details:
|
164
|
+
- Name: {request.app_name}
|
165
|
+
- Description: {request.description}
|
166
|
+
- Type: {request.app_type.value}
|
167
|
+
- Complexity: {request.complexity.value}
|
168
|
+
|
169
|
+
Requirements:
|
170
|
+
1. Create ModelForm classes for main models
|
171
|
+
2. Add proper field validation
|
172
|
+
3. Include custom clean methods
|
173
|
+
4. Use appropriate widgets
|
174
|
+
5. Add form styling classes
|
175
|
+
6. Include proper error messages
|
176
|
+
7. Add form helpers if using crispy forms
|
177
|
+
8. Include proper docstrings
|
178
|
+
9. Add custom form fields if needed
|
179
|
+
10. Consider accessibility
|
180
|
+
|
181
|
+
Generate complete, user-friendly forms with proper validation."""
|
182
|
+
|
183
|
+
def _get_api_prompt(self, request: FileGenerationRequest) -> str:
|
184
|
+
"""Get prompt for generating API files (serializers.py)."""
|
185
|
+
return f"""Generate Django REST Framework serializers.py for the '{request.app_name}' application.
|
186
|
+
|
187
|
+
Application Details:
|
188
|
+
- Name: {request.app_name}
|
189
|
+
- Description: {request.description}
|
190
|
+
- Type: {request.app_type.value}
|
191
|
+
- Complexity: {request.complexity.value}
|
192
|
+
|
193
|
+
Requirements:
|
194
|
+
1. Create ModelSerializer classes for main models
|
195
|
+
2. Include proper field validation
|
196
|
+
3. Add custom serializer methods
|
197
|
+
4. Use nested serializers for relationships
|
198
|
+
5. Include proper read-only fields
|
199
|
+
6. Add custom create/update methods
|
200
|
+
7. Include proper docstrings
|
201
|
+
8. Add API versioning considerations
|
202
|
+
9. Use proper field representations
|
203
|
+
10. Include permission-aware serialization
|
204
|
+
|
205
|
+
Generate complete REST API serializers with proper validation."""
|
206
|
+
|
207
|
+
def _get_tests_prompt(self, request: FileGenerationRequest) -> str:
|
208
|
+
"""Get prompt for generating tests.py."""
|
209
|
+
return f"""Generate comprehensive Django tests.py for the '{request.app_name}' application.
|
210
|
+
|
211
|
+
Application Details:
|
212
|
+
- Name: {request.app_name}
|
213
|
+
- Description: {request.description}
|
214
|
+
- Type: {request.app_type.value}
|
215
|
+
- Complexity: {request.complexity.value}
|
216
|
+
|
217
|
+
Requirements:
|
218
|
+
1. Create test classes for models, views, forms
|
219
|
+
2. Use Django's TestCase and test client
|
220
|
+
3. Include proper test data setup
|
221
|
+
4. Test all major functionality
|
222
|
+
5. Add negative test cases
|
223
|
+
6. Test permissions and security
|
224
|
+
7. Include API tests if applicable
|
225
|
+
8. Use proper assertions
|
226
|
+
9. Add performance tests for complex operations
|
227
|
+
10. Include integration tests
|
228
|
+
|
229
|
+
Generate comprehensive test coverage with proper test organization."""
|
230
|
+
|
231
|
+
def _get_tasks_prompt(self, request: FileGenerationRequest) -> str:
|
232
|
+
"""Get prompt for generating tasks.py (Celery/background tasks)."""
|
233
|
+
return f"""Generate Django tasks.py for background processing in the '{request.app_name}' application.
|
234
|
+
|
235
|
+
Application Details:
|
236
|
+
- Name: {request.app_name}
|
237
|
+
- Description: {request.description}
|
238
|
+
- Type: {request.app_type.value}
|
239
|
+
- Complexity: {request.complexity.value}
|
240
|
+
|
241
|
+
Requirements:
|
242
|
+
1. Create Celery tasks for background processing
|
243
|
+
2. Include proper error handling and retries
|
244
|
+
3. Add task monitoring and logging
|
245
|
+
4. Use proper task signatures
|
246
|
+
5. Include task result handling
|
247
|
+
6. Add periodic tasks if needed
|
248
|
+
7. Include proper docstrings
|
249
|
+
8. Add task progress tracking
|
250
|
+
9. Use proper task queues
|
251
|
+
10. Include task testing utilities
|
252
|
+
|
253
|
+
Generate production-ready background tasks with proper error handling."""
|
254
|
+
|
255
|
+
def _get_signals_prompt(self, request: FileGenerationRequest) -> str:
|
256
|
+
"""Get prompt for generating signals.py."""
|
257
|
+
return f"""Generate Django signals.py for the '{request.app_name}' application.
|
258
|
+
|
259
|
+
Application Details:
|
260
|
+
- Name: {request.app_name}
|
261
|
+
- Description: {request.description}
|
262
|
+
- Type: {request.app_type.value}
|
263
|
+
- Complexity: {request.complexity.value}
|
264
|
+
|
265
|
+
Requirements:
|
266
|
+
1. Create appropriate signal handlers
|
267
|
+
2. Use proper signal decorators
|
268
|
+
3. Include error handling in signals
|
269
|
+
4. Add proper logging
|
270
|
+
5. Consider signal performance impact
|
271
|
+
6. Include proper docstrings
|
272
|
+
7. Use weak references where appropriate
|
273
|
+
8. Add signal testing
|
274
|
+
9. Consider signal ordering
|
275
|
+
10. Include proper cleanup
|
276
|
+
|
277
|
+
Generate efficient signal handlers with proper error handling."""
|
278
|
+
|
279
|
+
def _get_generic_prompt(self, request: FileGenerationRequest) -> str:
|
280
|
+
"""Get generic prompt for other features."""
|
281
|
+
return f"""Generate a Django file for the '{request.feature.value}' feature in the '{request.app_name}' application.
|
282
|
+
|
283
|
+
Application Details:
|
284
|
+
- Name: {request.app_name}
|
285
|
+
- Description: {request.description}
|
286
|
+
- Feature: {request.feature.value}
|
287
|
+
- Type: {request.app_type.value}
|
288
|
+
- Complexity: {request.complexity.value}
|
289
|
+
|
290
|
+
Generate appropriate, production-ready code following Django best practices."""
|