@@ -412,6 +412,22 @@ for obj in get_objects():
412412
413413" " Python source code to get forms." )
414414
415+ (defvar djangonaut-get-widgets-code "
416+ from gc import get_objects
417+ from importlib import import_module
418+ from inspect import findsource, getsourcefile, getmodule, isclass
419+
420+ from django.forms.widgets import Widget
421+
422+ import_module(settings.ROOT_URLCONF)
423+
424+ for obj in get_objects():
425+ if isclass(obj) and issubclass(obj, Widget):
426+ name = getmodule(obj).__name__ + '.' + obj.__name__
427+ result[name] = [getsourcefile(obj), findsource(obj)[1]]
428+
429+ " " Python source code to get widgets." )
430+
415431(defvar djangonaut-get-templates-code "
416432from os import walk
417433from os.path import join
@@ -604,6 +620,8 @@ except:
604620
605621(defvar djangonaut-forms-history nil )
606622
623+ (defvar djangonaut-widgets-history nil )
624+
607625(defvar djangonaut-templates-history nil )
608626
609627(defvar djangonaut-template-tags-history nil )
@@ -768,6 +786,10 @@ user input. HIST is a variable to store history of choices."
768786 " Execute and parse python code to get forms."
769787 (djangonaut-read (djangonaut-call djangonaut-get-forms-code)))
770788
789+ (defun djangonaut-get-widgets ()
790+ " Execute and parse python code to get widgets."
791+ (djangonaut-read (djangonaut-call djangonaut-get-widgets-code)))
792+
771793(defun djangonaut-get-templates ()
772794 " Execute and parse python code to get templates."
773795 (djangonaut-read (djangonaut-call djangonaut-get-templates-code)))
@@ -974,6 +996,16 @@ user input. HIST is a variable to store history of choices."
974996 (interactive )
975997 (djangonaut-find-file-and-line #'find-file-other-window " Form: " (djangonaut-get-forms) 'djangonaut-forms-history ))
976998
999+ (defun djangonaut-find-widget ()
1000+ " Open definition of the Django widget."
1001+ (interactive )
1002+ (djangonaut-find-file-and-line #'find-file " Widget: " (djangonaut-get-widgets) 'djangonaut-widgets-history ))
1003+
1004+ (defun djangonaut-find-widget-other-window ()
1005+ " Open definition of the Django widget in the other window."
1006+ (interactive )
1007+ (djangonaut-find-file-and-line #'find-file-other-window " Widget: " (djangonaut-get-widgets) 'djangonaut-widgets-history ))
1008+
9771009(defun djangonaut-find-template ()
9781010 " Open definition of the Django template."
9791011 (interactive )
@@ -1043,6 +1075,7 @@ user input. HIST is a variable to store history of choices."
10431075 (define-key map (kbd " d" ) 'djangonaut-find-middleware )
10441076 (define-key map (kbd " u" ) 'djangonaut-find-url-module )
10451077 (define-key map (kbd " f" ) 'djangonaut-find-form )
1078+ (define-key map (kbd " w" ) 'djangonaut-find-widget )
10461079 (define-key map (kbd " t" ) 'djangonaut-find-template )
10471080 (define-key map (kbd " g" ) 'djangonaut-find-template-tag )
10481081 (define-key map (kbd " h" ) 'djangonaut-find-template-filter )
@@ -1062,6 +1095,7 @@ user input. HIST is a variable to store history of choices."
10621095 (define-key map (kbd " 4 d" ) 'djangonaut-find-middleware-other-window )
10631096 (define-key map (kbd " 4 u" ) 'djangonaut-find-url-module-other-window )
10641097 (define-key map (kbd " 4 f" ) 'djangonaut-find-form-other-window )
1098+ (define-key map (kbd " 4 w" ) 'djangonaut-find-widget-other-window )
10651099 (define-key map (kbd " 4 t" ) 'djangonaut-find-template-other-window )
10661100 (define-key map (kbd " 4 g" ) 'djangonaut-find-template-tag-other-window )
10671101 (define-key map (kbd " 4 h" ) 'djangonaut-find-template-filter-other-window )
@@ -1109,6 +1143,8 @@ user input. HIST is a variable to store history of choices."
11091143 :help " Open definition of the Django url module" ]
11101144 [" Find form" djangonaut-find-form
11111145 :help " Open definition of the Django form" ]
1146+ [" Find widget" djangonaut-find-widget
1147+ :help " Open definition of the Django widget" ]
11121148 [" Find template" djangonaut-find-template
11131149 :help " Open definition of the Django template" ]
11141150 [" Find template tag" djangonaut-find-template-tag
0 commit comments