Neapolitan 24.2 release

A quick flit publish and Neapolitan 24.2 is available on PyPI.

$ pip install -U neapolitan 

Go get yours now! šŸš€

Quicker template overrides

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. šŸŽ

The minimal test

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ā€¦

How to update (again)

$ pip install -U neapolitan  

šŸ„³