django-cfg 1.4.10__py3-none-any.whl → 1.4.11__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.
Files changed (181) hide show
  1. django_cfg/apps/agents/management/commands/create_agent.py +1 -1
  2. django_cfg/apps/agents/management/commands/orchestrator_status.py +3 -3
  3. django_cfg/apps/newsletter/serializers.py +40 -3
  4. django_cfg/apps/newsletter/views/campaigns.py +12 -3
  5. django_cfg/apps/newsletter/views/emails.py +14 -3
  6. django_cfg/apps/newsletter/views/subscriptions.py +12 -2
  7. django_cfg/apps/payments/views/api/currencies.py +49 -6
  8. django_cfg/apps/payments/views/api/webhooks.py +72 -7
  9. django_cfg/apps/payments/views/overview/serializers.py +34 -1
  10. django_cfg/apps/payments/views/overview/views.py +2 -1
  11. django_cfg/apps/payments/views/serializers/payments.py +6 -6
  12. django_cfg/apps/urls.py +106 -45
  13. django_cfg/core/base/config_model.py +2 -2
  14. django_cfg/core/constants.py +1 -1
  15. django_cfg/core/generation/integration_generators/__init__.py +1 -1
  16. django_cfg/core/generation/integration_generators/api.py +72 -49
  17. django_cfg/core/integration/display/startup.py +30 -22
  18. django_cfg/core/integration/url_integration.py +15 -16
  19. django_cfg/dashboard/sections/documentation.py +391 -0
  20. django_cfg/management/commands/check_endpoints.py +11 -160
  21. django_cfg/management/commands/check_settings.py +13 -348
  22. django_cfg/management/commands/clear_constance.py +13 -201
  23. django_cfg/management/commands/create_token.py +13 -321
  24. django_cfg/management/commands/generate_clients.py +23 -0
  25. django_cfg/management/commands/list_urls.py +13 -306
  26. django_cfg/management/commands/migrate_all.py +13 -126
  27. django_cfg/management/commands/migrator.py +13 -396
  28. django_cfg/management/commands/rundramatiq.py +15 -247
  29. django_cfg/management/commands/rundramatiq_simulator.py +12 -429
  30. django_cfg/management/commands/runserver_ngrok.py +15 -160
  31. django_cfg/management/commands/script.py +12 -488
  32. django_cfg/management/commands/show_config.py +12 -215
  33. django_cfg/management/commands/show_urls.py +12 -342
  34. django_cfg/management/commands/superuser.py +15 -295
  35. django_cfg/management/commands/task_clear.py +14 -217
  36. django_cfg/management/commands/task_status.py +13 -248
  37. django_cfg/management/commands/test_email.py +15 -86
  38. django_cfg/management/commands/test_telegram.py +14 -61
  39. django_cfg/management/commands/test_twilio.py +15 -105
  40. django_cfg/management/commands/tree.py +13 -383
  41. django_cfg/management/commands/validate_openapi.py +10 -0
  42. django_cfg/middleware/README.md +1 -1
  43. django_cfg/middleware/user_activity.py +3 -3
  44. django_cfg/models/__init__.py +2 -2
  45. django_cfg/models/api/drf/spectacular.py +6 -6
  46. django_cfg/models/django/__init__.py +2 -2
  47. django_cfg/models/django/openapi.py +238 -0
  48. django_cfg/modules/django_admin/management/__init__.py +0 -0
  49. django_cfg/modules/django_admin/management/commands/__init__.py +0 -0
  50. django_cfg/modules/django_admin/management/commands/check_endpoints.py +169 -0
  51. django_cfg/modules/django_admin/management/commands/check_settings.py +355 -0
  52. django_cfg/modules/django_admin/management/commands/clear_constance.py +208 -0
  53. django_cfg/modules/django_admin/management/commands/create_token.py +328 -0
  54. django_cfg/modules/django_admin/management/commands/list_urls.py +313 -0
  55. django_cfg/modules/django_admin/management/commands/migrate_all.py +133 -0
  56. django_cfg/modules/django_admin/management/commands/migrator.py +403 -0
  57. django_cfg/modules/django_admin/management/commands/script.py +496 -0
  58. django_cfg/modules/django_admin/management/commands/show_config.py +225 -0
  59. django_cfg/modules/django_admin/management/commands/show_urls.py +361 -0
  60. django_cfg/modules/django_admin/management/commands/superuser.py +302 -0
  61. django_cfg/modules/django_admin/management/commands/tree.py +390 -0
  62. django_cfg/modules/django_client/__init__.py +20 -0
  63. django_cfg/modules/django_client/apps.py +35 -0
  64. django_cfg/modules/django_client/core/__init__.py +56 -0
  65. django_cfg/modules/django_client/core/archive/__init__.py +11 -0
  66. django_cfg/modules/django_client/core/archive/manager.py +134 -0
  67. django_cfg/modules/django_client/core/cli/__init__.py +12 -0
  68. django_cfg/modules/django_client/core/cli/main.py +235 -0
  69. django_cfg/modules/django_client/core/config/__init__.py +18 -0
  70. django_cfg/modules/django_client/core/config/config.py +188 -0
  71. django_cfg/modules/django_client/core/config/group.py +101 -0
  72. django_cfg/modules/django_client/core/config/service.py +209 -0
  73. django_cfg/modules/django_client/core/generator/__init__.py +115 -0
  74. django_cfg/modules/django_client/core/generator/base.py +767 -0
  75. django_cfg/modules/django_client/core/generator/python.py +751 -0
  76. django_cfg/modules/django_client/core/generator/templates/python/__init__.py.jinja +9 -0
  77. django_cfg/modules/django_client/core/generator/templates/python/api_wrapper.py.jinja +130 -0
  78. django_cfg/modules/django_client/core/generator/templates/python/app_init.py.jinja +6 -0
  79. django_cfg/modules/django_client/core/generator/templates/python/client/app_client.py.jinja +18 -0
  80. django_cfg/modules/django_client/core/generator/templates/python/client/flat_client.py.jinja +38 -0
  81. django_cfg/modules/django_client/core/generator/templates/python/client/main_client.py.jinja +50 -0
  82. django_cfg/modules/django_client/core/generator/templates/python/client/main_client_file.py.jinja +13 -0
  83. django_cfg/modules/django_client/core/generator/templates/python/client/operation_method.py.jinja +7 -0
  84. django_cfg/modules/django_client/core/generator/templates/python/client/sub_client.py.jinja +11 -0
  85. django_cfg/modules/django_client/core/generator/templates/python/client_file.py.jinja +13 -0
  86. django_cfg/modules/django_client/core/generator/templates/python/main_init.py.jinja +50 -0
  87. django_cfg/modules/django_client/core/generator/templates/python/models/app_models.py.jinja +17 -0
  88. django_cfg/modules/django_client/core/generator/templates/python/models/enum_class.py.jinja +15 -0
  89. django_cfg/modules/django_client/core/generator/templates/python/models/enums.py.jinja +8 -0
  90. django_cfg/modules/django_client/core/generator/templates/python/models/models.py.jinja +17 -0
  91. django_cfg/modules/django_client/core/generator/templates/python/models/schema_class.py.jinja +19 -0
  92. django_cfg/modules/django_client/core/generator/templates/python/utils/logger.py.jinja +255 -0
  93. django_cfg/modules/django_client/core/generator/templates/python/utils/schema.py.jinja +12 -0
  94. django_cfg/modules/django_client/core/generator/templates/typescript/app_index.ts.jinja +2 -0
  95. django_cfg/modules/django_client/core/generator/templates/typescript/client/app_client.ts.jinja +18 -0
  96. django_cfg/modules/django_client/core/generator/templates/typescript/client/client.ts.jinja +327 -0
  97. django_cfg/modules/django_client/core/generator/templates/typescript/client/flat_client.ts.jinja +109 -0
  98. django_cfg/modules/django_client/core/generator/templates/typescript/client/main_client_file.ts.jinja +9 -0
  99. django_cfg/modules/django_client/core/generator/templates/typescript/client/operation.ts.jinja +61 -0
  100. django_cfg/modules/django_client/core/generator/templates/typescript/client/sub_client.ts.jinja +15 -0
  101. django_cfg/modules/django_client/core/generator/templates/typescript/client_file.ts.jinja +9 -0
  102. django_cfg/modules/django_client/core/generator/templates/typescript/index.ts.jinja +5 -0
  103. django_cfg/modules/django_client/core/generator/templates/typescript/main_index.ts.jinja +206 -0
  104. django_cfg/modules/django_client/core/generator/templates/typescript/models/app_models.ts.jinja +8 -0
  105. django_cfg/modules/django_client/core/generator/templates/typescript/models/enums.ts.jinja +4 -0
  106. django_cfg/modules/django_client/core/generator/templates/typescript/models/models.ts.jinja +8 -0
  107. django_cfg/modules/django_client/core/generator/templates/typescript/utils/errors.ts.jinja +114 -0
  108. django_cfg/modules/django_client/core/generator/templates/typescript/utils/http.ts.jinja +98 -0
  109. django_cfg/modules/django_client/core/generator/templates/typescript/utils/logger.ts.jinja +251 -0
  110. django_cfg/modules/django_client/core/generator/templates/typescript/utils/schema.ts.jinja +7 -0
  111. django_cfg/modules/django_client/core/generator/templates/typescript/utils/storage.ts.jinja +114 -0
  112. django_cfg/modules/django_client/core/generator/typescript.py +872 -0
  113. django_cfg/modules/django_client/core/groups/__init__.py +13 -0
  114. django_cfg/modules/django_client/core/groups/detector.py +178 -0
  115. django_cfg/modules/django_client/core/groups/manager.py +314 -0
  116. django_cfg/modules/django_client/core/ir/__init__.py +57 -0
  117. django_cfg/modules/django_client/core/ir/context.py +387 -0
  118. django_cfg/modules/django_client/core/ir/operation.py +518 -0
  119. django_cfg/modules/django_client/core/ir/schema.py +353 -0
  120. django_cfg/modules/django_client/core/parser/__init__.py +74 -0
  121. django_cfg/modules/django_client/core/parser/base.py +648 -0
  122. django_cfg/modules/django_client/core/parser/models/__init__.py +74 -0
  123. django_cfg/modules/django_client/core/parser/models/base.py +212 -0
  124. django_cfg/modules/django_client/core/parser/models/components.py +160 -0
  125. django_cfg/modules/django_client/core/parser/models/openapi.py +203 -0
  126. django_cfg/modules/django_client/core/parser/models/operation.py +207 -0
  127. django_cfg/modules/django_client/core/parser/models/schema.py +266 -0
  128. django_cfg/modules/django_client/core/parser/openapi30.py +56 -0
  129. django_cfg/modules/django_client/core/parser/openapi31.py +64 -0
  130. django_cfg/modules/django_client/core/validation/__init__.py +22 -0
  131. django_cfg/modules/django_client/core/validation/checker.py +134 -0
  132. django_cfg/modules/django_client/core/validation/fixer.py +216 -0
  133. django_cfg/modules/django_client/core/validation/reporter.py +480 -0
  134. django_cfg/modules/django_client/core/validation/rules/__init__.py +11 -0
  135. django_cfg/modules/django_client/core/validation/rules/base.py +96 -0
  136. django_cfg/modules/django_client/core/validation/rules/type_hints.py +288 -0
  137. django_cfg/modules/django_client/core/validation/safety.py +266 -0
  138. django_cfg/modules/django_client/management/__init__.py +3 -0
  139. django_cfg/modules/django_client/management/commands/__init__.py +3 -0
  140. django_cfg/modules/django_client/management/commands/generate_client.py +422 -0
  141. django_cfg/modules/django_client/management/commands/validate_openapi.py +343 -0
  142. django_cfg/modules/django_client/spectacular/__init__.py +9 -0
  143. django_cfg/modules/django_client/spectacular/enum_naming.py +192 -0
  144. django_cfg/modules/django_client/urls.py +72 -0
  145. django_cfg/modules/django_email/management/__init__.py +0 -0
  146. django_cfg/modules/django_email/management/commands/__init__.py +0 -0
  147. django_cfg/modules/django_email/management/commands/test_email.py +93 -0
  148. django_cfg/modules/django_logging/django_logger.py +6 -6
  149. django_cfg/modules/django_ngrok/management/__init__.py +0 -0
  150. django_cfg/modules/django_ngrok/management/commands/__init__.py +0 -0
  151. django_cfg/modules/django_ngrok/management/commands/runserver_ngrok.py +167 -0
  152. django_cfg/modules/django_tasks/management/__init__.py +0 -0
  153. django_cfg/modules/django_tasks/management/commands/__init__.py +0 -0
  154. django_cfg/modules/django_tasks/management/commands/rundramatiq.py +254 -0
  155. django_cfg/modules/django_tasks/management/commands/rundramatiq_simulator.py +437 -0
  156. django_cfg/modules/django_tasks/management/commands/task_clear.py +226 -0
  157. django_cfg/modules/django_tasks/management/commands/task_status.py +257 -0
  158. django_cfg/modules/django_telegram/management/__init__.py +0 -0
  159. django_cfg/modules/django_telegram/management/commands/__init__.py +0 -0
  160. django_cfg/modules/django_telegram/management/commands/test_telegram.py +68 -0
  161. django_cfg/modules/django_twilio/management/__init__.py +0 -0
  162. django_cfg/modules/django_twilio/management/commands/__init__.py +0 -0
  163. django_cfg/modules/django_twilio/management/commands/test_twilio.py +112 -0
  164. django_cfg/modules/django_unfold/callbacks/main.py +16 -5
  165. django_cfg/modules/django_unfold/callbacks/revolution.py +41 -36
  166. django_cfg/pyproject.toml +2 -6
  167. django_cfg/registry/third_party.py +5 -7
  168. django_cfg/routing/callbacks.py +1 -1
  169. django_cfg/static/admin/css/prose-unfold.css +666 -0
  170. django_cfg/templates/admin/index.html +8 -0
  171. django_cfg/templates/admin/index_new.html +13 -0
  172. django_cfg/templates/admin/layouts/dashboard_with_tabs.html +15 -3
  173. django_cfg/templates/admin/sections/documentation_section.html +172 -0
  174. django_cfg/templates/admin/snippets/tabs/documentation_tab.html +231 -0
  175. {django_cfg-1.4.10.dist-info → django_cfg-1.4.11.dist-info}/METADATA +2 -2
  176. {django_cfg-1.4.10.dist-info → django_cfg-1.4.11.dist-info}/RECORD +180 -59
  177. django_cfg/management/commands/generate.py +0 -107
  178. /django_cfg/models/django/{revolution.py → revolution_legacy.py} +0 -0
  179. {django_cfg-1.4.10.dist-info → django_cfg-1.4.11.dist-info}/WHEEL +0 -0
  180. {django_cfg-1.4.10.dist-info → django_cfg-1.4.11.dist-info}/entry_points.txt +0 -0
  181. {django_cfg-1.4.10.dist-info → django_cfg-1.4.11.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,391 @@
1
+ """Documentation section for dashboard."""
2
+
3
+ import os
4
+ import inspect
5
+ from pathlib import Path
6
+ from typing import Dict, Any, List
7
+ from django.core.management import get_commands, load_command_class
8
+ from .base import DataSection
9
+
10
+
11
+ class DocumentationSection(DataSection):
12
+ """
13
+ Management commands documentation section.
14
+
15
+ Displays the README.md file from django_cfg/management/ directory.
16
+ """
17
+
18
+ template_name = "admin/sections/documentation_section.html"
19
+ title = "Commands Documentation"
20
+ icon = "description"
21
+
22
+ def get_context_data(self, **kwargs) -> Dict[str, Any]:
23
+ """Add documentation data directly to context (not nested under 'data')."""
24
+ # Call parent but skip DataSection's get_data() nesting
25
+ context = super(DataSection, self).get_context_data(**kwargs)
26
+ # Add our data directly to context
27
+ context.update(self.get_data())
28
+ return context
29
+
30
+ def find_module_readme(self, module_name: str) -> str:
31
+ """Find and read README.md from module's management directory."""
32
+ import logging
33
+ logger = logging.getLogger(__name__)
34
+
35
+ try:
36
+ import django_cfg
37
+ django_cfg_path = Path(django_cfg.__file__).parent
38
+
39
+ # Try different paths
40
+ possible_paths = [
41
+ django_cfg_path / 'modules' / module_name / 'management' / 'README.md',
42
+ django_cfg_path / 'management' / 'commands' / module_name / 'README.md',
43
+ ]
44
+
45
+ for readme_path in possible_paths:
46
+ if readme_path.exists():
47
+ logger.info(f"Found module README at: {readme_path}")
48
+ with open(readme_path, 'r', encoding='utf-8') as f:
49
+ return f.read()
50
+ except Exception as e:
51
+ logger.debug(f"Could not find README for module {module_name}: {e}")
52
+
53
+ return ""
54
+
55
+ def get_commands_structure(self) -> Dict[str, List[Dict[str, Any]]]:
56
+ """Get structured command data grouped by app."""
57
+ import logging
58
+ logger = logging.getLogger(__name__)
59
+
60
+ # Get all management commands
61
+ commands = get_commands()
62
+
63
+ # Filter only django_cfg commands
64
+ django_cfg_commands = {
65
+ name: app for name, app in commands.items()
66
+ if 'django_cfg' in app
67
+ }
68
+
69
+ logger.info(f"Found {len(django_cfg_commands)} django_cfg commands")
70
+
71
+ # Group commands by app
72
+ commands_by_app = {}
73
+
74
+ for cmd_name, app_name in sorted(django_cfg_commands.items()):
75
+ try:
76
+ # Load the command class
77
+ try:
78
+ command = load_command_class(app_name, cmd_name)
79
+ except (ImportError, ModuleNotFoundError) as e:
80
+ logger.debug(f"Skipping command {cmd_name}: module not found - {e}")
81
+ continue
82
+
83
+ # Use app_name as group key
84
+ if app_name not in commands_by_app:
85
+ # Create display name from app_name
86
+ display_name = app_name.replace('django_cfg.modules.', '').replace('django_cfg', 'Django CFG').replace('_', ' ').title()
87
+
88
+ commands_by_app[app_name] = {
89
+ 'name': app_name,
90
+ 'display_name': display_name,
91
+ 'commands': []
92
+ }
93
+
94
+ # Extract command information
95
+ command_info = {
96
+ 'name': cmd_name,
97
+ 'help': getattr(command, 'help', 'No description available'),
98
+ 'docstring': inspect.cleandoc(command.__doc__) if command.__doc__ else '',
99
+ 'web_executable': getattr(command, 'web_executable', None),
100
+ 'requires_input': getattr(command, 'requires_input', None),
101
+ 'is_destructive': getattr(command, 'is_destructive', None),
102
+ 'arguments': []
103
+ }
104
+
105
+ # Get arguments
106
+ try:
107
+ parser = command.create_parser('', cmd_name)
108
+ actions = [action for action in parser._actions if action.dest != 'help']
109
+
110
+ for action in actions:
111
+ if action.option_strings:
112
+ command_info['arguments'].append({
113
+ 'options': action.option_strings,
114
+ 'help': action.help or 'No description',
115
+ 'default': action.default if action.default != '==SUPPRESS==' else None,
116
+ 'required': getattr(action, 'required', False),
117
+ })
118
+ except Exception as e:
119
+ logger.debug(f"Could not extract arguments for {cmd_name}: {e}")
120
+
121
+ commands_by_app[app_name]['commands'].append(command_info)
122
+
123
+ except Exception as e:
124
+ logger.error(f"Error loading command {cmd_name}: {e}")
125
+ continue
126
+
127
+ return commands_by_app
128
+
129
+ def generate_documentation_from_commands(self) -> str:
130
+ """Generate markdown documentation from command docstrings and module READMEs."""
131
+ import logging
132
+ logger = logging.getLogger(__name__)
133
+
134
+ markdown_lines = []
135
+ markdown_lines.append("# Django-CFG Management Commands\n\n")
136
+
137
+ # Check for main README.md
138
+ try:
139
+ import django_cfg
140
+ django_cfg_path = Path(django_cfg.__file__).parent
141
+ main_readme_path = django_cfg_path / 'management' / 'README.md'
142
+
143
+ if main_readme_path.exists():
144
+ logger.info("Found main management README.md, using it as primary documentation")
145
+ with open(main_readme_path, 'r', encoding='utf-8') as f:
146
+ return f.read() # Use existing README if it exists
147
+ except Exception as e:
148
+ logger.debug(f"No main README found, continuing with auto-generation: {e}")
149
+
150
+ markdown_lines.append("_Auto-generated documentation from command docstrings and module READMEs._\n\n")
151
+
152
+ # Get all management commands
153
+ commands = get_commands()
154
+
155
+ # Filter only django_cfg commands
156
+ django_cfg_commands = {
157
+ name: app for name, app in commands.items()
158
+ if 'django_cfg' in app
159
+ }
160
+
161
+ logger.info(f"Found {len(django_cfg_commands)} django_cfg commands")
162
+
163
+ # Group commands by module
164
+ commands_by_module = {}
165
+ module_paths = {} # Store module paths for README lookup
166
+
167
+ for cmd_name, app_name in sorted(django_cfg_commands.items()):
168
+ try:
169
+ # Load the command class
170
+ command = load_command_class(app_name, cmd_name)
171
+
172
+ # Get module path
173
+ module_path = command.__module__
174
+ if 'modules' in module_path:
175
+ # Extract module name like 'django_ngrok', 'django_tasks', etc.
176
+ parts = module_path.split('.')
177
+ if 'modules' in parts:
178
+ module_idx = parts.index('modules')
179
+ if len(parts) > module_idx + 1:
180
+ module_name = parts[module_idx + 1]
181
+ else:
182
+ module_name = 'core'
183
+ else:
184
+ module_name = 'core'
185
+ else:
186
+ module_name = 'core'
187
+
188
+ if module_name not in commands_by_module:
189
+ commands_by_module[module_name] = []
190
+ module_paths[module_name] = module_path
191
+
192
+ commands_by_module[module_name].append((cmd_name, command))
193
+
194
+ except Exception as e:
195
+ logger.error(f"Error loading command {cmd_name}: {e}")
196
+ continue
197
+
198
+ # Generate documentation for each module
199
+ for module_name in sorted(commands_by_module.keys()):
200
+ markdown_lines.append(f"\n## {module_name.replace('_', ' ').title()} Commands\n\n")
201
+
202
+ # Check for module-specific README
203
+ module_readme = self.find_module_readme(module_name)
204
+ if module_readme:
205
+ markdown_lines.append(f"_{module_name} module documentation:_\n\n")
206
+ markdown_lines.append(module_readme)
207
+ markdown_lines.append("\n\n### Available Commands\n\n")
208
+
209
+ for cmd_name, command_class in sorted(commands_by_module[module_name]):
210
+ markdown_lines.append(f"\n#### `{cmd_name}`\n\n")
211
+
212
+ # Get help text
213
+ if hasattr(command_class, 'help'):
214
+ markdown_lines.append(f"{command_class.help}\n\n")
215
+
216
+ # Get class docstring
217
+ if command_class.__doc__:
218
+ doc = inspect.cleandoc(command_class.__doc__)
219
+ markdown_lines.append(f"{doc}\n\n")
220
+
221
+ # Get metadata
222
+ metadata = []
223
+ if hasattr(command_class, 'web_executable'):
224
+ metadata.append(f"**Web Executable**: {'Yes' if command_class.web_executable else 'No'}")
225
+ if hasattr(command_class, 'requires_input'):
226
+ metadata.append(f"**Requires Input**: {'Yes' if command_class.requires_input else 'No'}")
227
+ if hasattr(command_class, 'is_destructive'):
228
+ metadata.append(f"**Destructive**: {'Yes' if command_class.is_destructive else 'No'}")
229
+
230
+ if metadata:
231
+ markdown_lines.append("**Metadata:**\n\n")
232
+ for meta in metadata:
233
+ markdown_lines.append(f"- {meta}\n")
234
+ markdown_lines.append("\n")
235
+
236
+ # Get arguments
237
+ try:
238
+ parser = command_class.create_parser('', cmd_name)
239
+ actions = [action for action in parser._actions if action.dest != 'help']
240
+
241
+ if actions:
242
+ markdown_lines.append("**Arguments:**\n\n")
243
+ for action in actions:
244
+ if action.option_strings:
245
+ opts = ', '.join(f"`{opt}`" for opt in action.option_strings)
246
+ help_text = action.help or 'No description'
247
+ markdown_lines.append(f"- {opts}: {help_text}\n")
248
+ markdown_lines.append("\n")
249
+ except Exception as e:
250
+ logger.debug(f"Could not extract arguments for {cmd_name}: {e}")
251
+
252
+ # Add usage example if available in docstring
253
+ if command_class.__doc__ and '```' in command_class.__doc__:
254
+ markdown_lines.append("**Example:**\n\n")
255
+
256
+ return ''.join(markdown_lines)
257
+
258
+ def get_data(self) -> Dict[str, Any]:
259
+ """Get structured command documentation data."""
260
+ import logging
261
+ logger = logging.getLogger(__name__)
262
+
263
+ try:
264
+ commands_structure = self.get_commands_structure()
265
+
266
+ return {
267
+ 'commands_by_module': commands_structure,
268
+ 'total_commands': sum(len(app['commands']) for app in commands_structure.values()),
269
+ 'total_modules': len(commands_structure),
270
+ }
271
+ except Exception as e:
272
+ logger.error(f"Error generating command structure: {e}", exc_info=True)
273
+ return {
274
+ 'commands_by_module': {},
275
+ 'total_commands': 0,
276
+ 'total_modules': 0,
277
+ 'error': str(e)
278
+ }
279
+
280
+ def get_data_old(self) -> Dict[str, Any]:
281
+ """DEPRECATED: Get documentation content from README.md or auto-generate from docstrings."""
282
+ import logging
283
+ logger = logging.getLogger(__name__)
284
+
285
+ # Check if we should use auto-generation
286
+ use_autogen = os.environ.get('DJANGO_CFG_AUTOGEN_DOCS', 'true').lower() == 'true'
287
+
288
+ readme_content = ""
289
+ documentation_html = ""
290
+ readme_path = None
291
+ readme_exists = False
292
+
293
+ if use_autogen:
294
+ # Auto-generate documentation from command docstrings
295
+ logger.info("Auto-generating documentation from command docstrings")
296
+ try:
297
+ readme_content = self.generate_documentation_from_commands()
298
+
299
+ # Convert to HTML
300
+ try:
301
+ import markdown
302
+ documentation_html = markdown.markdown(
303
+ readme_content,
304
+ extensions=[
305
+ 'markdown.extensions.fenced_code',
306
+ 'markdown.extensions.tables',
307
+ 'markdown.extensions.toc',
308
+ 'markdown.extensions.nl2br',
309
+ 'markdown.extensions.sane_lists',
310
+ ]
311
+ )
312
+ logger.info("Auto-generated documentation rendered successfully")
313
+ except ImportError:
314
+ logger.warning("Markdown library not available, will display as plain text")
315
+
316
+ readme_exists = True
317
+ readme_path = "Auto-generated from docstrings"
318
+
319
+ except Exception as e:
320
+ logger.error(f"Error auto-generating documentation: {e}", exc_info=True)
321
+ readme_content = f"Error auto-generating documentation: {str(e)}"
322
+ else:
323
+ # Use static README.md file
324
+ # Try multiple path resolution strategies
325
+ possible_paths = [
326
+ # Strategy 1: Relative to this file
327
+ Path(__file__).parent.parent.parent / 'management' / 'README.md',
328
+ # Strategy 2: Using django_cfg module location
329
+ Path(__file__).parent.parent.parent / 'management' / 'README.md',
330
+ # Strategy 3: Absolute path for django_cfg package
331
+ Path('/Users/markinmatrix/Documents/htdocs/@CARAPIS/encar_parser_new/@projects/django-cfg/projects/django-cfg-dev/src/django_cfg/management/README.md'),
332
+ ]
333
+
334
+ # Find the first existing path
335
+ for path in possible_paths:
336
+ if path.exists():
337
+ readme_path = path
338
+ logger.info(f"Found README.md at: {readme_path}")
339
+ break
340
+
341
+ # If still not found, try using django_cfg module import
342
+ if not readme_path or not readme_path.exists():
343
+ try:
344
+ import django_cfg
345
+ django_cfg_path = Path(django_cfg.__file__).parent
346
+ readme_path = django_cfg_path / 'management' / 'README.md'
347
+ logger.info(f"Using django_cfg module path: {readme_path}")
348
+ except Exception as e:
349
+ logger.error(f"Error finding django_cfg module: {e}")
350
+ readme_path = possible_paths[0] # Fallback to first path
351
+
352
+ try:
353
+ if readme_path and readme_path.exists():
354
+ logger.info(f"Reading README from: {readme_path}")
355
+ with open(readme_path, 'r', encoding='utf-8') as f:
356
+ readme_content = f.read()
357
+ logger.info(f"README content loaded: {len(readme_content)} characters")
358
+
359
+ # Try to convert markdown to HTML
360
+ try:
361
+ import markdown
362
+ documentation_html = markdown.markdown(
363
+ readme_content,
364
+ extensions=[
365
+ 'markdown.extensions.fenced_code',
366
+ 'markdown.extensions.tables',
367
+ 'markdown.extensions.toc',
368
+ 'markdown.extensions.nl2br',
369
+ 'markdown.extensions.sane_lists',
370
+ ]
371
+ )
372
+ logger.info("Markdown rendered successfully")
373
+ except ImportError:
374
+ logger.warning("Markdown library not available, will display as plain text")
375
+ pass
376
+
377
+ readme_exists = True
378
+ else:
379
+ logger.error(f"README.md not found at: {readme_path}")
380
+ readme_content = f"README.md not found. Searched paths:\n" + "\n".join(str(p) for p in possible_paths)
381
+
382
+ except Exception as e:
383
+ logger.error(f"Error loading documentation: {e}", exc_info=True)
384
+ readme_content = f"Error loading documentation: {str(e)}"
385
+
386
+ return {
387
+ 'readme_content': readme_content,
388
+ 'documentation_content': documentation_html if documentation_html else None,
389
+ 'readme_path': str(readme_path) if readme_path else 'Not found',
390
+ 'readme_exists': readme_exists,
391
+ }
@@ -1,169 +1,20 @@
1
1
  """
2
- Django management command to check all API endpoints status.
2
+ Django-CFG wrapper for check_endpoints command.
3
+
4
+ This is a simple alias for django_admin.management.commands.check_endpoints.
5
+ All logic is in django_admin module.
3
6
 
4
7
  Usage:
5
8
  python manage.py check_endpoints
6
- python manage.py check_endpoints --include-unnamed
7
- python manage.py check_endpoints --timeout 10
8
- python manage.py check_endpoints --json
9
9
  """
10
10
 
11
- from django.core.management.base import BaseCommand
12
- from django.urls import reverse
13
- from django_cfg.apps.api.endpoints.checker import check_all_endpoints
14
- import json
15
-
16
-
17
- class Command(BaseCommand):
18
- help = 'Check status of all Django CFG API endpoints'
19
-
20
- def add_arguments(self, parser):
21
- parser.add_argument(
22
- '--include-unnamed',
23
- action='store_true',
24
- help='Include unnamed URL patterns in the check',
25
- )
26
- parser.add_argument(
27
- '--timeout',
28
- type=int,
29
- default=5,
30
- help='Request timeout in seconds (default: 5)',
31
- )
32
- parser.add_argument(
33
- '--json',
34
- action='store_true',
35
- help='Output results as JSON',
36
- )
37
- parser.add_argument(
38
- '--url',
39
- type=str,
40
- help='Check specific endpoint by URL name (e.g., "endpoints_status")',
41
- )
42
- parser.add_argument(
43
- '--no-auth',
44
- action='store_true',
45
- help='Disable automatic JWT authentication retry (default: enabled)',
46
- )
47
-
48
- def handle(self, *args, **options):
49
- include_unnamed = options['include_unnamed']
50
- timeout = options['timeout']
51
- output_json = options['json']
52
- url_name = options.get('url')
53
- auto_auth = not options['no_auth'] # Auto-auth enabled by default
54
-
55
- # If specific URL requested, just resolve and display it
56
- if url_name:
57
- try:
58
- url = reverse(url_name)
59
- self.stdout.write(self.style.SUCCESS(f'✅ URL name "{url_name}" resolves to: {url}'))
60
- return
61
- except Exception as e:
62
- self.stdout.write(self.style.ERROR(f'❌ Error resolving URL "{url_name}": {e}'))
63
- return
64
-
65
- # Check all endpoints
66
- auth_msg = "with auto-auth" if auto_auth else "without auth"
67
- self.stdout.write(self.style.WARNING(f'🔍 Checking endpoints (timeout: {timeout}s, {auth_msg})...'))
68
-
69
- status_data = check_all_endpoints(
70
- include_unnamed=include_unnamed,
71
- timeout=timeout,
72
- auto_auth=auto_auth
73
- )
74
-
75
- # Output as JSON if requested
76
- if output_json:
77
- self.stdout.write(json.dumps(status_data, indent=2))
78
- return
79
-
80
- # Pretty print results
81
- self._print_results(status_data)
82
-
83
- def _print_results(self, data):
84
- """Print formatted results to console."""
85
-
86
- # Overall status
87
- status = data['status']
88
- if status == 'healthy':
89
- status_style = self.style.SUCCESS
90
- emoji = '✅'
91
- elif status == 'degraded':
92
- status_style = self.style.WARNING
93
- emoji = '⚠️'
94
- else:
95
- status_style = self.style.ERROR
96
- emoji = '❌'
97
-
98
- self.stdout.write('')
99
- self.stdout.write(status_style(f'{emoji} Overall Status: {status.upper()}'))
100
- self.stdout.write('')
101
-
102
- # Summary
103
- self.stdout.write(self.style.HTTP_INFO('📊 Summary:'))
104
- self.stdout.write(f' Total endpoints: {data["total_endpoints"]}')
105
- self.stdout.write(self.style.SUCCESS(f' ✅ Healthy: {data["healthy"]}'))
106
- self.stdout.write(self.style.WARNING(f' ⚠️ Warnings: {data["warnings"]}'))
107
- self.stdout.write(self.style.ERROR(f' ❌ Unhealthy: {data["unhealthy"]}'))
108
- self.stdout.write(self.style.ERROR(f' ❌ Errors: {data["errors"]}'))
109
- self.stdout.write(f' ⏭️ Skipped: {data["skipped"]}')
110
- self.stdout.write('')
111
-
112
- # Endpoints details
113
- self.stdout.write(self.style.HTTP_INFO('🔗 Endpoints:'))
114
-
115
- for endpoint in data['endpoints']:
116
- name = endpoint.get('url_name') or 'unnamed'
117
- url = endpoint['url']
118
- status = endpoint['status']
119
-
120
- if status == 'healthy':
121
- icon = '✅'
122
- style = self.style.SUCCESS
123
- elif status == 'degraded':
124
- icon = '⚠️'
125
- style = self.style.WARNING
126
- else:
127
- icon = '❌'
128
- style = self.style.ERROR
129
-
130
- self.stdout.write(f' {icon} {name}')
131
-
132
- # Show both pattern and resolved URL for parametrized endpoints
133
- if endpoint.get('has_parameters') and endpoint.get('url_pattern'):
134
- self.stdout.write(f' Pattern: {endpoint["url_pattern"]}')
135
- self.stdout.write(f' Resolved: {url}')
136
- else:
137
- self.stdout.write(f' URL: {url}')
138
-
139
- # Show status with status code
140
- status_code = endpoint.get('status_code')
141
- if status_code:
142
- self.stdout.write(style(f' Status: {status} ({status_code})'))
143
- else:
144
- self.stdout.write(style(f' Status: {status}'))
145
-
146
- if endpoint.get('response_time_ms'):
147
- self.stdout.write(f' Response time: {endpoint["response_time_ms"]:.2f}ms')
148
-
149
- if endpoint.get('error'):
150
- error_type = endpoint.get('error_type', 'general')
151
- if error_type == 'database':
152
- self.stdout.write(self.style.WARNING(f' ⚠️ DB Error (multi-db): {endpoint["error"]}'))
153
- else:
154
- self.stdout.write(self.style.ERROR(f' Error: {endpoint["error"]}'))
155
-
156
- # Show reason for warnings (e.g., 404 explanations)
157
- if endpoint.get('reason') and status == 'warning':
158
- self.stdout.write(self.style.WARNING(f' ⚠️ {endpoint["reason"]}'))
159
-
160
- if endpoint.get('required_auth'):
161
- self.stdout.write(f' 🔐 Required JWT authentication')
11
+ from django_cfg.modules.django_admin.management.commands.check_endpoints import Command as CheckEndpointsCommand
162
12
 
163
- if endpoint.get('rate_limited'):
164
- self.stdout.write(f' ⏱️ Rate limited (429)')
165
13
 
166
- self.stdout.write('')
14
+ class Command(CheckEndpointsCommand):
15
+ """
16
+ Alias for check_endpoints command.
167
17
 
168
- # Timestamp
169
- self.stdout.write(self.style.HTTP_INFO(f'🕐 Checked at: {data["timestamp"]}'))
18
+ Simply inherits from CheckEndpointsCommand without any changes.
19
+ """
20
+ pass