django-flags 5.2.0__tar.gz → 5.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {django_flags-5.2.0 → django_flags-5.3.0}/.github/workflows/docs.yml +2 -2
- {django_flags-5.2.0 → django_flags-5.3.0}/.github/workflows/release.yml +3 -3
- {django_flags-5.2.0 → django_flags-5.3.0}/.github/workflows/test.yml +8 -8
- {django_flags-5.2.0/django_flags.egg-info → django_flags-5.3.0}/PKG-INFO +1 -1
- {django_flags-5.2.0 → django_flags-5.3.0/django_flags.egg-info}/PKG-INFO +1 -1
- {django_flags-5.2.0 → django_flags-5.3.0}/django_flags.egg-info/SOURCES.txt +2 -0
- django_flags-5.3.0/django_flags.egg-info/scm_file_list.json +101 -0
- django_flags-5.3.0/django_flags.egg-info/scm_version.json +8 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/docs/api/conditions.md +18 -11
- {django_flags-5.2.0 → django_flags-5.3.0}/docs/api/decorators.md +19 -12
- {django_flags-5.2.0 → django_flags-5.3.0}/docs/api/sources.md +2 -3
- {django_flags-5.2.0 → django_flags-5.3.0}/docs/api/state.md +2 -2
- {django_flags-5.2.0 → django_flags-5.3.0}/docs/api/urls.md +8 -3
- {django_flags-5.2.0 → django_flags-5.3.0}/docs/api/views.md +5 -5
- {django_flags-5.2.0 → django_flags-5.3.0}/docs/conditions.md +23 -10
- {django_flags-5.2.0 → django_flags-5.3.0}/docs/debugging.md +8 -8
- {django_flags-5.2.0 → django_flags-5.3.0}/docs/index.md +9 -11
- {django_flags-5.2.0 → django_flags-5.3.0}/docs/settings.md +25 -15
- {django_flags-5.2.0 → django_flags-5.3.0}/docs/usage.md +23 -11
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/checks.py +2 -2
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/conditions/validators.py +6 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/test_checks.py +12 -2
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/test_conditions_validators.py +15 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/.editorconfig +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/.gitignore +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/.pre-commit-config.yaml +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/CODE_OF_CONDUCT.md +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/CONTRIBUTING.md +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/LICENSE +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/MANIFEST.in +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/README.md +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/TERMS.md +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/django_flags.egg-info/dependency_links.txt +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/django_flags.egg-info/requires.txt +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/django_flags.egg-info/top_level.txt +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/docs/api/django.md +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/docs/api/jinja2.md +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/docs/css/overrides.css +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/docs/images/screenshot_create.png +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/docs/images/screenshot_flag_checks_panel.png +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/docs/images/screenshot_flags_debug_panel.png +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/docs/images/screenshot_list.png +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/docs/management_commands.md +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/docs/releasenotes.md +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/docs/testing.md +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/docs/theme-overrides/toc.html +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/__init__.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/admin.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/apps.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/conditions/__init__.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/conditions/conditions.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/conditions/registry.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/decorators.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/forms.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/jinja2tags.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/management/__init__.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/management/commands/__init__.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/management/commands/disable_flag.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/management/commands/enable_flag.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/middleware.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/migrations/0012_replace_migrations_for_wagtail_independence.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/migrations/0013_add_required_field.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/migrations/0014_flagstate_unique_constraint.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/migrations/__init__.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/models.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/panels.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/sources.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/state.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/templates/flags/panels/flag_checks.html +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/templates/flags/panels/flags.html +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/templatetags/__init__.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/templatetags/feature_flags.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/templatetags/flags_debug.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/__init__.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/settings.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/test_admin.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/test_conditions_conditions.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/test_conditions_registry.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/test_decorators.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/test_forms.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/test_jinja2tags.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/test_management_commands_disable_flag.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/test_management_commands_enable_flag.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/test_middleware.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/test_models.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/test_panels.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/test_sources.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/test_state.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/test_templatetags_feature_flags.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/test_templatetags_flags_debug.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/test_urls.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/test_views.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/testapp/__init__.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/testapp/apps.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/testapp/migrations/0001_initial.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/testapp/migrations/__init__.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/testapp/models.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/urls.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/urls.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/utils.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/flags/views.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/mkdocs.yml +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/pyproject.toml +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/setup.cfg +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/setup.py +0 -0
- {django_flags-5.2.0 → django_flags-5.3.0}/tox.ini +0 -0
|
@@ -8,12 +8,12 @@ jobs:
|
|
|
8
8
|
runs-on: ubuntu-latest
|
|
9
9
|
|
|
10
10
|
steps:
|
|
11
|
-
- uses: actions/checkout@v5
|
|
11
|
+
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
|
|
12
12
|
- run: |
|
|
13
13
|
git fetch --no-tags --prune --depth=1 origin gh-pages
|
|
14
14
|
|
|
15
15
|
- name: Set up Python
|
|
16
|
-
uses: actions/setup-python@v6
|
|
16
|
+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
|
|
17
17
|
with:
|
|
18
18
|
python-version: "3.13"
|
|
19
19
|
|
|
@@ -15,9 +15,9 @@ jobs:
|
|
|
15
15
|
permissions:
|
|
16
16
|
id-token: write
|
|
17
17
|
steps:
|
|
18
|
-
- uses: actions/checkout@v5
|
|
18
|
+
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
|
|
19
19
|
- name: Set up Python
|
|
20
|
-
uses: actions/setup-python@v6
|
|
20
|
+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
|
|
21
21
|
with:
|
|
22
22
|
python-version: 3.13
|
|
23
23
|
- name: Install dependencies
|
|
@@ -27,4 +27,4 @@ jobs:
|
|
|
27
27
|
run: |
|
|
28
28
|
python -m build
|
|
29
29
|
- name: Publish to PyPI
|
|
30
|
-
uses: pypa/gh-action-pypi-publish@release/v1
|
|
30
|
+
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # release/v1
|
|
@@ -7,10 +7,10 @@ jobs:
|
|
|
7
7
|
name: lint
|
|
8
8
|
runs-on: ubuntu-latest
|
|
9
9
|
steps:
|
|
10
|
-
- uses: actions/checkout@v5
|
|
10
|
+
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
|
|
11
11
|
|
|
12
12
|
- name: Set up Python
|
|
13
|
-
uses: actions/setup-python@v6
|
|
13
|
+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
|
|
14
14
|
with:
|
|
15
15
|
python-version: "3.13"
|
|
16
16
|
|
|
@@ -45,10 +45,10 @@ jobs:
|
|
|
45
45
|
django: "6.0"
|
|
46
46
|
|
|
47
47
|
steps:
|
|
48
|
-
- uses: actions/checkout@v5
|
|
48
|
+
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
|
|
49
49
|
|
|
50
50
|
- name: Set up Python
|
|
51
|
-
uses: actions/setup-python@v6
|
|
51
|
+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
|
|
52
52
|
with:
|
|
53
53
|
python-version: ${{ matrix.python }}
|
|
54
54
|
|
|
@@ -64,7 +64,7 @@ jobs:
|
|
|
64
64
|
TOXENV: python${{ matrix.python }}-django${{ matrix.django }}
|
|
65
65
|
|
|
66
66
|
- name: Store test coverage
|
|
67
|
-
uses: actions/upload-artifact@v5
|
|
67
|
+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5
|
|
68
68
|
with:
|
|
69
69
|
name: coverage-${{ matrix.python }}-${{ matrix.django }}
|
|
70
70
|
include-hidden-files: true
|
|
@@ -77,12 +77,12 @@ jobs:
|
|
|
77
77
|
- test
|
|
78
78
|
|
|
79
79
|
steps:
|
|
80
|
-
- uses: actions/checkout@v5
|
|
80
|
+
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
|
|
81
81
|
with:
|
|
82
82
|
fetch-depth: 0
|
|
83
83
|
|
|
84
84
|
- name: Set up Python
|
|
85
|
-
uses: actions/setup-python@v6
|
|
85
|
+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
|
|
86
86
|
with:
|
|
87
87
|
python-version: "3.13"
|
|
88
88
|
|
|
@@ -92,7 +92,7 @@ jobs:
|
|
|
92
92
|
pip install tox
|
|
93
93
|
|
|
94
94
|
- name: Retrieve test coverage
|
|
95
|
-
uses: actions/download-artifact@v6
|
|
95
|
+
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6
|
|
96
96
|
with:
|
|
97
97
|
merge-multiple: true
|
|
98
98
|
|
|
@@ -18,6 +18,8 @@ django_flags.egg-info/PKG-INFO
|
|
|
18
18
|
django_flags.egg-info/SOURCES.txt
|
|
19
19
|
django_flags.egg-info/dependency_links.txt
|
|
20
20
|
django_flags.egg-info/requires.txt
|
|
21
|
+
django_flags.egg-info/scm_file_list.json
|
|
22
|
+
django_flags.egg-info/scm_version.json
|
|
21
23
|
django_flags.egg-info/top_level.txt
|
|
22
24
|
docs/conditions.md
|
|
23
25
|
docs/debugging.md
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
{
|
|
2
|
+
"files": [
|
|
3
|
+
".editorconfig",
|
|
4
|
+
".github/workflows/docs.yml",
|
|
5
|
+
".github/workflows/release.yml",
|
|
6
|
+
".github/workflows/test.yml",
|
|
7
|
+
".gitignore",
|
|
8
|
+
".pre-commit-config.yaml",
|
|
9
|
+
"CODE_OF_CONDUCT.md",
|
|
10
|
+
"CONTRIBUTING.md",
|
|
11
|
+
"LICENSE",
|
|
12
|
+
"MANIFEST.in",
|
|
13
|
+
"README.md",
|
|
14
|
+
"TERMS.md",
|
|
15
|
+
"docs/api/conditions.md",
|
|
16
|
+
"docs/api/decorators.md",
|
|
17
|
+
"docs/api/django.md",
|
|
18
|
+
"docs/api/jinja2.md",
|
|
19
|
+
"docs/api/sources.md",
|
|
20
|
+
"docs/api/state.md",
|
|
21
|
+
"docs/api/urls.md",
|
|
22
|
+
"docs/api/views.md",
|
|
23
|
+
"docs/conditions.md",
|
|
24
|
+
"docs/css/overrides.css",
|
|
25
|
+
"docs/debugging.md",
|
|
26
|
+
"docs/images/screenshot_create.png",
|
|
27
|
+
"docs/images/screenshot_flag_checks_panel.png",
|
|
28
|
+
"docs/images/screenshot_flags_debug_panel.png",
|
|
29
|
+
"docs/images/screenshot_list.png",
|
|
30
|
+
"docs/index.md",
|
|
31
|
+
"docs/management_commands.md",
|
|
32
|
+
"docs/releasenotes.md",
|
|
33
|
+
"docs/settings.md",
|
|
34
|
+
"docs/testing.md",
|
|
35
|
+
"docs/theme-overrides/toc.html",
|
|
36
|
+
"docs/usage.md",
|
|
37
|
+
"flags/__init__.py",
|
|
38
|
+
"flags/admin.py",
|
|
39
|
+
"flags/apps.py",
|
|
40
|
+
"flags/checks.py",
|
|
41
|
+
"flags/conditions/__init__.py",
|
|
42
|
+
"flags/conditions/conditions.py",
|
|
43
|
+
"flags/conditions/registry.py",
|
|
44
|
+
"flags/conditions/validators.py",
|
|
45
|
+
"flags/decorators.py",
|
|
46
|
+
"flags/forms.py",
|
|
47
|
+
"flags/jinja2tags.py",
|
|
48
|
+
"flags/management/__init__.py",
|
|
49
|
+
"flags/management/commands/__init__.py",
|
|
50
|
+
"flags/management/commands/disable_flag.py",
|
|
51
|
+
"flags/management/commands/enable_flag.py",
|
|
52
|
+
"flags/middleware.py",
|
|
53
|
+
"flags/migrations/0012_replace_migrations_for_wagtail_independence.py",
|
|
54
|
+
"flags/migrations/0013_add_required_field.py",
|
|
55
|
+
"flags/migrations/0014_flagstate_unique_constraint.py",
|
|
56
|
+
"flags/migrations/__init__.py",
|
|
57
|
+
"flags/models.py",
|
|
58
|
+
"flags/panels.py",
|
|
59
|
+
"flags/sources.py",
|
|
60
|
+
"flags/state.py",
|
|
61
|
+
"flags/templates/flags/panels/flag_checks.html",
|
|
62
|
+
"flags/templates/flags/panels/flags.html",
|
|
63
|
+
"flags/templatetags/__init__.py",
|
|
64
|
+
"flags/templatetags/feature_flags.py",
|
|
65
|
+
"flags/templatetags/flags_debug.py",
|
|
66
|
+
"flags/tests/__init__.py",
|
|
67
|
+
"flags/tests/settings.py",
|
|
68
|
+
"flags/tests/test_admin.py",
|
|
69
|
+
"flags/tests/test_checks.py",
|
|
70
|
+
"flags/tests/test_conditions_conditions.py",
|
|
71
|
+
"flags/tests/test_conditions_registry.py",
|
|
72
|
+
"flags/tests/test_conditions_validators.py",
|
|
73
|
+
"flags/tests/test_decorators.py",
|
|
74
|
+
"flags/tests/test_forms.py",
|
|
75
|
+
"flags/tests/test_jinja2tags.py",
|
|
76
|
+
"flags/tests/test_management_commands_disable_flag.py",
|
|
77
|
+
"flags/tests/test_management_commands_enable_flag.py",
|
|
78
|
+
"flags/tests/test_middleware.py",
|
|
79
|
+
"flags/tests/test_models.py",
|
|
80
|
+
"flags/tests/test_panels.py",
|
|
81
|
+
"flags/tests/test_sources.py",
|
|
82
|
+
"flags/tests/test_state.py",
|
|
83
|
+
"flags/tests/test_templatetags_feature_flags.py",
|
|
84
|
+
"flags/tests/test_templatetags_flags_debug.py",
|
|
85
|
+
"flags/tests/test_urls.py",
|
|
86
|
+
"flags/tests/test_views.py",
|
|
87
|
+
"flags/tests/testapp/__init__.py",
|
|
88
|
+
"flags/tests/testapp/apps.py",
|
|
89
|
+
"flags/tests/testapp/migrations/0001_initial.py",
|
|
90
|
+
"flags/tests/testapp/migrations/__init__.py",
|
|
91
|
+
"flags/tests/testapp/models.py",
|
|
92
|
+
"flags/tests/urls.py",
|
|
93
|
+
"flags/urls.py",
|
|
94
|
+
"flags/utils.py",
|
|
95
|
+
"flags/views.py",
|
|
96
|
+
"mkdocs.yml",
|
|
97
|
+
"pyproject.toml",
|
|
98
|
+
"setup.py",
|
|
99
|
+
"tox.ini"
|
|
100
|
+
]
|
|
101
|
+
}
|
|
@@ -15,7 +15,8 @@ Register a new condition, either as a decorator:
|
|
|
15
15
|
```python
|
|
16
16
|
from flags import conditions
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
|
|
19
|
+
@conditions.register("path")
|
|
19
20
|
def path_condition(path, request=None, **kwargs):
|
|
20
21
|
return request.path.startswith(path)
|
|
21
22
|
```
|
|
@@ -26,7 +27,8 @@ Or as a function call:
|
|
|
26
27
|
def path_condition(path, request=None, **kwargs):
|
|
27
28
|
return request.path.startswith(path)
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
|
|
31
|
+
conditions.register("path", fn=path_condition)
|
|
30
32
|
```
|
|
31
33
|
|
|
32
34
|
Will raise a `conditions.DuplicateCondition` exception if the condition name is already registered.
|
|
@@ -38,11 +40,13 @@ A [validator](https://docs.djangoproject.com/en/stable/ref/validators/) can be g
|
|
|
38
40
|
from django.core.exceptions import ValidationError
|
|
39
41
|
from flags import conditions
|
|
40
42
|
|
|
43
|
+
|
|
41
44
|
def validate_path(value):
|
|
42
|
-
if not value.startswith(
|
|
43
|
-
raise ValidationError(
|
|
45
|
+
if not value.startswith("/"):
|
|
46
|
+
raise ValidationError("Enter a valid path")
|
|
44
47
|
|
|
45
|
-
|
|
48
|
+
|
|
49
|
+
@conditions.register("path", validator=validate_path)
|
|
46
50
|
def path_condition(path, request=None, **kwargs):
|
|
47
51
|
return request.path.startswith(path)
|
|
48
52
|
```
|
|
@@ -53,22 +57,24 @@ Or as an attribute on the condition callable:
|
|
|
53
57
|
from django.core.exceptions import ValidationError
|
|
54
58
|
from flags import conditions
|
|
55
59
|
|
|
60
|
+
|
|
56
61
|
class PathCondition:
|
|
57
62
|
def __call__(self, path, request=None, **kwargs):
|
|
58
63
|
return request.path.startswith(path)
|
|
59
64
|
|
|
60
65
|
def validate(self, value):
|
|
61
|
-
if not value.startswith(
|
|
62
|
-
raise ValidationError(
|
|
66
|
+
if not value.startswith("/"):
|
|
67
|
+
raise ValidationError("Enter a valid path")
|
|
68
|
+
|
|
63
69
|
|
|
64
|
-
conditions.register(
|
|
70
|
+
conditions.register("path", fn=PathCondition)
|
|
65
71
|
```
|
|
66
72
|
|
|
67
73
|
Validators specified in both ways are available on condition callables as
|
|
68
74
|
a `validate` attribute:
|
|
69
75
|
|
|
70
76
|
```python
|
|
71
|
-
condition = get_condition(
|
|
77
|
+
condition = get_condition("path")
|
|
72
78
|
condition.validate(value)
|
|
73
79
|
```
|
|
74
80
|
|
|
@@ -83,11 +89,12 @@ Exception raised by `conditions.register` if the condition name being registered
|
|
|
83
89
|
Exception intended to be raised when a condition is not given a keyword argument it requires for evaluation.
|
|
84
90
|
|
|
85
91
|
```python
|
|
86
|
-
@conditions.register(
|
|
92
|
+
@conditions.register("path")
|
|
87
93
|
def path_condition(path, request=None, **kwargs):
|
|
88
94
|
if request is None:
|
|
89
95
|
raise conditions.RequiredForCondition(
|
|
90
|
-
"request is required for condition 'path'"
|
|
96
|
+
"request is required for condition 'path'"
|
|
97
|
+
)
|
|
91
98
|
|
|
92
99
|
return request.path.startswith(path)
|
|
93
100
|
```
|
|
@@ -24,20 +24,24 @@ Check that a given flag has the given state. If the state does not match, perfor
|
|
|
24
24
|
```python
|
|
25
25
|
from flags.decorators import flag_check
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
|
|
28
|
+
@flag_check("MY_FLAG", True)
|
|
28
29
|
def view_requiring_flag(request):
|
|
29
|
-
return HttpResponse(
|
|
30
|
+
return HttpResponse("MY_FLAG was true")
|
|
31
|
+
|
|
30
32
|
|
|
31
|
-
@flag_check(
|
|
33
|
+
@flag_check("MY_OTHER_FLAG", False)
|
|
32
34
|
def view_requiring_other_flag_not_true(request):
|
|
33
|
-
return HttpResponse(
|
|
35
|
+
return HttpResponse("MY_OTHER_FLAG was False")
|
|
36
|
+
|
|
34
37
|
|
|
35
38
|
def fallback_view(request):
|
|
36
|
-
return HttpResponse(
|
|
39
|
+
return HttpResponse("MY_FLAG_WITH_FALLBACK was False")
|
|
40
|
+
|
|
37
41
|
|
|
38
|
-
@flag_check(
|
|
42
|
+
@flag_check("MY_FLAG_WITH_FALLBACK", True, fallback=fallback_view)
|
|
39
43
|
def view_with_fallback(request):
|
|
40
|
-
return HttpResponse(
|
|
44
|
+
return HttpResponse("MY_FLAG_WITH_FALLBACK was True")
|
|
41
45
|
```
|
|
42
46
|
|
|
43
47
|
|
|
@@ -53,14 +57,17 @@ Require the given flag to be enabled.
|
|
|
53
57
|
```python
|
|
54
58
|
from flags.decorators import flag_required
|
|
55
59
|
|
|
56
|
-
|
|
60
|
+
|
|
61
|
+
@flag_required("MY_FLAG")
|
|
57
62
|
def view_requiring_flag(request):
|
|
58
|
-
return HttpResponse(
|
|
63
|
+
return HttpResponse("flag was set")
|
|
64
|
+
|
|
59
65
|
|
|
60
66
|
def other_view(request):
|
|
61
|
-
return HttpResponse(
|
|
67
|
+
return HttpResponse("flag was not set")
|
|
68
|
+
|
|
62
69
|
|
|
63
|
-
@flag_required(
|
|
70
|
+
@flag_required("MY_FLAG_WITH_FALLBACK", fallback_view=other_view)
|
|
64
71
|
def view_with_fallback(request):
|
|
65
|
-
return HttpResponse(
|
|
72
|
+
return HttpResponse("flag was set")
|
|
66
73
|
```
|
|
@@ -7,11 +7,10 @@ from flags.sources import Condition
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class CustomFlagSource(object):
|
|
10
|
-
|
|
11
10
|
def get_flags(self):
|
|
12
11
|
flags = {
|
|
13
|
-
|
|
14
|
-
Condition(
|
|
12
|
+
"MY_FLAG": [
|
|
13
|
+
Condition("parameter", "enable_my_flag"),
|
|
15
14
|
]
|
|
16
15
|
}
|
|
17
16
|
return flags
|
|
@@ -29,8 +29,8 @@ Return the value for the flag (`True` or `False`) by passing kwargs to its condi
|
|
|
29
29
|
Returns `True` if a flag is enabled by passing kwargs to its conditions, otherwise returns `False`.
|
|
30
30
|
|
|
31
31
|
```python
|
|
32
|
-
if flag_enabled(
|
|
33
|
-
|
|
32
|
+
if flag_enabled("MY_FLAG", request=a_request):
|
|
33
|
+
print("My feature flag is enabled")
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
### `flag_disabled(flag_name, **kwargs)`
|
|
@@ -3,7 +3,12 @@
|
|
|
3
3
|
Flagged URL patterns are an alternative to [flagging views with decorators](../../api/decorators).
|
|
4
4
|
|
|
5
5
|
```python
|
|
6
|
-
from flags.urls import
|
|
6
|
+
from flags.urls import (
|
|
7
|
+
flagged_path,
|
|
8
|
+
flagged_paths,
|
|
9
|
+
flagged_re_path,
|
|
10
|
+
flagged_re_paths,
|
|
11
|
+
)
|
|
7
12
|
```
|
|
8
13
|
|
|
9
14
|
### `flagged_path(flag_name, route, view, kwargs=None, name=None, state=True, fallback=None)`
|
|
@@ -47,9 +52,9 @@ Flag multiple URLs in the same context with a context manager.
|
|
|
47
52
|
When a fallback view is given it *must* take the same arguments as the flagged view.
|
|
48
53
|
|
|
49
54
|
```python
|
|
50
|
-
with flagged_paths(
|
|
55
|
+
with flagged_paths("MY_FLAG") as path:
|
|
51
56
|
flagged_url_patterns = [
|
|
52
|
-
path(
|
|
57
|
+
path("a-url/", view_requiring_flag),
|
|
53
58
|
]
|
|
54
59
|
|
|
55
60
|
urlpatterns = urlpatterns + flagged_url_patterns
|
|
@@ -35,9 +35,10 @@ For example, in `views.py`:
|
|
|
35
35
|
from django.views.generic import View
|
|
36
36
|
from flags.views import FlaggedViewMixin
|
|
37
37
|
|
|
38
|
+
|
|
38
39
|
class MyFlaggedView(FlaggedViewMixin, View):
|
|
39
40
|
def get(self, request, *args, **kwargs):
|
|
40
|
-
return HttpResponse(
|
|
41
|
+
return HttpResponse("ok")
|
|
41
42
|
```
|
|
42
43
|
|
|
43
44
|
And in `urls.py`:
|
|
@@ -46,9 +47,7 @@ And in `urls.py`:
|
|
|
46
47
|
from django.urls import path
|
|
47
48
|
from flags.urls import flagged_path
|
|
48
49
|
|
|
49
|
-
urlpatterns = [
|
|
50
|
-
path('my-url/', MyFlaggedView.as_view(flag_name='MY_FLAG'))
|
|
51
|
-
]
|
|
50
|
+
urlpatterns = [path("my-url/", MyFlaggedView.as_view(flag_name="MY_FLAG"))]
|
|
52
51
|
```
|
|
53
52
|
|
|
54
53
|
### `FlaggedTemplateView`
|
|
@@ -60,9 +59,10 @@ For example, in `views.py`:
|
|
|
60
59
|
```python
|
|
61
60
|
from flags.views import FlaggedTemplateView
|
|
62
61
|
|
|
62
|
+
|
|
63
63
|
class MyFlaggedView(FlaggedTemplateView):
|
|
64
64
|
template_name = "mytemplate.html"
|
|
65
|
-
flag_name =
|
|
65
|
+
flag_name = "MY_FLAG"
|
|
66
66
|
```
|
|
67
67
|
|
|
68
68
|
Or to serve a template directly in `urls.py`:
|
|
@@ -10,7 +10,7 @@ A simple boolean true/false intended to enable or disable a flag explicitly. The
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
```python
|
|
13
|
-
FLAGS = {
|
|
13
|
+
FLAGS = {"MY_FLAG": [{"condition": "boolean", "value": True}]}
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
The value can given as a Python `True` or `False` or as any [string representation of truth](https://docs.python.org/3/distutils/apiref.html#distutils.util.strtobool), such as `y`, `yes`, `t`, `true`, `on` and `1` for true values, and `n`, `no`, `f`, `false`, `off` and `0` for false values.
|
|
@@ -20,7 +20,7 @@ The value can given as a Python `True` or `False` or as any [string representat
|
|
|
20
20
|
Allows a flag to be enabled for the username given as the condition's value.
|
|
21
21
|
|
|
22
22
|
```python
|
|
23
|
-
FLAGS = {
|
|
23
|
+
FLAGS = {"MY_FLAG": [{"condition": "user", "value": "jane.doe"}]}
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
### `anonymous`
|
|
@@ -29,7 +29,7 @@ Allows a flag to be either enabled or disabled depending on whether a user is an
|
|
|
29
29
|
|
|
30
30
|
```python
|
|
31
31
|
# MY_FLAG is enabled if the user is not anonymous (is logged in)
|
|
32
|
-
FLAGS = {
|
|
32
|
+
FLAGS = {"MY_FLAG": [{"condition": "anonymous", "value": False}]}
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
The value can given as a Python `True` or `False` or as any [string representation of truth](https://docs.python.org/3/distutils/apiref.html#distutils.util.strtobool), such as `y`, `yes`, `t`, `true`, `on` and `1` for true values, and `n`, `no`, `f`, `false`, `off` and `0` for false values.
|
|
@@ -40,10 +40,19 @@ Allows a flag to be enabled by including a parameter in the request's query stri
|
|
|
40
40
|
|
|
41
41
|
```python
|
|
42
42
|
FLAGS = {
|
|
43
|
-
|
|
44
|
-
{
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
"MY_FLAG": [
|
|
44
|
+
{
|
|
45
|
+
"condition": "parameter",
|
|
46
|
+
"value": "my_flag_param1",
|
|
47
|
+
}, # ?my_flag_param1=True
|
|
48
|
+
{
|
|
49
|
+
"condition": "parameter",
|
|
50
|
+
"value": "my_flag_param2=now",
|
|
51
|
+
}, # ?my_flag_param2=now
|
|
52
|
+
{
|
|
53
|
+
"condition": "parameter",
|
|
54
|
+
"value": "my_flag_param3=",
|
|
55
|
+
}, # ?my_flag_param3
|
|
47
56
|
]
|
|
48
57
|
}
|
|
49
58
|
```
|
|
@@ -53,7 +62,9 @@ FLAGS = {
|
|
|
53
62
|
Allows a flag to be enabled if the request's path matches the regular expression value.
|
|
54
63
|
|
|
55
64
|
```python
|
|
56
|
-
FLAGS = {
|
|
65
|
+
FLAGS = {
|
|
66
|
+
"MY_FLAG": [{"condition": "path matches", "value": r"^/flagged/path"}]
|
|
67
|
+
}
|
|
57
68
|
```
|
|
58
69
|
|
|
59
70
|
### `after date`
|
|
@@ -61,7 +72,9 @@ FLAGS = {'MY_FLAG': [{'condition': 'path matches', 'value': r'^/flagged/path'}]}
|
|
|
61
72
|
Allows a flag to be enabled after a given date (and time) given in [ISO 8601 format](https://en.wikipedia.org/wiki/ISO_8601). The time must be specified either in UTC or as an offset from UTC.
|
|
62
73
|
|
|
63
74
|
```python
|
|
64
|
-
FLAGS = {
|
|
75
|
+
FLAGS = {
|
|
76
|
+
"MY_FLAG": [{"condition": "after date", "value": "2017-06-01T12:00Z"}]
|
|
77
|
+
}
|
|
65
78
|
```
|
|
66
79
|
|
|
67
80
|
### `before_date`
|
|
@@ -69,7 +82,7 @@ FLAGS = {'MY_FLAG': [{'condition': 'after date', 'value': '2017-06-01T12:00Z'}]}
|
|
|
69
82
|
Allows a flag to be enabled before a given date (and time) given in [ISO 8601 format](https://en.wikipedia.org/wiki/ISO_8601). The time must be specified either in UTC or as an offset from UTC.
|
|
70
83
|
|
|
71
84
|
```python
|
|
72
|
-
FLAGS = {
|
|
85
|
+
FLAGS = {"MY_FLAG": {"before date": "2022-06-01T12:00Z"}}
|
|
73
86
|
```
|
|
74
87
|
|
|
75
88
|
## Custom conditions
|
|
@@ -3,22 +3,22 @@
|
|
|
3
3
|
## System checks
|
|
4
4
|
|
|
5
5
|
<dl>
|
|
6
|
-
<dt>`flags.
|
|
6
|
+
<dt>`flags.W001`</dt>
|
|
7
7
|
<dd>
|
|
8
8
|
<p>Django-Flags includes a <a href="https://docs.djangoproject.com/en/stable/topics/checks/">Django system check</a> to check for flags that have non-existent conditions on start-up.</p>
|
|
9
|
-
<pre><code>?: (flags.
|
|
9
|
+
<pre><code>?: (flags.W001) Flag FLAG_WITH_ANY_CONDITIONS has non-existent condition "condition name".
|
|
10
10
|
HINT: Register "condition name" as a Django-Flags condition.</code></pre>
|
|
11
11
|
</dd>
|
|
12
|
-
</dl>
|
|
12
|
+
</dl>
|
|
13
13
|
|
|
14
14
|
<dl>
|
|
15
|
-
<dt>`flags.
|
|
15
|
+
<dt>`flags.W002`</dt>
|
|
16
16
|
<dd>
|
|
17
17
|
<p>Django-Flags includes a <a href="https://docs.djangoproject.com/en/stable/topics/checks/">Django system check</a> to check to ensure that flag conditions have valid expected values on start-up.</p>
|
|
18
|
-
<pre><code>?: (flags.
|
|
18
|
+
<pre><code>?: (flags.W002) Flag FLAG_WITH_ANY_CONDITIONS's "boolean" condition has an invalid value.
|
|
19
19
|
HINT: Enter one of "on", "off", "true", "false".</code></pre>
|
|
20
20
|
</dd>
|
|
21
|
-
</dl>
|
|
21
|
+
</dl>
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
## Exceptions
|
|
@@ -46,7 +46,7 @@ To enable the panel first follow the [installation and setup instructions for Dj
|
|
|
46
46
|
```python
|
|
47
47
|
DEBUG_TOOLBAR_PANELS = [
|
|
48
48
|
# …
|
|
49
|
-
|
|
49
|
+
"flags.panels.FlagsPanel",
|
|
50
50
|
# …
|
|
51
51
|
]
|
|
52
52
|
```
|
|
@@ -62,7 +62,7 @@ To enable the panel first follow the [installation and setup instructions for Dj
|
|
|
62
62
|
```python
|
|
63
63
|
DEBUG_TOOLBAR_PANELS = [
|
|
64
64
|
# …
|
|
65
|
-
|
|
65
|
+
"flags.panels.FlagChecksPanel",
|
|
66
66
|
# …
|
|
67
67
|
]
|
|
68
68
|
```
|
|
@@ -4,8 +4,8 @@ Feature flags allow you to toggle functionality in both Django code and the Djan
|
|
|
4
4
|
|
|
5
5
|
## Dependencies
|
|
6
6
|
|
|
7
|
-
- Django
|
|
8
|
-
- Python 3.
|
|
7
|
+
- Django 4.2, 5.1, 5.2, 6.0
|
|
8
|
+
- Python 3.10+
|
|
9
9
|
|
|
10
10
|
## Installation
|
|
11
11
|
|
|
@@ -20,7 +20,7 @@ Then add `flags` as an installed app in your Django `settings.py`:
|
|
|
20
20
|
```python
|
|
21
21
|
INSTALLED_APPS = (
|
|
22
22
|
# …
|
|
23
|
-
|
|
23
|
+
"flags",
|
|
24
24
|
# …
|
|
25
25
|
)
|
|
26
26
|
```
|
|
@@ -30,13 +30,13 @@ And `django.template.context_processors.request` to the `TEMPLATES` `context_pro
|
|
|
30
30
|
```python
|
|
31
31
|
TEMPLATES = [
|
|
32
32
|
{
|
|
33
|
-
|
|
33
|
+
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
|
34
34
|
# …
|
|
35
|
-
|
|
35
|
+
"OPTIONS": {
|
|
36
36
|
# …
|
|
37
|
-
|
|
37
|
+
"context_processors": [
|
|
38
38
|
# …
|
|
39
|
-
|
|
39
|
+
"django.template.context_processors.request",
|
|
40
40
|
# …
|
|
41
41
|
],
|
|
42
42
|
# …
|
|
@@ -65,9 +65,7 @@ To use Django-Flags you first need to define the flag, use the flag, and define
|
|
|
65
65
|
First, define the flag in Django `settings.py`:
|
|
66
66
|
|
|
67
67
|
```python
|
|
68
|
-
FLAGS = {
|
|
69
|
-
'MY_FLAG': []
|
|
70
|
-
}
|
|
68
|
+
FLAGS = {"MY_FLAG": []}
|
|
71
69
|
```
|
|
72
70
|
|
|
73
71
|
Then use the flag in a Django template (`mytemplate.html`):
|
|
@@ -90,7 +88,7 @@ from django.urls import path
|
|
|
90
88
|
from django.views.generic import TemplateView
|
|
91
89
|
|
|
92
90
|
urlpatterns = [
|
|
93
|
-
path(r
|
|
91
|
+
path(r"mypage/", TemplateView.as_view(template_name="mytemplate.html")),
|
|
94
92
|
]
|
|
95
93
|
```
|
|
96
94
|
|
|
@@ -22,7 +22,7 @@ Conditions can either be included as:
|
|
|
22
22
|
```
|
|
23
23
|
or
|
|
24
24
|
```python
|
|
25
|
-
{
|
|
25
|
+
{"condition": "condition name", "value": "expected value"}
|
|
26
26
|
```
|
|
27
27
|
(`required` defaults to `False`).
|
|
28
28
|
- A list of 3-tuples with the format:
|
|
@@ -39,20 +39,30 @@ For example:
|
|
|
39
39
|
|
|
40
40
|
```python
|
|
41
41
|
FLAGS = {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
42
|
+
"FLAG_WITH_EMPTY_CONDITIONS": [],
|
|
43
|
+
"FLAG_WITH_DICT_CONDITIONS": [
|
|
44
|
+
{
|
|
45
|
+
"condition": "condition name",
|
|
46
|
+
"value": "expected value to be enabled",
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"condition": "condition name",
|
|
50
|
+
"value": "expected value to be enabled",
|
|
51
|
+
"required": True,
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
"FLAG_WITH_TUPLE_CONDITIONS": [
|
|
55
|
+
("condition name", "expected value to be enabled"),
|
|
56
|
+
("condition name", "expected value to be enabled", True),
|
|
57
|
+
],
|
|
58
|
+
# This is possible, but not recommended
|
|
59
|
+
"FLAG_WITH_MIXED_CONDITIONS": [
|
|
60
|
+
{
|
|
61
|
+
"condition": "condition name",
|
|
62
|
+
"value": "expected value to be enabled",
|
|
63
|
+
},
|
|
64
|
+
("condition name", "expected value to be enabled", True),
|
|
65
|
+
],
|
|
56
66
|
}
|
|
57
67
|
```
|
|
58
68
|
|
|
@@ -6,15 +6,22 @@ Flags are defined in Django settings with the conditions in which they are enabl
|
|
|
6
6
|
|
|
7
7
|
```python
|
|
8
8
|
FLAGS = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
{
|
|
12
|
-
|
|
9
|
+
"FLAG_WITH_EMPTY_CONDITIONS": [],
|
|
10
|
+
"FLAG_WITH_ANY_CONDITIONS": [
|
|
11
|
+
{
|
|
12
|
+
"condition": "condition name",
|
|
13
|
+
"value": "expected value to be enabled",
|
|
14
|
+
},
|
|
15
|
+
{"condition": "user", "value": "lady.liberty"},
|
|
16
|
+
],
|
|
17
|
+
"FLAG_WITH_REQUIRED_CONDITIONS": [
|
|
18
|
+
{"condition": "user", "value": "lady.liberty"},
|
|
19
|
+
{
|
|
20
|
+
"condition": "path matches",
|
|
21
|
+
"value": r"^/liberty/island",
|
|
22
|
+
"required": True,
|
|
23
|
+
},
|
|
13
24
|
],
|
|
14
|
-
'FLAG_WITH_REQUIRED_CONDITIONS': [
|
|
15
|
-
{'condition': 'user', 'value': 'lady.liberty'},
|
|
16
|
-
{'condition': 'path matches', 'value': r'^/liberty/island', 'required': True},
|
|
17
|
-
]
|
|
18
25
|
}
|
|
19
26
|
```
|
|
20
27
|
|
|
@@ -29,8 +36,8 @@ Flags can be used in Python code:
|
|
|
29
36
|
```python
|
|
30
37
|
from flags.state import flag_enabled
|
|
31
38
|
|
|
32
|
-
if flag_enabled(
|
|
33
|
-
print("My feature flag is enabled")
|
|
39
|
+
if flag_enabled("FLAG_WITH_ANY_CONDITIONS", request=a_request):
|
|
40
|
+
print("My feature flag is enabled")
|
|
34
41
|
```
|
|
35
42
|
|
|
36
43
|
In Django templates:
|
|
@@ -61,7 +68,12 @@ In `urls.py`:
|
|
|
61
68
|
from flags.urls import flagged_path
|
|
62
69
|
|
|
63
70
|
urlpatterns = [
|
|
64
|
-
flagged_path(
|
|
71
|
+
flagged_path(
|
|
72
|
+
"FLAG_WITH_REQUIRED_CONDITIONS",
|
|
73
|
+
"a-url/",
|
|
74
|
+
view_requiring_flag,
|
|
75
|
+
state=True,
|
|
76
|
+
),
|
|
65
77
|
]
|
|
66
78
|
```
|
|
67
79
|
|
|
@@ -22,7 +22,7 @@ def flag_conditions_check(app_configs, **kwargs):
|
|
|
22
22
|
f"Register '{condition.condition}' as a "
|
|
23
23
|
"Django-Flags condition."
|
|
24
24
|
),
|
|
25
|
-
id="flags.
|
|
25
|
+
id="flags.W001",
|
|
26
26
|
)
|
|
27
27
|
)
|
|
28
28
|
elif condition.fn.validate is not None:
|
|
@@ -36,7 +36,7 @@ def flag_conditions_check(app_configs, **kwargs):
|
|
|
36
36
|
"condition has an invalid value."
|
|
37
37
|
),
|
|
38
38
|
hint=e.message,
|
|
39
|
-
id="flags.
|
|
39
|
+
id="flags.W002",
|
|
40
40
|
)
|
|
41
41
|
)
|
|
42
42
|
|
|
@@ -3,6 +3,7 @@ import re
|
|
|
3
3
|
from django.contrib.auth import get_user_model
|
|
4
4
|
from django.core.exceptions import ValidationError
|
|
5
5
|
from django.core.validators import RegexValidator
|
|
6
|
+
from django.db import OperationalError, ProgrammingError
|
|
6
7
|
from django.utils import dateparse
|
|
7
8
|
|
|
8
9
|
from flags.utils import strtobool
|
|
@@ -45,6 +46,11 @@ def validate_user(value):
|
|
|
45
46
|
UserModel.objects.get(**{UserModel.USERNAME_FIELD: value})
|
|
46
47
|
except UserModel.DoesNotExist as err:
|
|
47
48
|
raise ValidationError("Enter the username of a valid user.") from err
|
|
49
|
+
except (OperationalError, ProgrammingError) as err:
|
|
50
|
+
raise ValidationError(
|
|
51
|
+
"Unable to validate the user because the user table is not "
|
|
52
|
+
"available. This may be because migrations have not been run."
|
|
53
|
+
) from err
|
|
48
54
|
|
|
49
55
|
|
|
50
56
|
def validate_date(value):
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from django.apps import apps
|
|
2
2
|
from django.core.checks import Warning
|
|
3
|
+
from django.db import connection
|
|
3
4
|
from django.test import TestCase, override_settings
|
|
4
5
|
|
|
5
6
|
from flags.checks import flag_conditions_check
|
|
@@ -15,11 +16,20 @@ class TestFlagsConditionsCheck(TestCase):
|
|
|
15
16
|
errors = flag_conditions_check(apps.get_app_configs())
|
|
16
17
|
self.assertEqual(len(errors), 1)
|
|
17
18
|
self.assertIsInstance(errors[0], Warning)
|
|
18
|
-
self.assertEqual(errors[0].id, "flags.
|
|
19
|
+
self.assertEqual(errors[0].id, "flags.W001")
|
|
19
20
|
|
|
20
21
|
@override_settings(FLAGS={"FLAG_TO_CHECK": [("boolean", "foo")]})
|
|
21
22
|
def test_check_fails_if_conditions_exist_with_invalid_value(self):
|
|
22
23
|
errors = flag_conditions_check(apps.get_app_configs())
|
|
23
24
|
self.assertEqual(len(errors), 1)
|
|
24
25
|
self.assertIsInstance(errors[0], Warning)
|
|
25
|
-
self.assertEqual(errors[0].id, "flags.
|
|
26
|
+
self.assertEqual(errors[0].id, "flags.W002")
|
|
27
|
+
|
|
28
|
+
@override_settings(FLAGS={"FLAG_TO_CHECK": [("user", "testuser")]})
|
|
29
|
+
def test_check_does_not_crash_when_user_table_missing(self):
|
|
30
|
+
with connection.cursor() as cursor:
|
|
31
|
+
cursor.execute("DROP TABLE auth_user")
|
|
32
|
+
errors = flag_conditions_check(apps.get_app_configs())
|
|
33
|
+
self.assertEqual(len(errors), 1)
|
|
34
|
+
self.assertIsInstance(errors[0], Warning)
|
|
35
|
+
self.assertEqual(errors[0].id, "flags.W002")
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
from unittest import mock
|
|
2
|
+
|
|
1
3
|
from django.contrib.auth import get_user_model
|
|
2
4
|
from django.core.exceptions import ValidationError
|
|
5
|
+
from django.db import OperationalError
|
|
3
6
|
from django.test import TestCase, override_settings
|
|
4
7
|
|
|
5
8
|
from flags.conditions.validators import (
|
|
@@ -82,6 +85,18 @@ class ValidateUserTestCase(TestCase):
|
|
|
82
85
|
with self.assertRaises(ValidationError):
|
|
83
86
|
validate_user("nottestuser")
|
|
84
87
|
|
|
88
|
+
def test_user_table_missing_raises_validation_error(self):
|
|
89
|
+
User = get_user_model()
|
|
90
|
+
with (
|
|
91
|
+
mock.patch.object(
|
|
92
|
+
User.objects,
|
|
93
|
+
"get",
|
|
94
|
+
side_effect=OperationalError("no such table: auth_user"),
|
|
95
|
+
),
|
|
96
|
+
self.assertRaises(ValidationError),
|
|
97
|
+
):
|
|
98
|
+
validate_user("testuser")
|
|
99
|
+
|
|
85
100
|
|
|
86
101
|
class ValidateDateTestCase(TestCase):
|
|
87
102
|
def test_invalid_date_strings(self):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_flags-5.2.0 → django_flags-5.3.0}/flags/migrations/0014_flagstate_unique_constraint.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/test_management_commands_disable_flag.py
RENAMED
|
File without changes
|
{django_flags-5.2.0 → django_flags-5.3.0}/flags/tests/test_management_commands_enable_flag.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|