Skip to content

Commit a99c848

Browse files
committed
Support form search.
1 parent 7e4c602 commit a99c848

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

README.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ For example, open `/docker:root@container:/code/manage.py` instead of
155155
| <kbd>C-c ' q</kbd> | djangonaut-find-sql-function |
156156
| <kbd>C-c ' r</kbd> | djangonaut-find-signal-receiver |
157157
| <kbd>C-c ' s</kbd> | djangonaut-find-drf-serializer |
158+
| <kbd>C-c ' f</kbd> | djangonaut-find-form |
158159
| <kbd>C-c ' t</kbd> | djangonaut-find-template |
159160
| <kbd>C-c ' u</kbd> | djangonaut-find-url-module |
160161
| <kbd>C-c ' v</kbd> | djangonaut-find-view |

djangonaut.el

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 "
399416
from os import walk
400417
from 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

Comments
 (0)