-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add setting to run other admin commands at the end (#79)
- Loading branch information
1 parent
0688b8b
commit 1f87053
Showing
5 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Configuration | ||
============= | ||
|
||
.. automodule:: django_remake_migrations.conf | ||
:noindex: | ||
|
||
.. autoclass:: AppSettings() | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
installation | ||
usage | ||
configuration | ||
technical-details | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" | ||
These are the available settings. | ||
All attributes prefixed ``REMAKE_MIGRATIONS_*`` can be overridden from your Django | ||
project's settings module by defining a setting with the same name. | ||
For instance, to run ``showmigrations`` and ``migrate`` after remaking, | ||
add the following to your project settings: | ||
.. code-block:: python | ||
REMAKE_MIGRATIONS_POST_COMMANDS = [ | ||
["showmigrations"], | ||
["migrate"], | ||
] | ||
""" | ||
from __future__ import annotations | ||
|
||
from collections.abc import Sequence | ||
from dataclasses import dataclass | ||
from typing import Any | ||
|
||
from django.conf import settings as django_settings | ||
|
||
# All attributes accessed with this prefix are possible to overwrite | ||
# through django.conf.settings. | ||
SETTINGS_PREFIX = "REMAKE_MIGRATIONS_" | ||
|
||
|
||
@dataclass(frozen=True) | ||
class AppSettings: | ||
"""Access this instance as `django_remake_migrations.conf.app_settings`.""" | ||
|
||
REMAKE_MIGRATIONS_POST_COMMANDS: Sequence[Sequence[str]] = () | ||
"""Some commands with arguments to run after generating the new migration.""" | ||
|
||
def __getattribute__(self, __name: str) -> Any: | ||
""" | ||
Check if a Django project settings should override the app default. | ||
In order to avoid returning any random properties of the django settings, | ||
we inspect the prefix firstly. | ||
""" | ||
if __name.startswith(SETTINGS_PREFIX) and hasattr(django_settings, __name): | ||
return getattr(django_settings, __name) | ||
|
||
return super().__getattribute__(__name) | ||
|
||
|
||
app_settings = AppSettings() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters