MCPcopy
hub / github.com/django/django / handle

Method handle

django/core/management/templates.py:88–234  ·  view source on GitHub ↗
(self, app_or_project, name, target=None, **options)

Source from the content-addressed store, hash-verified

86 )
87
88 def handle(self, app_or_project, name, target=None, **options):
89 self.app_or_project = app_or_project
90 self.a_or_an = "an" if app_or_project == "app" else "a"
91 self.paths_to_remove = []
92 self.verbosity = options["verbosity"]
93
94 self.validate_name(name)
95
96 # if some directory is given, make sure it's nicely expanded
97 if target is None:
98 top_dir = os.path.join(os.getcwd(), name)
99 try:
100 os.makedirs(top_dir)
101 except FileExistsError:
102 raise CommandError("'%s' already exists" % top_dir)
103 except OSError as e:
104 raise CommandError(e)
105 else:
106 top_dir = os.path.abspath(os.path.expanduser(target))
107 if app_or_project == "app":
108 self.validate_name(os.path.basename(top_dir), "directory")
109 if not os.path.exists(top_dir):
110 try:
111 os.makedirs(top_dir)
112 except OSError as e:
113 raise CommandError(e)
114
115 # Find formatters, which are external executables, before input
116 # from the templates can sneak into the path.
117 formatter_paths = find_formatters()
118
119 extensions = tuple(handle_extensions(options["extensions"]))
120 extra_files = []
121 excluded_directories = [".git", "__pycache__"]
122 for file in options["files"]:
123 extra_files.extend(map(lambda x: x.strip(), file.split(",")))
124 if exclude := options.get("exclude"):
125 for directory in exclude:
126 excluded_directories.append(directory.strip())
127 if self.verbosity >= 2:
128 self.stdout.write(
129 "Rendering %s template files with extensions: %s"
130 % (app_or_project, ", ".join(extensions))
131 )
132 self.stdout.write(
133 "Rendering %s template files with filenames: %s"
134 % (app_or_project, ", ".join(extra_files))
135 )
136 base_name = "%s_name" % app_or_project
137 base_subdir = "%s_template" % app_or_project
138 base_directory = "%s_directory" % app_or_project
139 camel_case_name = "camel_case_%s_name" % app_or_project
140 camel_case_value = "".join(x for x in name.title() if x != "_")
141
142 context = Context(
143 {
144 **options,
145 base_name: name,

Callers

nothing calls this directly

Calls 15

validate_nameMethod · 0.95
handle_templateMethod · 0.95
apply_umaskMethod · 0.95
make_writeableMethod · 0.95
CommandErrorClass · 0.90
find_formattersFunction · 0.90
handle_extensionsFunction · 0.90
ContextClass · 0.90
get_docs_versionFunction · 0.90
EngineClass · 0.90
run_formattersFunction · 0.90
extendMethod · 0.80

Tested by

no test coverage detected