Skip to content

Conversation

@blag
Copy link
Contributor

@blag blag commented Jun 11, 2025

In the first commit:

  1. Tweak the logic to only connect signals if the user has configured the corresponding setting. This is slightly better than the previous behavior, which was always connecting the signals and checking for the setting value in the signal handler.
  2. Decompose the tests a bit more, using the setting_changed signal to connect and disconnect the add_default_site signal handler during tests
  3. Refactor the tests to split out a context manager that securely creates a temporary directory for tests and automatically deletes it when the test is done.
  4. Update tests to use pathlib.Path, since that API is much nicer than the os.path API, which let me simplify some file writing and reading later on, since we can use Path.read_text() and Path.write_text() instead of manually using context managers to open files for reading and writing.
  5. Use modern unittest and Django assertions, like assertIn and assertQuerySetEqual.
  6. Utilize Django's override_setting decorator and self.settings() context manager to automatically handle changing settings during tests, and resetting to the previous values after those tests finish.

In the second commit:

  1. Split the monolithic TestCase into different TestCases according to what piece of dbtemplates they test.
  2. Add a few more tests to improve coverage results.
  3. Update test_settings.py to fit more modern Django settings modules (read: use CACHES instead of configuring a cache backend directly).
  4. Refactor the dbtemplates loader and the Template.populate() method a little bit to improve readability by using try/except/else.
  5. Utilizing pathlib.Path in the sync_templates command.
  6. Refactor dbtemplates/utils/templates.py to properly record the chain of loaders that were tried when finding a template.

Then I formatted a bunch of files with Ruff.

Once this is merged I'll submit a commit/PR that updates the changelog and then merge and tag it so a new version gets released to PyPI.

@blag blag requested a review from mpasternak June 11, 2025 04:34
@blag blag added the feature label Jun 11, 2025
@blag blag force-pushed the modernize branch 4 times, most recently from 9cf4e01 to e28f19c Compare June 12, 2025 04:14
@blag
Copy link
Contributor Author

blag commented Jun 17, 2025

If I don't have any reviews or feedback on this by next week I'll take that as tacit approval and merge it, then push a tag and release a new version of django-dbtemplates.

@blag blag removed the request for review from mpasternak June 26, 2025 18:47
vied12 added a commit to Codepan-GmbH/django-dbtemplates that referenced this pull request Jul 28, 2025
vied12 added a commit to Codepan-GmbH/django-dbtemplates that referenced this pull request Jul 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant