A quick flit publish
and Neapolitan 24.2 is available on PyPI.
$ pip install -U neapolitan
Go get yours now! š
The release adds a new mktemplate
management command, that lets you quickly bootstrap an override of your active neapolitan
templates, on a per model and per CRUD action basis.
This makes āOh, I need to customise the list templateā much easier, so you donāt have to break your flow.
Basic usage is like this:
$ ./manage.py mktemplate cakeshop.Ingredient --list
You pass pass your model as <app_name.ModelName>
ā e.g. auth.User
, yay šāĀ and a flag for the CRUD operation you want to customise.
Thatās it. Youāll get a new cakeshop/templates/ingredient_list.html
template, where itāll be picked up by your IngredientCRUDView
.
* This is a copy of the default neapolitan/object_list.html
which is used otherwise.
* But it will use the template loader, so youāve overridden the default templates, your (correct) active templates will be the ones that are used.
I blocked mktemplate
out on Thursday morning. I knew I had a series of overrides coming up that morning, and this has been on the backlog a while.
The first --list
was good. By the time Iād done a --detail
, a --form
and a --delete
to complete the set, I was hooked.
See the --help
command for full options. I hope you enjoy. š
I wrote the mktemplate
command locally, against my development project. I didnāt have a test. It worked. I was happy.
I didnāt want to release it though without any tests at all.
No doubt there will be bugs: not everyoneās project looks exactly like mine.
When the bugs do come up, Iām going to ask for a test case, so we can fix it, and avoid regressions going forwards.
The hardest thing though with tests is bootstrapping them: that very first run. I wanted to avoid having a potential contributor put off by that hurdle.
So I added a very basic test. Testing a management command you use call_command
, and then assert something:
def test_mktemplate_command(self):
# Run the command
call_command('mktemplate', 'tests.Bookmark', '--list')
# Check if the file was created
file_path = 'tests/templates/tests/bookmark_list.html'
self.assertTrue(os.path.isfile(file_path))
# Remove the created file
os.remove(file_path)
Itās not the most glamorous thing. Looking at it now, Iām immediately like I should have used Path.
But itāll will do as a starter. Any issue is going to need a test looking something similar. It can serve as the setting off point for a future PR.
I mention it only because I think that kind of minimal test is pretty much always worth it.
Even if you only test the simplest Happy Path. At least you know you didnāt break that. But you also have at least some scaffolding up for when you do need a real test, when you do hit a real bug later.
Anyhowā¦
$ pip install -U neapolitan
š„³