I am requesting that it would be possible to use the entirety of values
within the `context`. E.g.
{{{
new_path = os.path.join(top_dir, relative_dir, filename)
# Sort context by length of the key, so that longer keys are tested
first
for key, value in sorted(context.dicts[-1].items(), key=lambda kv:
len(kv[0]), reverse=True):
if key in new_path:
new_path = new_path.replace(key, value)
break
}}}
This would allow the usage of filenames like `camel_case_nameFilename.py-
tpl` to be replaced with `AppNameFilename.py`.
--
Ticket URL: <https://code.djangoproject.com/ticket/34312>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by Will Gordon):
If there's an agreement, I'm happy to submit a PR for the change.
--
Ticket URL: <https://code.djangoproject.com/ticket/34312#comment:1>
* status: new => closed
* resolution: => wontfix
Comment:
Thanks for this ticket, however `context` can contain custom variables and
replacing all of them in file name would be backward incompatible and
confusing for users. Moreover, this seems quite niche and sounds like a
good use case for [https://docs.djangoproject.com/en/stable/howto/custom-
management-commands/#overriding-commands overriding] the
`startapp`/`startproject` commands in your project and making whatever
customizations you need.
--
Ticket URL: <https://code.djangoproject.com/ticket/34312#comment:2>
Comment (by Greg Sadetsky):
@Will Gordon: for now, you can use use the cookiecutter project
(https://github.com/cookiecutter/cookiecutter) which does support
template-based file renaming
See https://github.com/cookiecutter/cookiecutter-django for example, which
has `{{cookiecutter.project_slug}}` as the directory name.
---
@Mariusz Felisiak: agreed that replacing words in filenames would be
potentially very risky - would you consider template-based replacing, as
above i.e. allowing `{{ project_name }}` to be used & replaced as part of
directory and file names?
Personally speaking, that's all I'd need for my project templates & would
save me from doing hacky `mv`s after instantiating a project.
Thank you!
--
Ticket URL: <https://code.djangoproject.com/ticket/34312#comment:3>