django-lucy-assist 1.2.2__tar.gz → 1.2.3__tar.gz

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 (57) hide show
  1. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/PKG-INFO +1 -1
  2. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/django_lucy_assist.egg-info/PKG-INFO +1 -1
  3. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/django_lucy_assist.egg-info/SOURCES.txt +2 -0
  4. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/__init__.py +1 -1
  5. django_lucy_assist-1.2.3/lucy_assist/admin.py +109 -0
  6. django_lucy_assist-1.2.3/lucy_assist/migrations/0005_configurationlucyassist_project_context.py +22 -0
  7. django_lucy_assist-1.2.3/lucy_assist/migrations/0006_remove_configurationlucyassist_prompt_complementaire.py +17 -0
  8. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/models/configuration.py +120 -12
  9. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/pyproject.toml +1 -1
  10. django_lucy_assist-1.2.2/lucy_assist/admin.py +0 -76
  11. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/MANIFEST.in +0 -0
  12. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/README.md +0 -0
  13. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/django_lucy_assist.egg-info/dependency_links.txt +0 -0
  14. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/django_lucy_assist.egg-info/requires.txt +0 -0
  15. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/django_lucy_assist.egg-info/top_level.txt +0 -0
  16. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/apps.py +0 -0
  17. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/conf.py +0 -0
  18. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/constantes.py +0 -0
  19. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/context_processors.py +0 -0
  20. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/migrations/0001_initial.py +0 -0
  21. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/migrations/0002_configurationlucyassist_prompt_complementaire.py +0 -0
  22. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/migrations/0003_configurationlucyassist_crud_views_mapping.py +0 -0
  23. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/migrations/0004_configurationlucyassist_system_prompt.py +0 -0
  24. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/migrations/__init__.py +0 -0
  25. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/models/__init__.py +0 -0
  26. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/models/base.py +0 -0
  27. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/models/conversation.py +0 -0
  28. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/models/message.py +0 -0
  29. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/models/project_context_cache.py +0 -0
  30. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/services/__init__.py +0 -0
  31. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/services/bug_notification_service.py +0 -0
  32. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/services/context_service.py +0 -0
  33. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/services/crud_service.py +0 -0
  34. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/services/gitlab_service.py +0 -0
  35. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/services/mistral_service.py +0 -0
  36. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/services/project_context_service.py +0 -0
  37. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/services/tool_executor_service.py +0 -0
  38. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/services/tools_definition.py +0 -0
  39. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/services/view_discovery_service.py +0 -0
  40. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/signals.py +0 -0
  41. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/static/lucy_assist/css/lucy-assist.css +0 -0
  42. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/static/lucy_assist/image/icon-lucy.png +0 -0
  43. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/static/lucy_assist/js/lucy-assist.js +0 -0
  44. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/templates/lucy_assist/chatbot_sidebar.html +0 -0
  45. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/templates/lucy_assist/partials/documentation_content.html +0 -0
  46. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/tests/__init__.py +0 -0
  47. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/tests/factories/__init__.py +0 -0
  48. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/tests/factories/lucy_assist_factories.py +0 -0
  49. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/tests/test_lucy_assist.py +0 -0
  50. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/urls.py +0 -0
  51. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/utils/__init__.py +0 -0
  52. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/utils/log_utils.py +0 -0
  53. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/utils/message_utils.py +0 -0
  54. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/utils/token_utils.py +0 -0
  55. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/views/__init__.py +0 -0
  56. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/lucy_assist/views/api_views.py +0 -0
  57. {django_lucy_assist-1.2.2 → django_lucy_assist-1.2.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: django-lucy-assist
3
- Version: 1.2.2
3
+ Version: 1.2.3
4
4
  Summary: Assistant IA intelligent Revolucy pour outil métier
5
5
  Author-email: Revolucy <hello@revolucy.fr>
6
6
  Maintainer-email: Maxence <hello@revolucy.fr>
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: django-lucy-assist
3
- Version: 1.2.2
3
+ Version: 1.2.3
4
4
  Summary: Assistant IA intelligent Revolucy pour outil métier
5
5
  Author-email: Revolucy <hello@revolucy.fr>
6
6
  Maintainer-email: Maxence <hello@revolucy.fr>
@@ -18,6 +18,8 @@ lucy_assist/migrations/0001_initial.py
18
18
  lucy_assist/migrations/0002_configurationlucyassist_prompt_complementaire.py
19
19
  lucy_assist/migrations/0003_configurationlucyassist_crud_views_mapping.py
20
20
  lucy_assist/migrations/0004_configurationlucyassist_system_prompt.py
21
+ lucy_assist/migrations/0005_configurationlucyassist_project_context.py
22
+ lucy_assist/migrations/0006_remove_configurationlucyassist_prompt_complementaire.py
21
23
  lucy_assist/migrations/__init__.py
22
24
  lucy_assist/models/__init__.py
23
25
  lucy_assist/models/base.py
@@ -5,7 +5,7 @@ Un chatbot IA base sur Mistral AI, integrable dans n'importe quelle
5
5
  application Django pour fournir une assistance contextuelle aux utilisateurs.
6
6
  """
7
7
 
8
- __version__ = '1.2.2'
8
+ __version__ = '1.2.3'
9
9
  __author__ = 'Revolucy'
10
10
 
11
11
  default_app_config = 'lucy_assist.apps.LucyAssistConfig'
@@ -0,0 +1,109 @@
1
+ from django.contrib import admin
2
+
3
+ from lucy_assist.models import Conversation, Message, ConfigurationLucyAssist
4
+
5
+
6
+ class BlockMessage(admin.StackedInline):
7
+ model = Message
8
+ extra = 1
9
+
10
+
11
+ @admin.register(Conversation)
12
+ class ConversationAdmin(admin.ModelAdmin):
13
+ list_display = ('id', 'utilisateur', 'titre', 'created_date', 'is_active')
14
+ list_filter = ('is_active', 'created_date')
15
+ search_fields = ('utilisateur__email', 'titre')
16
+ ordering = ('-created_date',)
17
+ inlines = [BlockMessage]
18
+
19
+
20
+ @admin.register(ConfigurationLucyAssist)
21
+ class ConfigurationLucyAssistAdmin(admin.ModelAdmin):
22
+ list_display = ('id', 'tokens_disponibles', 'prix_par_million_tokens', 'nb_vues_crud', 'has_project_context', 'updated_date')
23
+ readonly_fields = ('crud_views_mapping_display', 'model_app_mapping_display', 'project_context_display')
24
+ fieldsets = (
25
+ ('Configuration Tokens', {
26
+ 'fields': ('tokens_disponibles', 'prix_par_million_tokens', 'actif')
27
+ }),
28
+ ('Personnalisation', {
29
+ 'fields': ('avatar', 'questions_frequentes')
30
+ }),
31
+ ('Prompt Systeme', {
32
+ 'fields': ('system_prompt',),
33
+ 'classes': ('collapse',),
34
+ 'description': 'Le prompt systeme est initialise automatiquement si vide.'
35
+ }),
36
+ ('Contexte Projet GitLab', {
37
+ 'fields': ('project_context_display',),
38
+ 'classes': ('collapse',),
39
+ 'description': 'Analyse du projet depuis GitLab. Utilisez l\'action "Rafraichir le contexte projet" pour mettre a jour.'
40
+ }),
41
+ ('Mapping Automatique (lecture seule)', {
42
+ 'fields': ('crud_views_mapping_display', 'model_app_mapping_display'),
43
+ 'classes': ('collapse',)
44
+ }),
45
+ )
46
+ actions = ['refresh_crud_views', 'refresh_project_context']
47
+
48
+ def nb_vues_crud(self, obj):
49
+ """Affiche le nombre de modeles avec des vues CRUD decouvertes."""
50
+ if obj.crud_views_mapping:
51
+ return len(obj.crud_views_mapping)
52
+ return 0
53
+ nb_vues_crud.short_description = "Modeles CRUD"
54
+
55
+ def has_project_context(self, obj):
56
+ """Indique si le contexte projet est configure."""
57
+ return bool(obj.project_context)
58
+ has_project_context.short_description = "Contexte GitLab"
59
+ has_project_context.boolean = True
60
+
61
+ def crud_views_mapping_display(self, obj):
62
+ """Affiche le mapping des vues CRUD de manière lisible."""
63
+ import json
64
+ if obj.crud_views_mapping:
65
+ return json.dumps(obj.crud_views_mapping, indent=2, ensure_ascii=False)
66
+ return "Aucune vue découverte. Utilisez l'action 'Rafraîchir les vues CRUD'."
67
+ crud_views_mapping_display.short_description = "Vues CRUD découvertes"
68
+
69
+ def model_app_mapping_display(self, obj):
70
+ """Affiche le mapping modele -> app de maniere lisible."""
71
+ import json
72
+ if obj.model_app_mapping:
73
+ return json.dumps(obj.model_app_mapping, indent=2, ensure_ascii=False)
74
+ return "Aucun mapping. Sera construit automatiquement."
75
+ model_app_mapping_display.short_description = "Mapping Modele -> App"
76
+
77
+ def project_context_display(self, obj):
78
+ """Affiche le contexte projet analyse depuis GitLab."""
79
+ if obj.project_context:
80
+ return obj.project_context
81
+ return "Aucun contexte. Utilisez l'action 'Rafraichir le contexte projet' ou configurez GitLab."
82
+ project_context_display.short_description = "Contexte Projet"
83
+
84
+ @admin.action(description="Rafraichir les vues CRUD decouvertes")
85
+ def refresh_crud_views(self, request, queryset):
86
+ """Action admin pour rafraichir le mapping des vues CRUD."""
87
+ for config in queryset:
88
+ mapping = config.refresh_crud_views_mapping()
89
+ nb_models = len(mapping)
90
+ nb_views = sum(len(actions) for actions in mapping.values())
91
+ self.message_user(
92
+ request,
93
+ f"Mapping rafraichi: {nb_models} modeles, {nb_views} vues decouvertes."
94
+ )
95
+
96
+ @admin.action(description="Rafraichir le contexte projet (GitLab)")
97
+ def refresh_project_context(self, request, queryset):
98
+ """Action admin pour analyser le projet depuis GitLab."""
99
+ for config in queryset:
100
+ result = config.refresh_project_context()
101
+ if "non configure" in result.lower():
102
+ self.message_user(request, result, level='warning')
103
+ else:
104
+ # Compter les lignes pour donner une idee de la taille
105
+ nb_lines = len(result.split('\n'))
106
+ self.message_user(
107
+ request,
108
+ f"Contexte projet rafraichi: {nb_lines} lignes d'analyse."
109
+ )
@@ -0,0 +1,22 @@
1
+ # Generated by Django
2
+
3
+ from django.db import migrations, models
4
+
5
+
6
+ class Migration(migrations.Migration):
7
+
8
+ dependencies = [
9
+ ('lucy_assist', '0004_configurationlucyassist_system_prompt'),
10
+ ]
11
+
12
+ operations = [
13
+ migrations.AddField(
14
+ model_name='configurationlucyassist',
15
+ name='project_context',
16
+ field=models.TextField(
17
+ blank=True,
18
+ default='',
19
+ help_text="Contexte du projet analyse depuis GitLab. Rafraichir via l'action admin."
20
+ ),
21
+ ),
22
+ ]
@@ -0,0 +1,17 @@
1
+ # Generated by Django
2
+
3
+ from django.db import migrations
4
+
5
+
6
+ class Migration(migrations.Migration):
7
+
8
+ dependencies = [
9
+ ('lucy_assist', '0005_configurationlucyassist_project_context'),
10
+ ]
11
+
12
+ operations = [
13
+ migrations.RemoveField(
14
+ model_name='configurationlucyassist',
15
+ name='prompt_complementaire',
16
+ ),
17
+ ]
@@ -21,16 +21,12 @@ class ConfigurationLucyAssist(LucyAssistBaseModel):
21
21
  avatar = models.ImageField(null=True, blank=True)
22
22
 
23
23
  # Prompt système principal pour l'assistant
24
- # Initialisé automatiquement via signal si vide
24
+ # Initialisé automatiquement si vide
25
25
  system_prompt = models.TextField(
26
26
  blank=True,
27
27
  default='',
28
- help_text="Prompt système pour l'assistant IA. Initialisé automatiquement si vide."
29
28
  )
30
29
 
31
- # Instructions complémentaires pour le prompt (ajoutées après le system_prompt)
32
- prompt_complementaire = models.TextField(blank=True, default='')
33
-
34
30
  # Mapping des modèles vers leurs applications Django
35
31
  model_app_mapping = models.JSONField(blank=True, default=dict)
36
32
 
@@ -45,6 +41,13 @@ class ConfigurationLucyAssist(LucyAssistBaseModel):
45
41
  # }
46
42
  crud_views_mapping = models.JSONField(blank=True, default=dict)
47
43
 
44
+ # Contexte du projet analyse depuis GitLab
45
+ # Contient une description detaillee du projet, ses fonctionnalites, modeles, etc.
46
+ project_context = models.TextField(
47
+ blank=True,
48
+ default='',
49
+ )
50
+
48
51
  class Meta:
49
52
  verbose_name = "Configuration Lucy Assist"
50
53
  verbose_name_plural = "Configuration Lucy Assist"
@@ -245,15 +248,15 @@ class ConfigurationLucyAssist(LucyAssistBaseModel):
245
248
  available_models: str = ""
246
249
  ) -> str:
247
250
  """
248
- Retourne le prompt système formaté avec les variables de contexte.
251
+ Retourne le prompt systeme formate avec les variables de contexte.
249
252
 
250
253
  Args:
251
254
  page_context: Contexte JSON de la page actuelle
252
255
  user_permissions: Liste des permissions de l'utilisateur
253
- available_models: Liste des modèles disponibles
256
+ available_models: Liste des modeles disponibles
254
257
 
255
258
  Returns:
256
- Prompt système complet avec le prompt_complementaire ajouté
259
+ Prompt systeme complet avec le project_context
257
260
  """
258
261
  prompt = self.system_prompt
259
262
 
@@ -265,9 +268,9 @@ class ConfigurationLucyAssist(LucyAssistBaseModel):
265
268
  available_models=available_models
266
269
  )
267
270
 
268
- # Ajouter les instructions complémentaires si configurées
269
- if self.prompt_complementaire:
270
- prompt += f"\n\n## Instructions complémentaires\n{self.prompt_complementaire}"
271
+ # Ajouter le contexte du projet (analyse GitLab) si disponible
272
+ if self.project_context:
273
+ prompt += f"\n\n## Contexte du projet (analyse du code source)\n{self.project_context}"
271
274
 
272
275
  return prompt
273
276
 
@@ -319,7 +322,112 @@ class ConfigurationLucyAssist(LucyAssistBaseModel):
319
322
  fields_str += ", ..."
320
323
  descriptions.append(f"- {model_name} ({model_name_lower}) : {fields_str}")
321
324
 
322
- return "\n".join(descriptions) if descriptions else "Aucun modèle configuré"
325
+ return "\n".join(descriptions) if descriptions else "Aucun modele configure"
326
+
327
+ def refresh_project_context(self) -> str:
328
+ """
329
+ Analyse le projet GitLab et genere un contexte detaille.
330
+ Necessite GITLAB_TOKEN, GITLAB_URL et GITLAB_PROJECT_ID configures.
331
+
332
+ Returns:
333
+ Le contexte genere ou un message d'erreur
334
+ """
335
+ from lucy_assist.services.gitlab_service import GitLabService
336
+
337
+ gitlab = GitLabService()
338
+
339
+ # Verifier que GitLab est configure
340
+ if not gitlab.token or not gitlab.project_id:
341
+ return "GitLab non configure. Definissez GITLAB_TOKEN, GITLAB_URL et GITLAB_PROJECT_ID."
342
+
343
+ context_parts = []
344
+ app_name = self._get_application_name()
345
+ context_parts.append(f"# Analyse du projet {app_name}\n")
346
+
347
+ # 1. Analyser la structure du projet (fichiers apps.py)
348
+ apps_search = gitlab.search_code("class.*Config.*AppConfig", per_page=20)
349
+ if apps_search:
350
+ context_parts.append("## Applications Django")
351
+ apps_found = []
352
+ for result in apps_search:
353
+ filename = result.get('filename', '')
354
+ if 'apps.py' in filename:
355
+ # Extraire le nom de l'app
356
+ parts = filename.split('/')
357
+ if len(parts) >= 2:
358
+ apps_found.append(parts[-2])
359
+ if apps_found:
360
+ context_parts.append(f"Applications trouvees: {', '.join(set(apps_found))}\n")
361
+
362
+ # 2. Analyser les modeles principaux
363
+ models_search = gitlab.search_code("class.*models.Model", per_page=30)
364
+ if models_search:
365
+ context_parts.append("## Modeles principaux")
366
+ models_info = {}
367
+ for result in models_search:
368
+ filename = result.get('filename', '')
369
+ data = result.get('data', '')
370
+ if 'models' in filename and 'class ' in data:
371
+ # Extraire le nom du modele
372
+ import re
373
+ match = re.search(r'class\s+(\w+)\s*\(', data)
374
+ if match:
375
+ model_name = match.group(1)
376
+ if model_name not in ('Meta', 'Manager'):
377
+ # Recuperer plus de details sur le modele
378
+ model_detail = gitlab.find_model_and_form(model_name)
379
+ if model_detail.get('model_code'):
380
+ # Extraire les champs
381
+ fields = re.findall(
382
+ r'(\w+)\s*=\s*models\.(\w+)',
383
+ model_detail['model_code']
384
+ )
385
+ if fields:
386
+ models_info[model_name] = [f[0] for f in fields[:10]]
387
+
388
+ for model_name, fields in list(models_info.items())[:15]:
389
+ context_parts.append(f"- {model_name}: {', '.join(fields)}")
390
+ context_parts.append("")
391
+
392
+ # 3. Analyser les vues principales
393
+ views_search = gitlab.search_code("class.*View.*", per_page=20)
394
+ if views_search:
395
+ context_parts.append("## Vues principales")
396
+ views_found = set()
397
+ for result in views_search:
398
+ filename = result.get('filename', '')
399
+ data = result.get('data', '')
400
+ if 'views' in filename and 'class ' in data:
401
+ import re
402
+ match = re.search(r'class\s+(\w+View)\s*\(', data)
403
+ if match:
404
+ views_found.add(match.group(1))
405
+ if views_found:
406
+ context_parts.append(f"Vues: {', '.join(list(views_found)[:20])}\n")
407
+
408
+ # 4. Analyser le README si present
409
+ readme_content = gitlab.get_file_content('README.md')
410
+ if readme_content:
411
+ context_parts.append("## Description du projet (README)")
412
+ # Garder les 500 premiers caracteres du README
413
+ context_parts.append(readme_content[:500])
414
+ if len(readme_content) > 500:
415
+ context_parts.append("...\n")
416
+
417
+ # 5. Recuperer les commits recents pour comprendre l'activite
418
+ commits = gitlab.get_recent_commits(per_page=5)
419
+ if commits:
420
+ context_parts.append("## Commits recents")
421
+ for commit in commits:
422
+ context_parts.append(f"- {commit['message']}")
423
+ context_parts.append("")
424
+
425
+ # Assembler le contexte
426
+ self.project_context = "\n".join(context_parts)
427
+ self.save(update_fields=['project_context'])
428
+ cache.delete('lucy_assist_config')
429
+
430
+ return self.project_context
323
431
 
324
432
 
325
433
  def get_default_model_app_mapping() -> dict:
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "django-lucy-assist"
7
- version = "1.2.2"
7
+ version = "1.2.3"
8
8
  description = "Assistant IA intelligent Revolucy pour outil métier"
9
9
  readme = "README.md"
10
10
  license = {text = "MIT"}
@@ -1,76 +0,0 @@
1
- from django.contrib import admin
2
-
3
- from lucy_assist.models import Conversation, Message, ConfigurationLucyAssist
4
-
5
-
6
- class BlockMessage(admin.StackedInline):
7
- model = Message
8
- extra = 1
9
-
10
-
11
- @admin.register(Conversation)
12
- class ConversationAdmin(admin.ModelAdmin):
13
- list_display = ('id', 'utilisateur', 'titre', 'created_date', 'is_active')
14
- list_filter = ('is_active', 'created_date')
15
- search_fields = ('utilisateur__email', 'titre')
16
- ordering = ('-created_date',)
17
- inlines = [BlockMessage]
18
-
19
-
20
- @admin.register(ConfigurationLucyAssist)
21
- class ConfigurationLucyAssistAdmin(admin.ModelAdmin):
22
- list_display = ('id', 'tokens_disponibles', 'prix_par_million_tokens', 'nb_vues_crud', 'updated_date')
23
- readonly_fields = ('crud_views_mapping_display', 'model_app_mapping_display')
24
- fieldsets = (
25
- ('Configuration Tokens', {
26
- 'fields': ('tokens_disponibles', 'prix_par_million_tokens', 'actif')
27
- }),
28
- ('Personnalisation', {
29
- 'fields': ('avatar', 'questions_frequentes')
30
- }),
31
- ('Prompt Système', {
32
- 'fields': ('system_prompt', 'prompt_complementaire'),
33
- 'classes': ('collapse',),
34
- 'description': 'Le prompt système est initialisé automatiquement si vide. Le prompt complémentaire est ajouté à la fin.'
35
- }),
36
- ('Mapping Automatique (lecture seule)', {
37
- 'fields': ('crud_views_mapping_display', 'model_app_mapping_display'),
38
- 'classes': ('collapse',)
39
- }),
40
- )
41
- actions = ['refresh_crud_views']
42
-
43
- def nb_vues_crud(self, obj):
44
- """Affiche le nombre de modèles avec des vues CRUD découvertes."""
45
- if obj.crud_views_mapping:
46
- return len(obj.crud_views_mapping)
47
- return 0
48
- nb_vues_crud.short_description = "Modèles CRUD"
49
-
50
- def crud_views_mapping_display(self, obj):
51
- """Affiche le mapping des vues CRUD de manière lisible."""
52
- import json
53
- if obj.crud_views_mapping:
54
- return json.dumps(obj.crud_views_mapping, indent=2, ensure_ascii=False)
55
- return "Aucune vue découverte. Utilisez l'action 'Rafraîchir les vues CRUD'."
56
- crud_views_mapping_display.short_description = "Vues CRUD découvertes"
57
-
58
- def model_app_mapping_display(self, obj):
59
- """Affiche le mapping modèle -> app de manière lisible."""
60
- import json
61
- if obj.model_app_mapping:
62
- return json.dumps(obj.model_app_mapping, indent=2, ensure_ascii=False)
63
- return "Aucun mapping. Sera construit automatiquement."
64
- model_app_mapping_display.short_description = "Mapping Modèle -> App"
65
-
66
- @admin.action(description="Rafraîchir les vues CRUD découvertes")
67
- def refresh_crud_views(self, request, queryset):
68
- """Action admin pour rafraîchir le mapping des vues CRUD."""
69
- for config in queryset:
70
- mapping = config.refresh_crud_views_mapping()
71
- nb_models = len(mapping)
72
- nb_views = sum(len(actions) for actions in mapping.values())
73
- self.message_user(
74
- request,
75
- f"Mapping rafraîchi: {nb_models} modèles, {nb_views} vues découvertes."
76
- )