django-qbe2 0.1.0a1__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.
@@ -0,0 +1,226 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ *.lcov
51
+ .hypothesis/
52
+ .pytest_cache/
53
+ cover/
54
+
55
+ # Translations
56
+ *.mo
57
+ *.pot
58
+
59
+ # Django stuff:
60
+ *.log
61
+ local_settings.py
62
+ db.sqlite3
63
+ db.sqlite3-journal
64
+
65
+ # Flask stuff:
66
+ instance/
67
+ .webassets-cache
68
+
69
+ # Scrapy stuff:
70
+ .scrapy
71
+
72
+ # Sphinx documentation
73
+ docs/_build/
74
+ docs/build/
75
+
76
+ # Personal plans and local agent state
77
+ /.superpowers/
78
+ /tasks/
79
+ /docs/superpowers/
80
+
81
+ # PyBuilder
82
+ .pybuilder/
83
+ target/
84
+
85
+ # Jupyter Notebook
86
+ .ipynb_checkpoints
87
+
88
+ # IPython
89
+ profile_default/
90
+ ipython_config.py
91
+
92
+ # pyenv
93
+ # For a library or package, you might want to ignore these files since the code is
94
+ # intended to run in multiple environments; otherwise, check them in:
95
+ # .python-version
96
+
97
+ # pipenv
98
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
99
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
100
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
101
+ # install all needed dependencies.
102
+ # Pipfile.lock
103
+
104
+ # uv
105
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
106
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
107
+ # commonly ignored for libraries.
108
+ # uv.lock
109
+
110
+ # poetry
111
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
112
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
113
+ # commonly ignored for libraries.
114
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
115
+ # poetry.lock
116
+ # poetry.toml
117
+
118
+ # pdm
119
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
120
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
121
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
122
+ # pdm.lock
123
+ # pdm.toml
124
+ .pdm-python
125
+ .pdm-build/
126
+
127
+ # pixi
128
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
129
+ # pixi.lock
130
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
131
+ # in the .venv directory. It is recommended not to include this directory in version control.
132
+ .pixi/*
133
+ !.pixi/config.toml
134
+
135
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
136
+ __pypackages__/
137
+
138
+ # Celery stuff
139
+ celerybeat-schedule*
140
+ celerybeat.pid
141
+
142
+ # Redis
143
+ *.rdb
144
+ *.aof
145
+ *.pid
146
+
147
+ # RabbitMQ
148
+ mnesia/
149
+ rabbitmq/
150
+ rabbitmq-data/
151
+
152
+ # ActiveMQ
153
+ activemq-data/
154
+
155
+ # SageMath parsed files
156
+ *.sage.py
157
+
158
+ # Environments
159
+ .env
160
+ .envrc
161
+ .venv
162
+ env/
163
+ venv/
164
+ ENV/
165
+ env.bak/
166
+ venv.bak/
167
+
168
+ # Spyder project settings
169
+ .spyderproject
170
+ .spyproject
171
+
172
+ # Rope project settings
173
+ .ropeproject
174
+
175
+ # mkdocs/Zensical documentation
176
+ /site
177
+
178
+ # mypy
179
+ .mypy_cache/
180
+ .dmypy.json
181
+ dmypy.json
182
+
183
+ # Pyre type checker
184
+ .pyre/
185
+
186
+ # pytype static type analyzer
187
+ .pytype/
188
+
189
+ # Cython debug symbols
190
+ cython_debug/
191
+
192
+ # PyCharm
193
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
194
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
195
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
196
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
197
+ # .idea/
198
+
199
+ # Abstra
200
+ # Abstra is an AI-powered process automation framework.
201
+ # Ignore directories containing user credentials, local state, and settings.
202
+ # Learn more at https://abstra.io/docs
203
+ .abstra/
204
+
205
+ # Visual Studio Code
206
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore that
207
+ # can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
208
+ # and can be added to the global gitignore or merged into this file. However, if you prefer, you
209
+ # could uncomment the following to ignore the entire vscode folder
210
+ # .vscode/
211
+ # Temporary file for partial code execution
212
+ tempCodeRunnerFile.py
213
+
214
+ # Ruff stuff:
215
+ .ruff_cache/
216
+
217
+ # PyPI configuration file
218
+ .pypirc
219
+
220
+ # Marimo
221
+ marimo/_static/
222
+ marimo/_lsp/
223
+ __marimo__/
224
+
225
+ # Streamlit
226
+ .streamlit/secrets.toml
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Carlos A. Rocha
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,145 @@
1
+ Metadata-Version: 2.4
2
+ Name: django-qbe2
3
+ Version: 0.1.0a1
4
+ Summary: A reusable Django app for authorized query-by-example reports.
5
+ Project-URL: Documentation, https://github.com/CARocha/django-qbe2/tree/main/docs
6
+ Project-URL: Repository, https://github.com/CARocha/django-qbe2
7
+ Project-URL: Issues, https://github.com/CARocha/django-qbe2/issues
8
+ Author: Carlos A. Rocha
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Framework :: Django
13
+ Classifier: Framework :: Django :: 6.1
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Requires-Python: <3.15,>=3.14
17
+ Requires-Dist: django<6.2,>=6.1
18
+ Description-Content-Type: text/markdown
19
+
20
+ # Django QBE 2
21
+
22
+ A reusable Django app for building authorized reports without writing SQL.
23
+ Choose columns, add typed conditions, follow model relationships, preview paginated
24
+ results and export a CSV. Designed for **Python 3.14 and Django 6.1**.
25
+
26
+ **Experimental alpha:** this is the initial implementation, not a production
27
+ release or a drop-in replacement for the original package. The first release
28
+ candidate is `0.1.0a1`; check [PyPI](https://pypi.org/project/django-qbe2/) for its
29
+ availability. Inspired by [versae/qbe](https://github.com/versae/qbe), rebuilt around
30
+ Django's ORM, explicit permissions and typed query definitions.
31
+
32
+ ## Try the demo
33
+
34
+ From a checkout containing this implementation:
35
+
36
+ ```sh
37
+ uv sync --python 3.14 --frozen --group dev
38
+ uv run python demo/manage.py migrate
39
+ uv run python demo/manage.py seed_demo
40
+ uv run python demo/manage.py changepassword qbe2_demo_alice
41
+ uv run python demo/manage.py runserver 127.0.0.1:8000
42
+ ```
43
+
44
+ Open [the report builder](http://127.0.0.1:8000/qbe/) and log in as
45
+ `qbe2_demo_alice` with the password you chose. The seed creates six synthetic
46
+ customers and 24 orders for two users. Each user can view only their own records.
47
+ It never sets a shared password or overwrites an existing non-demo account.
48
+ An optional superuser created with `createsuperuser` can inspect all demo records.
49
+
50
+ ## Install in another project
51
+
52
+ Build and install the local wheel in that project's environment:
53
+
54
+ ```sh
55
+ uv build
56
+ python -m pip install /absolute/path/to/dist/django_qbe2-0.1.0a1-py3-none-any.whl
57
+ ```
58
+
59
+ Add the app and mount its namespaced URLs alongside Django Admin:
60
+
61
+ ```python
62
+ # Keep your existing Django apps, including admin, auth, sessions and messages.
63
+ INSTALLED_APPS += ["django_qbe2"]
64
+ ```
65
+
66
+ ```python
67
+ from django.urls import include, path
68
+
69
+ # Keep your existing admin URL and other routes.
70
+ urlpatterns += [path("qbe/", include("django_qbe2.urls"))]
71
+ ```
72
+
73
+ Keep standard authentication, sessions and CSRF middleware, APP_DIRS template
74
+ discovery and the admin context processors. Serve the packaged assets with your
75
+ usual Django static-file setup. The reporting app itself has no models to migrate.
76
+ The catalog is empty until you register reports.
77
+
78
+ ## Register reports and their policies
79
+
80
+ Create `qbe.py` in your own installed app. Modules are discovered at startup,
81
+ without fetching report data. Register related targets as well as root models:
82
+
83
+ ```python
84
+ from django_qbe2.registry import Report, register
85
+ from .models import Customer, Order
86
+
87
+
88
+ @register
89
+ class CustomerReport(Report):
90
+ model = Customer
91
+ fields = ("name",)
92
+
93
+ def get_queryset(self, request):
94
+ return Customer.objects.filter(owner=request.user)
95
+
96
+
97
+ @register
98
+ class OrderReport(Report):
99
+ model = Order
100
+ fields = ("number", "customer__name", "total")
101
+ field_labels = {"customer__name": "Customer", "total": "Total amount"}
102
+
103
+ def get_queryset(self, request):
104
+ return Order.objects.filter(owner=request.user)
105
+ ```
106
+
107
+ Users need active staff status and Django `view` permissions for the root and any
108
+ related model used. Staff status alone does not grant report access. Every report
109
+ must provide an explicit row policy; Django model permissions do not imply row
110
+ authorization. The same policies apply to columns, filters, ordering, HTML and CSV.
111
+
112
+ ## What is included
113
+
114
+ - Text, integer, decimal, boolean, date, datetime and UUID fields.
115
+ - AND conditions, ascending/descending order and stable pagination.
116
+ - One forward ForeignKey/OneToOne hop with related-row authorization.
117
+ - Bounded CSV streaming, exact decimals, Unicode and safe text formula handling.
118
+ - Django Admin styling, light/dark modes and responsive, keyboard-accessible controls.
119
+
120
+ Saved queries, aggregates, OR/NOT groups, ManyToMany, inverse relationships,
121
+ arbitrary joins, multi-database selection, Excel and the visual diagram are later work.
122
+ CSV uses a synchronous streaming iterator intended for WSGI deployment.
123
+ See the [public documentation](https://github.com/CARocha/django-qbe2/blob/main/docs/README.md) for installation, row policies,
124
+ settings, API reference and troubleshooting. Sources are plain English
125
+ reStructuredText under [docs/source](https://github.com/CARocha/django-qbe2/blob/main/docs/source/index.rst), readable by developers
126
+ and agents. Contributor instructions live in [AGENTS.md](https://github.com/CARocha/django-qbe2/blob/main/AGENTS.md).
127
+
128
+ ## Build the documentation
129
+
130
+ ```sh
131
+ uv sync --python 3.14 --frozen --group dev --group docs
132
+ uv run --group docs sphinx-build -n -W -b html docs/source docs/_build/html
133
+ uv run --group docs sphinx-build -n -W -b text docs/source docs/_build/text
134
+ python -m http.server 8001 --bind 127.0.0.1 --directory docs/_build/html
135
+ ```
136
+
137
+ Open http://127.0.0.1:8001/. Sphinx is a documentation dependency only. CI checks
138
+ HTML and plain-text builds with warnings treated as errors. A manual GitHub Pages
139
+ workflow is prepared; the documentation site is not yet published.
140
+
141
+ ## License and attribution
142
+
143
+ MIT, copyright Carlos A. Rocha. The project acknowledges Javier de la Rosa and the
144
+ contributors to `versae/qbe` as its inspiration. The current code is a new
145
+ implementation; preserve upstream notices if you reuse upstream code in a future change.
@@ -0,0 +1,126 @@
1
+ # Django QBE 2
2
+
3
+ A reusable Django app for building authorized reports without writing SQL.
4
+ Choose columns, add typed conditions, follow model relationships, preview paginated
5
+ results and export a CSV. Designed for **Python 3.14 and Django 6.1**.
6
+
7
+ **Experimental alpha:** this is the initial implementation, not a production
8
+ release or a drop-in replacement for the original package. The first release
9
+ candidate is `0.1.0a1`; check [PyPI](https://pypi.org/project/django-qbe2/) for its
10
+ availability. Inspired by [versae/qbe](https://github.com/versae/qbe), rebuilt around
11
+ Django's ORM, explicit permissions and typed query definitions.
12
+
13
+ ## Try the demo
14
+
15
+ From a checkout containing this implementation:
16
+
17
+ ```sh
18
+ uv sync --python 3.14 --frozen --group dev
19
+ uv run python demo/manage.py migrate
20
+ uv run python demo/manage.py seed_demo
21
+ uv run python demo/manage.py changepassword qbe2_demo_alice
22
+ uv run python demo/manage.py runserver 127.0.0.1:8000
23
+ ```
24
+
25
+ Open [the report builder](http://127.0.0.1:8000/qbe/) and log in as
26
+ `qbe2_demo_alice` with the password you chose. The seed creates six synthetic
27
+ customers and 24 orders for two users. Each user can view only their own records.
28
+ It never sets a shared password or overwrites an existing non-demo account.
29
+ An optional superuser created with `createsuperuser` can inspect all demo records.
30
+
31
+ ## Install in another project
32
+
33
+ Build and install the local wheel in that project's environment:
34
+
35
+ ```sh
36
+ uv build
37
+ python -m pip install /absolute/path/to/dist/django_qbe2-0.1.0a1-py3-none-any.whl
38
+ ```
39
+
40
+ Add the app and mount its namespaced URLs alongside Django Admin:
41
+
42
+ ```python
43
+ # Keep your existing Django apps, including admin, auth, sessions and messages.
44
+ INSTALLED_APPS += ["django_qbe2"]
45
+ ```
46
+
47
+ ```python
48
+ from django.urls import include, path
49
+
50
+ # Keep your existing admin URL and other routes.
51
+ urlpatterns += [path("qbe/", include("django_qbe2.urls"))]
52
+ ```
53
+
54
+ Keep standard authentication, sessions and CSRF middleware, APP_DIRS template
55
+ discovery and the admin context processors. Serve the packaged assets with your
56
+ usual Django static-file setup. The reporting app itself has no models to migrate.
57
+ The catalog is empty until you register reports.
58
+
59
+ ## Register reports and their policies
60
+
61
+ Create `qbe.py` in your own installed app. Modules are discovered at startup,
62
+ without fetching report data. Register related targets as well as root models:
63
+
64
+ ```python
65
+ from django_qbe2.registry import Report, register
66
+ from .models import Customer, Order
67
+
68
+
69
+ @register
70
+ class CustomerReport(Report):
71
+ model = Customer
72
+ fields = ("name",)
73
+
74
+ def get_queryset(self, request):
75
+ return Customer.objects.filter(owner=request.user)
76
+
77
+
78
+ @register
79
+ class OrderReport(Report):
80
+ model = Order
81
+ fields = ("number", "customer__name", "total")
82
+ field_labels = {"customer__name": "Customer", "total": "Total amount"}
83
+
84
+ def get_queryset(self, request):
85
+ return Order.objects.filter(owner=request.user)
86
+ ```
87
+
88
+ Users need active staff status and Django `view` permissions for the root and any
89
+ related model used. Staff status alone does not grant report access. Every report
90
+ must provide an explicit row policy; Django model permissions do not imply row
91
+ authorization. The same policies apply to columns, filters, ordering, HTML and CSV.
92
+
93
+ ## What is included
94
+
95
+ - Text, integer, decimal, boolean, date, datetime and UUID fields.
96
+ - AND conditions, ascending/descending order and stable pagination.
97
+ - One forward ForeignKey/OneToOne hop with related-row authorization.
98
+ - Bounded CSV streaming, exact decimals, Unicode and safe text formula handling.
99
+ - Django Admin styling, light/dark modes and responsive, keyboard-accessible controls.
100
+
101
+ Saved queries, aggregates, OR/NOT groups, ManyToMany, inverse relationships,
102
+ arbitrary joins, multi-database selection, Excel and the visual diagram are later work.
103
+ CSV uses a synchronous streaming iterator intended for WSGI deployment.
104
+ See the [public documentation](https://github.com/CARocha/django-qbe2/blob/main/docs/README.md) for installation, row policies,
105
+ settings, API reference and troubleshooting. Sources are plain English
106
+ reStructuredText under [docs/source](https://github.com/CARocha/django-qbe2/blob/main/docs/source/index.rst), readable by developers
107
+ and agents. Contributor instructions live in [AGENTS.md](https://github.com/CARocha/django-qbe2/blob/main/AGENTS.md).
108
+
109
+ ## Build the documentation
110
+
111
+ ```sh
112
+ uv sync --python 3.14 --frozen --group dev --group docs
113
+ uv run --group docs sphinx-build -n -W -b html docs/source docs/_build/html
114
+ uv run --group docs sphinx-build -n -W -b text docs/source docs/_build/text
115
+ python -m http.server 8001 --bind 127.0.0.1 --directory docs/_build/html
116
+ ```
117
+
118
+ Open http://127.0.0.1:8001/. Sphinx is a documentation dependency only. CI checks
119
+ HTML and plain-text builds with warnings treated as errors. A manual GitHub Pages
120
+ workflow is prepared; the documentation site is not yet published.
121
+
122
+ ## License and attribution
123
+
124
+ MIT, copyright Carlos A. Rocha. The project acknowledges Javier de la Rosa and the
125
+ contributors to `versae/qbe` as its inspiration. The current code is a new
126
+ implementation; preserve upstream notices if you reuse upstream code in a future change.
@@ -0,0 +1,20 @@
1
+ # Public documentation
2
+
3
+ Read [source/index.rst](source/index.rst) directly or build the Sphinx site:
4
+
5
+ ```sh
6
+ uv sync --python 3.14 --frozen --group dev --group docs
7
+ uv run --group docs sphinx-build -n -W -b html docs/source docs/_build/html
8
+ uv run --group docs sphinx-build -n -W -b text docs/source docs/_build/text
9
+ python -m http.server 8001 --bind 127.0.0.1 --directory docs/_build/html
10
+ ```
11
+
12
+ Open http://127.0.0.1:8001/. Sources are English reStructuredText. The documentation
13
+ build does not import Django or connect to a database. Generated files are ignored.
14
+ The `docs` group adds no runtime dependencies to the reusable app.
15
+
16
+ Installation: [source/installation.rst](source/installation.rst).
17
+ Demo: [source/quickstart.rst](source/quickstart.rst).
18
+ Permissions: [source/reports.rst](source/reports.rst).
19
+ Contributor and CI checks: [source/contributing.rst](source/contributing.rst).
20
+ Publication: [source/releases.rst](source/releases.rst).
@@ -0,0 +1,51 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "django-qbe2"
7
+ version = "0.1.0a1"
8
+ description = "A reusable Django app for authorized query-by-example reports."
9
+ readme = "README.md"
10
+ requires-python = ">=3.14,<3.15"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "Carlos A. Rocha" }]
14
+ dependencies = ["Django>=6.1,<6.2"]
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Framework :: Django",
18
+ "Framework :: Django :: 6.1",
19
+ "Programming Language :: Python :: 3.14",
20
+ "Intended Audience :: Developers",
21
+ ]
22
+
23
+ [project.urls]
24
+ Documentation = "https://github.com/CARocha/django-qbe2/tree/main/docs"
25
+ Repository = "https://github.com/CARocha/django-qbe2"
26
+ Issues = "https://github.com/CARocha/django-qbe2/issues"
27
+
28
+ [dependency-groups]
29
+ dev = ["ruff>=0.11", "psycopg[binary]>=3.2.10"]
30
+ docs = [
31
+ "sphinx>=8.2,<10",
32
+ ]
33
+ release = [
34
+ "hatchling>=1.27,<2",
35
+ "twine>=6,<7",
36
+ ]
37
+
38
+ [tool.hatch.build.targets.wheel]
39
+ core-metadata-version = "2.4"
40
+ packages = ["src/django_qbe2"]
41
+
42
+ [tool.hatch.build.targets.sdist]
43
+ core-metadata-version = "2.4"
44
+ include = ["src/django_qbe2", "pyproject.toml", "README.md", "LICENSE"]
45
+
46
+ [tool.ruff]
47
+ target-version = "py314"
48
+ line-length = 88
49
+
50
+ [tool.ruff.lint]
51
+ select = ["E", "F", "I", "UP", "B"]
@@ -0,0 +1 @@
1
+ """Reusable, explicitly authorized query-by-example reports for Django."""
@@ -0,0 +1,30 @@
1
+ from collections.abc import Callable
2
+ from functools import wraps
3
+
4
+ from django.contrib.auth.views import redirect_to_login
5
+ from django.core.exceptions import PermissionDenied
6
+ from django.http import Http404, HttpRequest, HttpResponse
7
+ from django.urls import reverse
8
+
9
+ from django_qbe2.catalog import ReportSpec, get_catalog
10
+
11
+
12
+ def require_qbe_access(
13
+ view: Callable[..., HttpResponse],
14
+ ) -> Callable[..., HttpResponse]:
15
+ @wraps(view)
16
+ def wrapped(request: HttpRequest, *args, **kwargs):
17
+ if not request.user.is_authenticated:
18
+ return redirect_to_login(request.get_full_path(), reverse("admin:login"))
19
+ if not request.user.is_active or not request.user.is_staff:
20
+ raise PermissionDenied
21
+ return view(request, *args, **kwargs)
22
+
23
+ return wrapped
24
+
25
+
26
+ def visible_report(request: HttpRequest, report_id: str) -> ReportSpec:
27
+ report = get_catalog(request).get(report_id)
28
+ if report is None:
29
+ raise Http404("Report not available.")
30
+ return report
@@ -0,0 +1,14 @@
1
+ from importlib import import_module
2
+
3
+ from django.apps import AppConfig
4
+ from django.utils.module_loading import autodiscover_modules
5
+
6
+
7
+ class QBEConfig(AppConfig):
8
+ default_auto_field = "django.db.models.BigAutoField"
9
+ name = "django_qbe2"
10
+ verbose_name = "Query by Example"
11
+
12
+ def ready(self):
13
+ import_module("django_qbe2.checks")
14
+ autodiscover_modules("qbe")