in blog | Carlton's latest posts |
---|---|
original entry | Neapolitan 24.2 release |
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
đ„ł