carltongibson / neapolitan

Quick CRUD views for Django
https://noumenal.es/neapolitan/
MIT License
413 stars 30 forks source link

Make mktemplate also work with project-level template directories #49

Open haukuri opened 3 weeks ago

haukuri commented 3 weeks ago

The mktemplate management command was not working for project-level template directories. See issue #48.

This change updates the mktemplate handle function to work for both app and project template directories.

haukuri commented 3 weeks ago

@carltongibson I couldn't quite figure out how to make the test case for not using an app-level template directory work with the existing unit test structure so I refactored it to more closely resemble a project structure as generated by startproject and startapp.

Would you rather keep the existing structure?

If so, could you point me in the right direction towards how to implement the new test within it?

carltongibson commented 1 week ago

Hi @haukuri.

Would you rather keep the existing structure?

I would 😅

Could you not (merely) add an extra_templates folder? (This wouldn't be auto-detected by app-level finder, so would need to be added to the settings)

haukuri commented 1 week ago

Hi @carltongibson

The current version renames the template directory in the test project so that it does not get picked up as an app template dir. This is not great because now we are not testing the case in which the user is actually using an app template dir.

I've also tried to use the @override_settings decorator on the test method to disable app template directories and specify an extra_templates dir for a specific test but that did not work.

I've even tried having both the regular app templates directory and an extra_templates directory and temporarily renaming the templates dir while running mktemplate but that just resulted in upsetting the template loader.

A solution would be to have a second app in the test project that would not have a template directory so that we would fall back to the project level template dir but I'm not sure how to do that within the test project structure.

Perhaps we should just close this PR. You could always do the change to mktemplate at some later point if interested.

carltongibson commented 1 week ago

@haukuri Let me have a play. Thanks. 🙏