@@ -395,6 +395,23 @@ collect_url_modules(get_resolver(get_urlconf()))
395395
396396" " Python source code to get url modules." )
397397
398+ (defvar djangonaut-get-forms-code "
399+ from gc import get_objects
400+ from importlib import import_module
401+ from inspect import findsource, getsourcefile, getmodule, isclass
402+
403+ from django.forms.forms import BaseForm
404+ from django.forms.formsets import BaseFormSet
405+
406+ import_module(settings.ROOT_URLCONF)
407+
408+ for obj in get_objects():
409+ if isclass(obj) and issubclass(obj, (BaseForm, BaseFormSet)):
410+ name = getmodule(obj).__name__ + '.' + obj.__name__
411+ result[name] = [getsourcefile(obj), findsource(obj)[1]]
412+
413+ " " Python source code to get forms." )
414+
398415(defvar djangonaut-get-templates-code "
399416from os import walk
400417from os.path import join
@@ -585,6 +602,8 @@ except:
585602
586603(defvar djangonaut-url-modules-history nil )
587604
605+ (defvar djangonaut-forms-history nil )
606+
588607(defvar djangonaut-templates-history nil )
589608
590609(defvar djangonaut-template-tags-history nil )
@@ -745,6 +764,10 @@ user input. HIST is a variable to store history of choices."
745764 " Execute and parse python code to get url modules."
746765 (djangonaut-read (djangonaut-call djangonaut-get-url-modules-code)))
747766
767+ (defun djangonaut-get-forms ()
768+ " Execute and parse python code to get forms."
769+ (djangonaut-read (djangonaut-call djangonaut-get-forms-code)))
770+
748771(defun djangonaut-get-templates ()
749772 " Execute and parse python code to get templates."
750773 (djangonaut-read (djangonaut-call djangonaut-get-templates-code)))
@@ -941,6 +964,16 @@ user input. HIST is a variable to store history of choices."
941964 (interactive )
942965 (djangonaut-find-file #'find-file-other-window " URL Module: " (djangonaut-get-url-modules) 'djangonaut-url-modules-history ))
943966
967+ (defun djangonaut-find-form ()
968+ " Open definition of the Django form."
969+ (interactive )
970+ (djangonaut-find-file-and-line #'find-file " Form: " (djangonaut-get-forms) 'djangonaut-forms-history ))
971+
972+ (defun djangonaut-find-form-other-window ()
973+ " Open definition of the Django form in the other window."
974+ (interactive )
975+ (djangonaut-find-file-and-line #'find-file-other-window " Form: " (djangonaut-get-forms) 'djangonaut-forms-history ))
976+
944977(defun djangonaut-find-template ()
945978 " Open definition of the Django template."
946979 (interactive )
@@ -1009,6 +1042,7 @@ user input. HIST is a variable to store history of choices."
10091042 (define-key map (kbd " v" ) 'djangonaut-find-view )
10101043 (define-key map (kbd " d" ) 'djangonaut-find-middleware )
10111044 (define-key map (kbd " u" ) 'djangonaut-find-url-module )
1045+ (define-key map (kbd " f" ) 'djangonaut-find-form )
10121046 (define-key map (kbd " t" ) 'djangonaut-find-template )
10131047 (define-key map (kbd " g" ) 'djangonaut-find-template-tag )
10141048 (define-key map (kbd " h" ) 'djangonaut-find-template-filter )
@@ -1027,6 +1061,7 @@ user input. HIST is a variable to store history of choices."
10271061 (define-key map (kbd " 4 v" ) 'djangonaut-find-view-other-window )
10281062 (define-key map (kbd " 4 d" ) 'djangonaut-find-middleware-other-window )
10291063 (define-key map (kbd " 4 u" ) 'djangonaut-find-url-module-other-window )
1064+ (define-key map (kbd " 4 f" ) 'djangonaut-find-form-other-window )
10301065 (define-key map (kbd " 4 t" ) 'djangonaut-find-template-other-window )
10311066 (define-key map (kbd " 4 g" ) 'djangonaut-find-template-tag-other-window )
10321067 (define-key map (kbd " 4 h" ) 'djangonaut-find-template-filter-other-window )
@@ -1072,6 +1107,8 @@ user input. HIST is a variable to store history of choices."
10721107 :help " Open definition of the Django middleware" ]
10731108 [" Find url module" djangonaut-find-url-module
10741109 :help " Open definition of the Django url module" ]
1110+ [" Find form" djangonaut-find-form
1111+ :help " Open definition of the Django form" ]
10751112 [" Find template" djangonaut-find-template
10761113 :help " Open definition of the Django template" ]
10771114 [" Find template tag" djangonaut-find-template-tag
0 commit comments