@@ -6,7 +6,6 @@ use serde::Serialize;
66use crate :: db:: Db as ProjectDb ;
77use crate :: inspector;
88use crate :: inspector:: InspectorRequest ;
9- use crate :: python:: python_environment;
109use crate :: Project ;
1110
1211#[ derive( Serialize ) ]
@@ -20,70 +19,15 @@ impl InspectorRequest for DjangoInitRequest {
2019 type Response = DjangoInitResponse ;
2120}
2221
23- /// Initialize Django for the current project.
22+ /// Check if Django is available for the current project.
2423///
2524/// This tracked function attempts to initialize Django via the inspector.
2625/// Returns true if Django was successfully initialized, false otherwise.
2726#[ salsa:: tracked]
28- pub fn django_initialized ( db : & dyn ProjectDb , _project : Project ) -> bool {
27+ pub fn django_available ( db : & dyn ProjectDb , _project : Project ) -> bool {
2928 inspector:: query ( db, & DjangoInitRequest ) . is_some ( )
3029}
3130
32- /// Check if Django is available for the current project.
33- ///
34- /// This determines if Django is installed and configured in the Python environment.
35- /// First attempts to initialize Django, then falls back to environment detection.
36- #[ salsa:: tracked]
37- pub fn django_available ( db : & dyn ProjectDb , project : Project ) -> bool {
38- // Try to initialize Django
39- if django_initialized ( db, project) {
40- return true ;
41- }
42-
43- // Fallback to environment detection
44- python_environment ( db, project) . is_some ( )
45- }
46-
47- /// Get the Django settings module name for the current project.
48- ///
49- /// Returns `DJANGO_SETTINGS_MODULE` env var, or attempts to detect it
50- /// via common patterns.
51- #[ salsa:: tracked]
52- pub fn django_settings_module ( db : & dyn ProjectDb , project : Project ) -> Option < String > {
53- // Note: The django_init query doesn't return the settings module,
54- // it just initializes Django. So we detect it ourselves.
55-
56- // Check environment override first
57- if let Ok ( env_value) = std:: env:: var ( "DJANGO_SETTINGS_MODULE" ) {
58- if !env_value. is_empty ( ) {
59- return Some ( env_value) ;
60- }
61- }
62-
63- let project_path = project. root ( db) ;
64-
65- // Try to detect settings module
66- if project_path. join ( "manage.py" ) . exists ( ) {
67- // Look for common settings modules
68- for candidate in & [ "settings" , "config.settings" , "project.settings" ] {
69- let parts: Vec < & str > = candidate. split ( '.' ) . collect ( ) ;
70- let mut path = project_path. clone ( ) ;
71- for part in & parts[ ..parts. len ( ) - 1 ] {
72- path = path. join ( part) ;
73- }
74- if let Some ( last) = parts. last ( ) {
75- path = path. join ( format ! ( "{last}.py" ) ) ;
76- }
77-
78- if path. exists ( ) {
79- return Some ( ( * candidate) . to_string ( ) ) ;
80- }
81- }
82- }
83-
84- None
85- }
86-
8731#[ derive( Serialize ) ]
8832struct TemplatetagsRequest ;
8933
@@ -103,6 +47,8 @@ impl InspectorRequest for TemplatetagsRequest {
10347#[ salsa:: tracked]
10448pub fn templatetags ( db : & dyn ProjectDb , _project : Project ) -> Option < TemplateTags > {
10549 let response = inspector:: query ( db, & TemplatetagsRequest ) ?;
50+ let tag_count = response. templatetags . len ( ) ;
51+ tracing:: debug!( "Retrieved {} templatetags from inspector" , tag_count) ;
10652 Some ( TemplateTags ( response. templatetags ) )
10753}
10854
0 commit comments