django-admin-management-fdg 1.0.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.
Files changed (49) hide show
  1. django_admin_management_fdg-1.0.0/CHANGELOG.md +17 -0
  2. django_admin_management_fdg-1.0.0/LICENSE +21 -0
  3. django_admin_management_fdg-1.0.0/MANIFEST.in +6 -0
  4. django_admin_management_fdg-1.0.0/MIGRATION_GUIDE.md +55 -0
  5. django_admin_management_fdg-1.0.0/PKG-INFO +480 -0
  6. django_admin_management_fdg-1.0.0/README.md +460 -0
  7. django_admin_management_fdg-1.0.0/VALIDATION.md +24 -0
  8. django_admin_management_fdg-1.0.0/docs/PRE_PUBLISH_TEST_GUIDE.md +244 -0
  9. django_admin_management_fdg-1.0.0/docs/scope-guide/SCOPE_GUIDE.md +390 -0
  10. django_admin_management_fdg-1.0.0/docs/scope-guide/images/model-mixed.png +0 -0
  11. django_admin_management_fdg-1.0.0/docs/scope-guide/images/model-scope.png +0 -0
  12. django_admin_management_fdg-1.0.0/docs/scope-guide/images/object-mixed.png +0 -0
  13. django_admin_management_fdg-1.0.0/docs/scope-guide/images/object-scope.png +0 -0
  14. django_admin_management_fdg-1.0.0/example_project/demo/__init__.py +0 -0
  15. django_admin_management_fdg-1.0.0/example_project/demo/admin.py +24 -0
  16. django_admin_management_fdg-1.0.0/example_project/demo/migrations/0001_initial.py +6 -0
  17. django_admin_management_fdg-1.0.0/example_project/demo/migrations/__init__.py +0 -0
  18. django_admin_management_fdg-1.0.0/example_project/demo/models.py +9 -0
  19. django_admin_management_fdg-1.0.0/example_project/demo/tests.py +128 -0
  20. django_admin_management_fdg-1.0.0/example_project/demo/views.py +64 -0
  21. django_admin_management_fdg-1.0.0/example_project/manage.py +8 -0
  22. django_admin_management_fdg-1.0.0/example_project/settings.py +18 -0
  23. django_admin_management_fdg-1.0.0/example_project/templates/demo/external.html +68 -0
  24. django_admin_management_fdg-1.0.0/example_project/templates/demo/item_details.html +50 -0
  25. django_admin_management_fdg-1.0.0/example_project/templates/demo/manage.html +104 -0
  26. django_admin_management_fdg-1.0.0/example_project/templates/demo/reports.html +7 -0
  27. django_admin_management_fdg-1.0.0/example_project/urls.py +13 -0
  28. django_admin_management_fdg-1.0.0/pyproject.toml +36 -0
  29. django_admin_management_fdg-1.0.0/setup.cfg +4 -0
  30. django_admin_management_fdg-1.0.0/src/django_admin_management_fdg/__init__.py +11 -0
  31. django_admin_management_fdg-1.0.0/src/django_admin_management_fdg/apps.py +6 -0
  32. django_admin_management_fdg-1.0.0/src/django_admin_management_fdg/config.py +77 -0
  33. django_admin_management_fdg-1.0.0/src/django_admin_management_fdg/mixins.py +132 -0
  34. django_admin_management_fdg-1.0.0/src/django_admin_management_fdg/static/django_admin_management_fdg/api.js +24 -0
  35. django_admin_management_fdg-1.0.0/src/django_admin_management_fdg/static/django_admin_management_fdg/confirm.js +4 -0
  36. django_admin_management_fdg-1.0.0/src/django_admin_management_fdg/static/django_admin_management_fdg/management.css +7 -0
  37. django_admin_management_fdg-1.0.0/src/django_admin_management_fdg/templates/django_admin_management_fdg/base.html +61 -0
  38. django_admin_management_fdg-1.0.0/src/django_admin_management_fdg/templates/django_admin_management_fdg/buttons.html +24 -0
  39. django_admin_management_fdg-1.0.0/src/django_admin_management_fdg/templates/django_admin_management_fdg/change_form.html +6 -0
  40. django_admin_management_fdg-1.0.0/src/django_admin_management_fdg/templates/django_admin_management_fdg/change_list.html +6 -0
  41. django_admin_management_fdg-1.0.0/src/django_admin_management_fdg/templates/django_admin_management_fdg/components/metric.html +7 -0
  42. django_admin_management_fdg-1.0.0/src/django_admin_management_fdg/templates/django_admin_management_fdg/components/panel.html +4 -0
  43. django_admin_management_fdg-1.0.0/src/django_admin_management_fdg/templatetags/__init__.py +0 -0
  44. django_admin_management_fdg-1.0.0/src/django_admin_management_fdg/templatetags/management_tags.py +11 -0
  45. django_admin_management_fdg-1.0.0/src/django_admin_management_fdg.egg-info/PKG-INFO +480 -0
  46. django_admin_management_fdg-1.0.0/src/django_admin_management_fdg.egg-info/SOURCES.txt +47 -0
  47. django_admin_management_fdg-1.0.0/src/django_admin_management_fdg.egg-info/dependency_links.txt +1 -0
  48. django_admin_management_fdg-1.0.0/src/django_admin_management_fdg.egg-info/requires.txt +1 -0
  49. django_admin_management_fdg-1.0.0/src/django_admin_management_fdg.egg-info/top_level.txt +1 -0
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0
4
+
5
+ First intended public stable release; consolidates the earlier development versions.
6
+
7
+ - Declarative model-level and object-specific buttons, protected management pages and endpoints.
8
+ - Template, custom callable and existing named URL modes (existing URLs are model-scoped only).
9
+ - Scoped permissions, Admin navigation, grouped sibling links and optional confirmation.
10
+ - Endpoint URL tag, fetch helpers, dashboard partials and opt-in endpoint audit logging.
11
+ - Standalone demo, 15 bundled tests, scope guide, template usage guide and integration documentation.
12
+ - Django dependency is `Django>=5.2` without an upper bound; newer versions require compatibility verification.
13
+ - Release metadata updated and distributions rebuilt; see VALIDATION.md for test coverage and limitations.
14
+
15
+ ## 0.1.0 and 1.0.0rc1 (development milestones)
16
+
17
+ Internal development versions introducing the core infrastructure and extended functionality respectively; superseded by 1.0.0.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Founder Design Group
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,6 @@
1
+ include README.md LICENSE CHANGELOG.md MIGRATION_GUIDE.md VALIDATION.md
2
+ recursive-include src/django_admin_management_fdg/templates *.html
3
+ recursive-include src/django_admin_management_fdg/static *.css *.js
4
+ recursive-include example_project *.py *.html
5
+
6
+ recursive-include docs *.md *.png
@@ -0,0 +1,55 @@
1
+ # Migration notes: United Supermarket Adelaide
2
+
3
+ This is a generic new library, not a modification of the production apps. Keep existing business logic and URL protections. Test in staging first.
4
+
5
+ ## Flyer Manifest
6
+
7
+ `FlyerFileAdmin` currently sets `change_list_template`, injects `upload_page_url` via `changelist_view`, and uses a hardcoded `/flyer-manifest/upload-page/`. Replace just the button wiring with:
8
+
9
+ ```python
10
+ class FlyerFileAdmin(ManagementAdminMixin, admin.ModelAdmin):
11
+ management_pages = (
12
+ ManagementPage(name="staff_upload", label="Staff Upload Page", icon="🖼️",
13
+ url_name="flyer_upload_page",
14
+ permission="flyer_manifest.can_upload_flyer"),
15
+ )
16
+ # Keep existing list_display, filters, fields and other methods.
17
+ ```
18
+
19
+ Remove old button-specific template override/context/CSS only after checking it has no other responsibilities. Existing named routes and upload/edit/reorder/cron views stay intact. If the root project namespaces this URLconf, use the actual qualified URL name. Preserve the separate `flyer_manifest.can_run_flyer_manifest_cron` check and independently verify staff-only access on existing routes.
20
+
21
+ ## Site Notifications
22
+
23
+ `SiteNotificationAdmin` currently injects `manage_page_url` using `/site-notifications/manage/`. Configure:
24
+
25
+ ```python
26
+ management_pages = (
27
+ ManagementPage(name="notifications", label="Manage Notifications", icon="🔔",
28
+ url_name="notifications_manage",
29
+ permission="site_notifications.can_manage_notifications"),
30
+ )
31
+ ```
32
+
33
+ Add the mixin before ModelAdmin. Keep the existing `save_model`, role display, date/time logic and all existing API and cron permission checks. The named URL approach preserves the existing page design and current AJAX URLs; add navigation to that template yourself or migrate it to an internal page later.
34
+
35
+ ## Jobs
36
+
37
+ `JobPostAdmin` currently registers `manage/`, `manage/create/`, `manage/edit/<uuid:pk>/`, `manage/delete/<uuid:pk>/`, and `manage/run-cron/` in `get_urls()`. It also has app-level aliases in `job.urls`. For the lowest-risk initial migration retain its existing `get_urls` and views, remove the old button wiring and add:
38
+
39
+ ```python
40
+ management_pages = (
41
+ ManagementPage(name="jobs", label="Manage Jobs", icon="💼",
42
+ url_name="admin:job_jobpost_manage",
43
+ permission="job.can_upload_job"),
44
+ )
45
+ ```
46
+
47
+ This assumes the default AdminSite namespace. Preserve existing protection and `job.can_run_job_cron`. For a later full migration use `view=JobManagePageView.as_view()` and `ManagementEndpoint` for the create/edit/delete/run-cron views. Update all existing template URL tags, view URL reversals and JavaScript URL references to the new generated names before removing old routes. Do not change public job application or scheduled cron URLs as part of this migration. Verify HTTP methods against the existing views and preserve UUID converters.
48
+
49
+ ## Common checklist
50
+
51
+ - Add package and mixin imports; keep original models, migrations and business logic.
52
+ - Confirm existing project URL namespaces with `reverse()`.
53
+ - Test authorized and unauthorized users, direct endpoint requests, CSRF, and all existing CRUD and publishing operations.
54
+ - Test original navigation, styling, language and timezone behavior.
55
+ - Run collectstatic and restart after deployment.
@@ -0,0 +1,480 @@
1
+ Metadata-Version: 2.4
2
+ Name: django-admin-management-fdg
3
+ Version: 1.0.0
4
+ Summary: Reusable custom management pages and buttons for Django Admin
5
+ Author: Founder Design Group
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/huachenlihx/django-admin-management-fdg
8
+ Project-URL: Repository, https://github.com/huachenlihx/django-admin-management-fdg
9
+ Project-URL: Documentation, https://github.com/huachenlihx/django-admin-management-fdg#readme
10
+ Project-URL: Issues, https://github.com/huachenlihx/django-admin-management-fdg/issues
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Framework :: Django
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Operating System :: OS Independent
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: Django>=5.2
19
+ Dynamic: license-file
20
+
21
+ # Django Admin Management FDG
22
+
23
+ Version **1.0.0**. Add model-level and object-specific management buttons, custom pages and protected endpoints to Django Admin, without database migrations or a DRF dependency. Requires Python 3.10+ and Django 5.2 or newer, with no upper Django dependency limit. Newer Django releases are permitted by the installer, not automatically certified compatible. The bundled tests pass on Django 5.2.19 with Python 3.13; see VALIDATION.md for the remaining compatibility checks.
24
+
25
+ ## Documentation
26
+
27
+ - [Understanding model and object scopes (illustrated guide)](docs/scope-guide/SCOPE_GUIDE.md)
28
+ - [Testing in a separate Django project](docs/PRE_PUBLISH_TEST_GUIDE.md)
29
+ - [Migration guide](MIGRATION_GUIDE.md)
30
+ - [Validation results and limitations](VALIDATION.md)
31
+ - [MIT License](LICENSE)
32
+
33
+ ## Install
34
+
35
+ Once published: `pip install django-admin-management-fdg`. From this source checkout: `python -m pip install -e .`.
36
+
37
+ Add `django_admin_management_fdg` to `INSTALLED_APPS`. Keep the usual Django admin apps, session/authentication/CSRF/messages middleware and template context processors. Set `APP_DIRS=True` and `DIRS=[BASE_DIR / "templates"]` in the Django template backend to use project-level templates. No package migrations or root URL changes are needed for internally registered routes.
38
+
39
+ ## Quick start
40
+
41
+ ```python
42
+ from django.contrib import admin
43
+ from django_admin_management_fdg import ManagementAdminMixin, ManagementPage
44
+ from .models import JobPost
45
+
46
+ @admin.register(JobPost)
47
+ class JobPostAdmin(ManagementAdminMixin, admin.ModelAdmin):
48
+ management_pages = (
49
+ ManagementPage(name="manage_jobs", label="Manage Jobs", icon="💼",
50
+ template_name="job/manage_jobs.html",
51
+ permission="job.view_jobpost"),
52
+ ManagementPage(name="reports", label="Reports", icon="📊",
53
+ template_name="job/reports.html", order=10),
54
+ )
55
+ ```
56
+
57
+ Create `templates/job/manage_jobs.html` and `templates/job/reports.html`:
58
+
59
+ ```html
60
+ {% extends 'django_admin_management_fdg/base.html' %}
61
+ {% block management_content %}
62
+ <h1>My custom page</h1>
63
+ <p>Put your own forms, tables and JavaScript here.</p>
64
+ {% endblock %}
65
+ ```
66
+
67
+ The package places buttons next to the standard Add button. Generated routes follow `<admin-prefix>/<app>/<model>/manage/<name>/`. The base template uses Django's admin theme, includes breadcrumbs and links back to the model and Admin home. Use `management_css` and `management_js` blocks for additional styles and scripts. An independent template is also supported; use `management_parent_url` and `management_admin_home_url` for navigation.
68
+
69
+ ## Built-in templates and how to use them
70
+
71
+ The package ships six reusable Django templates. They are installed with the package; you do not need to copy them into your project to use them. Keep `APP_DIRS=True` and configure your project template directory as described in [Install](#install).
72
+
73
+ ```text
74
+ django_admin_management_fdg/templates/
75
+ └── django_admin_management_fdg/
76
+ ├── base.html
77
+ ├── buttons.html
78
+ ├── change_list.html
79
+ ├── change_form.html
80
+ └── components/
81
+ ├── metric.html
82
+ └── panel.html
83
+ ```
84
+
85
+ | Template (relative to `django_admin_management_fdg/`) | Purpose | How to use |
86
+ |---|---|---|
87
+ | `base.html` | Admin-themed management page with breadcrumbs, navigation and sibling links | Extend in your own management template |
88
+ | `buttons.html` | Renders authorized management buttons, labels, groups, icons, styles and confirmation attributes | Included automatically by the two Admin wrappers; include manually in custom Admin templates if needed |
89
+ | `change_list.html` | Adds model-scope buttons to the Admin list page | Used through `ManagementAdminMixin` |
90
+ | `change_form.html` | Adds object-scope buttons to the existing object's change page | Used through `ManagementAdminMixin` |
91
+ | `components/metric.html` | Displays a label, value and optional description | Include in a dashboard or management page |
92
+ | `components/panel.html` | Displays a heading and description | Include in a dashboard or management page |
93
+
94
+ ### 1. `base.html`: create a management page
95
+
96
+ Create your own template under the project-level `templates/` directory, for example `templates/job/manage_jobs.html`. Do not edit the installed package's base template for ordinary page customization.
97
+
98
+ ```django
99
+ {% extends "django_admin_management_fdg/base.html" %}
100
+ {% load static %}
101
+
102
+ {% block management_css %}
103
+ <link rel="stylesheet" href="{% static 'job/manage.css' %}">
104
+ {% endblock %}
105
+
106
+ {% block management_js %}
107
+ <script defer src="{% static 'job/manage.js' %}"></script>
108
+ {% endblock %}
109
+
110
+ {% block management_content %}
111
+ <h2>Manage jobs</h2>
112
+ <p>Add your forms, tables, reports and API-driven operations here.</p>
113
+ {% endblock %}
114
+ ```
115
+
116
+ The CSS and JavaScript blocks are optional. If you use the example assets, create `job/static/job/manage.css` and `job/static/job/manage.js` in your app. Scripts placed in `management_js` are loaded in the Admin document head; use `defer` for scripts that need the page DOM.
117
+
118
+ Register the template in your `ManagementAdminMixin` subclass:
119
+
120
+ ```python
121
+ ManagementPage(
122
+ name="manage_jobs",
123
+ label="Manage Jobs",
124
+ scope="model",
125
+ template_name="job/manage_jobs.html",
126
+ permission="job.view_jobpost",
127
+ )
128
+ ```
129
+
130
+ The base extends `admin/base_site.html`, loads the package stylesheet and confirmation script, and supplies navigation. Its relevant template context is:
131
+
132
+ | Variable | Purpose |
133
+ |---|---|
134
+ | `title` | Management page title |
135
+ | `opts` | Django model metadata |
136
+ | `management_admin_home_url` | Admin home URL |
137
+ | `management_app_url` | Admin application list URL |
138
+ | `management_parent_url` | Parent changelist or object change form URL |
139
+ | `management_page` | Current management page configuration |
140
+ | `management_siblings` | Permitted sibling management links of the same scope |
141
+ | `management_object` | Selected instance for an object-scope page |
142
+
143
+ For an object page you can use `{{ management_object.pk }}` and the instance's fields in `management_content`. For a custom view returning an unrendered `TemplateResponse`, the package supplies its context automatically; for an eager `render()` response, merge `request.fdg_management_context` before rendering. A page reached through `url_name` does not receive these variables automatically: its own view must supply context, navigation and permissions. An independent existing page can instead extend `admin/base_site.html` and use its AdminSite's `each_context(request)`.
144
+
145
+ ### 2. `buttons.html`: render management links in a custom Admin template
146
+
147
+ Normally the mixin renders this partial automatically. It consumes `fdg_management_buttons`, a collection of button entries containing `url` and `page`. It renders `<li>` elements, so include it inside the Admin object-tools list, not as a standalone page. Button appearance and confirmation text come from the `ManagementPage` configuration, not from hardcoded links in your template.
148
+
149
+ If you already override `change_list_template`, you can preserve your template and add the partial:
150
+
151
+ ```django
152
+ {% extends "admin/change_list.html" %}
153
+
154
+ {% block object-tools-items %}
155
+ {% include "django_admin_management_fdg/buttons.html" %}
156
+ {{ block.super }}
157
+ {% endblock %}
158
+ ```
159
+
160
+ For a custom object change form, extend `admin/change_form.html` instead and use the same block. Preserve `{{ block.super }}` to retain Django's standard tools. Do not include the partial twice. Button visibility is not a replacement for server-side authorization.
161
+
162
+ ### 3. `change_list.html`: model-level buttons
163
+
164
+ The package wrapper extends the template specified by `fdg_management_changelist_base`, defaulting to `admin/change_list.html`, and includes the buttons partial in `object-tools-items`.
165
+
166
+ With the mixin and `scope="model"`, no explicit template override is normally required. To retain a custom underlying changelist, set this on your ModelAdmin:
167
+
168
+ ```python
169
+ management_changelist_base = "job/admin/custom_change_list.html"
170
+ ```
171
+
172
+ The custom base must extend a normal Admin changelist, not the package's wrapper. Remove a competing `change_list_template` override if you choose this approach. Keep its `object-tools-items` block cooperative and do not add the buttons partial there again.
173
+
174
+ ### 4. `change_form.html`: object-level buttons
175
+
176
+ This wrapper uses `fdg_management_changeform_base`, defaulting to `admin/change_form.html`. Define an object-scope page to add a button to an existing record's change form:
177
+
178
+ ```python
179
+ ManagementPage(
180
+ name="preview",
181
+ label="Preview Job",
182
+ scope="object",
183
+ template_name="job/preview.html",
184
+ permission="job.view_jobpost",
185
+ )
186
+ ```
187
+
188
+ For example, `templates/job/preview.html`:
189
+
190
+ ```django
191
+ {% extends "django_admin_management_fdg/base.html" %}
192
+
193
+ {% block management_content %}
194
+ <h2>{{ management_object.title }}</h2>
195
+ <p>Job ID: {{ management_object.pk }}</p>
196
+ {% endblock %}
197
+ ```
198
+
199
+ If you have a custom underlying change form, set:
200
+
201
+ ```python
202
+ management_changeform_base = "job/admin/custom_change_form.html"
203
+ ```
204
+
205
+ The custom base must extend a normal Admin change form, not the package wrapper. Remove a competing `change_form_template` override when using this approach. Alternatively, keep your direct override and include the buttons partial as in section 2. Object-scope buttons are for saved objects, not add forms.
206
+
207
+ ### 5. `components/metric.html`: display a metric
208
+
209
+ Include this component within your management page. It accepts `label`, `value` and optional `description`.
210
+
211
+ ```django
212
+ {% include "django_admin_management_fdg/components/metric.html" with label="Total jobs" value=total_jobs description="All job postings" only %}
213
+ ```
214
+
215
+ `value` is supplied by your view; the component does not query the database or calculate statistics. The `only` keyword isolates the included template's context to the supplied arguments.
216
+
217
+ ### 6. `components/panel.html`: display a text panel
218
+
219
+ This component accepts `heading` and `description`. It is a simple text panel, not a block-based container for arbitrary nested HTML.
220
+
221
+ ```django
222
+ {% include "django_admin_management_fdg/components/panel.html" with heading="Publishing status" description="Review scheduled jobs before publishing." only %}
223
+ ```
224
+
225
+ ### Complete dashboard example
226
+
227
+ In `job/views.py`, assuming your `JobPost` model has an `is_published` database field:
228
+
229
+ ```python
230
+ from django.template.response import TemplateResponse
231
+ from .models import JobPost
232
+
233
+
234
+ def reports(request):
235
+ return TemplateResponse(
236
+ request,
237
+ "job/reports.html",
238
+ {
239
+ "total_jobs": JobPost.objects.count(),
240
+ "published_jobs": JobPost.objects.filter(is_published=True).count(),
241
+ },
242
+ )
243
+ ```
244
+
245
+ Adapt the query to your actual model fields and restrict the queryset to records the user may view where required. Register the view in your ModelAdmin:
246
+
247
+ ```python
248
+ ManagementPage(
249
+ name="reports",
250
+ label="Reports",
251
+ scope="model",
252
+ view=views.reports,
253
+ permission="job.view_jobpost",
254
+ )
255
+ ```
256
+
257
+ Import `views` from your app in `admin.py`. Use `view` instead of `template_name` here, not both.
258
+
259
+ Create `templates/job/reports.html`:
260
+
261
+ ```django
262
+ {% extends "django_admin_management_fdg/base.html" %}
263
+
264
+ {% block management_content %}
265
+ <div class="fdg-dashboard">
266
+ {% include "django_admin_management_fdg/components/metric.html" with label="Total jobs" value=total_jobs only %}
267
+ {% include "django_admin_management_fdg/components/metric.html" with label="Published" value=published_jobs only %}
268
+ {% include "django_admin_management_fdg/components/panel.html" with heading="Status" description="Review publishing activity here." only %}
269
+ </div>
270
+ {% endblock %}
271
+ ```
272
+
273
+ The package stylesheet loaded by `base.html` supplies the component styles. If using the components in an independent template, load `static` and include `django_admin_management_fdg/management.css` yourself; the components rely on Admin theme variables.
274
+
275
+ ### Template discovery and local testing
276
+
277
+ From a Django project with the package installed and configured:
278
+
279
+ ```bash
280
+ python manage.py check
281
+ python manage.py shell -c "from django.template.loader import get_template; print(get_template('django_admin_management_fdg/base.html').origin)"
282
+ python manage.py findstatic django_admin_management_fdg/management.css django_admin_management_fdg/confirm.js
283
+ python manage.py runserver
284
+ ```
285
+
286
+ Open the model's Admin list page, test the model-level buttons, open a saved object and test its object-level buttons, then verify breadcrumbs, Back navigation, dashboard components and both Admin themes. In production, run `python manage.py collectstatic --noinput` as part of normal deployment. Changing only HTML templates does not require migrations or collecting static files again. If modifying the package itself, an editable install uses the updated source templates; rebuild the wheel for distribution testing.
287
+
288
+
289
+ ## Three page modes
290
+
291
+ Provide exactly one of `template_name`, `view`, or `url_name`.
292
+
293
+ - `template_name`: automatically rendered with Admin context; GET/HEAD only.
294
+ - `view`: a Django callable or class-based view via `.as_view()`; GET/HEAD only. Unrendered `TemplateResponse` receives the package's context automatically. For `render()` or eager responses, explicitly merge `request.fdg_management_context` before rendering. Existing context values override package defaults.
295
+ - `url_name`: a pre-existing reversible named URL with no required arguments. This only adds the link. The destination and its API endpoints must enforce their own authentication, permissions, CSRF, and HTTP methods. Existing pages own their navigation. Do not treat link visibility as security.
296
+
297
+ The mixin must precede `admin.ModelAdmin` in the inheritance list. Preserve cooperative `super()` calls in overrides. `management_pages` is static per registered model; do not vary it by request because the URLconf is built independently of requests.
298
+
299
+ ## Endpoints and custom views
300
+
301
+ ```python
302
+ from django_admin_management_fdg import ManagementPage, ManagementEndpoint
303
+ from .views import ManageJobsView, create_job, run_cron
304
+
305
+ management_pages = (
306
+ ManagementPage(name="jobs", label="Manage Jobs", view=ManageJobsView.as_view(),
307
+ permission="job.view_jobpost", endpoints=(
308
+ ManagementEndpoint("create/", "create", create_job,
309
+ methods=("POST",), permission="job.add_jobpost"),
310
+ ManagementEndpoint("run-cron/", "run_cron", run_cron,
311
+ methods=("POST",), permission="job.can_run_job_cron"),
312
+ )),
313
+ )
314
+ ```
315
+
316
+ Endpoints are registered relative to their page and can use Django converters, e.g. `edit/<uuid:pk>/`. Reverse names are generated internally; do not hardcode them. In a management template:
317
+
318
+ ```html
319
+ {% load static management_tags %}
320
+ <form id="job-form" data-url="{% management_endpoint_url 'create' %}">
321
+ {% csrf_token %}
322
+ <input name="title" required>
323
+ <button type="submit">Create</button>
324
+ </form>
325
+ <script type="module">
326
+ import { apiFetch } from "{% static 'django_admin_management_fdg/api.js' %}";
327
+ const form = document.getElementById('job-form');
328
+ form.addEventListener('submit', async (event) => {
329
+ event.preventDefault();
330
+ try {
331
+ await apiFetch(form.dataset.url, {method: 'POST', body: new FormData(form)});
332
+ location.reload();
333
+ } catch (error) { alert(error.message); }
334
+ });
335
+ </script>
336
+ ```
337
+
338
+ For a parameterized route use `{% management_endpoint_url 'edit' pk=object.pk %}`. For JSON requests set `Content-Type: application/json` and serialize the body yourself. The helper supports same-origin requests only; it prefers the rendered CSRF form token and otherwise uses the default `csrftoken` cookie. Include `{% csrf_token %}` for custom cookie names, session-backed tokens or HTTP-only cookies. It rejects redirects (including expired login redirects) and throws on HTTP errors. It does not implement automatic retries. Optional utilities: `getCsrfToken`, `setLoading`, `showStatus`, `confirmAction`.
339
+
340
+ ## Configuration reference
341
+
342
+ | ManagementPage property | Meaning |
343
+ |---|---|
344
+ | name | Unique lowercase identifier (letters/digits/underscore, starts with letter) |
345
+ | label | Button and page title |
346
+ | template_name / view / url_name | Exactly one destination |
347
+ | permission | Additional Django permission (`app.codename`), optional |
348
+ | icon / tooltip | Optional escaped text |
349
+ | color / text_color | Optional six-digit hex colors |
350
+ | button_style | `pill` (native default), `rounded`, `square` |
351
+ | order | Integer sorting key; equal values retain declaration order |
352
+ | endpoints | Tuple of `ManagementEndpoint` configurations |
353
+ | scope | `model` (default) or `object` |
354
+ | group | Optional button/navigation group |
355
+ | confirmation | Optional browser confirmation text |
356
+ | audit | Enable endpoint activity logging (default `False`) |
357
+
358
+ `ManagementEndpoint(route, name, view, methods=("POST",), permission=None)` registers an additional protected callable. Endpoint names and literal routes must be unique within the page. Avoid overlapping converter patterns; Django resolves in declaration order.
359
+
360
+ ## Permissions and security
361
+
362
+ Internally registered pages and endpoints require the AdminSite's permission (active staff by default), model view or change permission, and the optional page permission. Endpoints additionally enforce their own optional permission and HTTP method allowlist. CSRF is enforced even when a supplied callable declares itself exempt. Admin routes use the AdminSite wrapper and are not cached by default. Do not use GET for mutations. The package does not decide custom object-level authorization, input validation, rate limits, transaction boundaries, durable audit retention, or business rules: these belong in your application. Never pass cron credentials to browser JavaScript. Use protected POST endpoints that call server-side publishing services or management commands. Avoid exposing duplicate unprotected routes.
363
+
364
+ To customize permission policy, override `has_management_permission(request, page, obj=None)` carefully, retaining staff and model authorization unless you have a deliberate alternative. Buttons and internal routes use this same hook. Existing named URLs remain independently protected.
365
+
366
+ ## Existing admin templates / branding
367
+
368
+ The package uses an opt-in changelist template, not a global override. To preserve an existing custom changelist set `management_changelist_base = "path/to/original.html"` and remove the old `change_list_template` override. The original must extend a normal Admin changelist and must not extend the package changelist (avoid recursion). Alternatively keep your existing `change_list_template` and explicitly include `{% include 'django_admin_management_fdg/buttons.html' %}` inside its `object-tools-items` block, preserving `{{ block.super }}`. Remove old duplicate buttons. Custom AdminSite names and URL prefixes are supported by reversing instance names. Branding extensions that customize `admin/base_site.html` should compose normally; actual compatibility with third-party themes must be tested.
369
+
370
+ ## Example project and tests
371
+
372
+ ```bash
373
+ python3 -m venv .venv
374
+ source .venv/bin/activate
375
+ python -m pip install -e .
376
+ python example_project/manage.py migrate
377
+ python example_project/manage.py createsuperuser
378
+ python example_project/manage.py runserver
379
+ ```
380
+
381
+ Visit `http://127.0.0.1:8000/admin/demo/item/` and try Manage Items, Reports, Existing Page. The example supports creating, publishing, deleting and manually running a bulk publishing operation. A second admin instance is at `/operations/`. Example settings and secret are development-only. The example uses SQLite; the reusable package has no database tables.
382
+
383
+ ```bash
384
+ python example_project/manage.py check
385
+ python example_project/manage.py test demo --verbosity 2
386
+ python example_project/manage.py collectstatic --noinput
387
+ ```
388
+
389
+ On cPanel, add the package to your requirements, install in the application's environment, run `collectstatic --noinput` and restart the deployed application. Use your normal production WSGI/ASGI deployment; do not run Django's development server in production.
390
+
391
+ ## Build and publish
392
+
393
+ ```bash
394
+ python -m pip install --upgrade build twine
395
+ rm -rf dist build
396
+ python -m build
397
+ python -m twine check dist/*
398
+ python -m twine upload --repository testpypi dist/*
399
+ # After validating the TestPyPI distribution:
400
+ python -m twine upload dist/*
401
+ ```
402
+
403
+ The manual GitHub publishing workflow uses PyPI Trusted Publishing; configure the matching repository, workflow and `pypi` environment in PyPI first. Never commit API tokens. Review the license and author metadata before publishing. No publishing has been performed.
404
+
405
+ See `MIGRATION_GUIDE.md` for the three motivating applications.
406
+
407
+ ## Extended functionality in 1.0
408
+
409
+ Existing model-level
410
+ configurations still default to `scope="model"`.
411
+
412
+ ### Object-specific pages
413
+
414
+ Add a page to `management_pages` with `scope="object"`. Its button appears on
415
+ existing object change forms (not on add forms or the changelist). For example:
416
+
417
+ ```python
418
+ ManagementPage(
419
+ name="details", label="Details", scope="object",
420
+ template_name="demo/item_details.html", permission="demo.view_item",
421
+ group="Item", confirmation="Open details?", audit=True,
422
+ )
423
+ ```
424
+
425
+ The package uses `ModelAdmin.get_object()` (and therefore its queryset) to
426
+ resolve the quoted object ID. It checks `has_view_or_change_permission(request,
427
+ obj)` and any explicit page and endpoint permissions. For custom views and
428
+ endpoints the resolved instance is `request.fdg_management_object`. Do not
429
+ trust an alternate object ID supplied by the client. Add explicit mutation
430
+ permissions to every write endpoint, including object-level permission checks
431
+ where your application needs them. The template receives `management_object`;
432
+ `management_parent_url` points back to its change form. The
433
+ `management_endpoint_url` tag automatically includes the object ID.
434
+ Object pages cannot use `url_name`; external routes remain model-level only.
435
+ Override `has_management_permission(self, request, page, obj=None)` for custom
436
+ policies; existing two-argument overrides continue to work for model pages.
437
+
438
+ ### Groups, navigation and confirmation
439
+
440
+ `group="Operations"` labels related buttons and groups sibling navigation on
441
+ managed pages. The sibling navigation only lists permitted pages of the same
442
+ scope. `confirmation="Continue?"` enables an optional browser confirmation
443
+ when following a link. It is a UX convenience, not authorization. For destructive
444
+ API actions use the optional `confirmAction()` JS utility and enforce server-side
445
+ permissions and CSRF protection independently. Custom changelist and change form
446
+ templates must include the package's buttons partial, or set
447
+ `management_changelist_base` and `management_changeform_base` to your own base
448
+ paths. If you override admin template attributes directly, you must include the
449
+ partial yourself.
450
+
451
+ ### Audit logging
452
+
453
+ Set `audit=True` on a managed page to emit INFO records for endpoint responses
454
+ through `django_admin_management_fdg.audit`. Configure Django LOGGING with a
455
+ handler and retention policy. Extra fields are `fdg_actor`, `fdg_model`,
456
+ `fdg_object`, `fdg_page`, `fdg_endpoint`, `fdg_method`, and `fdg_status`.
457
+ The package does not store request bodies, tokens, or audit database rows. This
458
+ records returned endpoint responses only, not denied requests, unhandled
459
+ exceptions or changes made outside these endpoints; it is not a compliance audit
460
+ trail. External views are responsible for their own audit logging.
461
+
462
+ ### Dashboard components
463
+
464
+ ```django
465
+ <div class="fdg-dashboard">
466
+ {% include 'django_admin_management_fdg/components/metric.html' with label='Items' value=item_count only %}
467
+ {% include 'django_admin_management_fdg/components/panel.html' with heading='Status' description='Ready' only %}
468
+ </div>
469
+ ```
470
+
471
+ These components use admin theme variables. See the example object's Details
472
+ and Preview buttons for a working integration example to test locally.
473
+
474
+ ### Release verification
475
+
476
+ Version `1.0.0` is the first stable-version release, following the maintainer's local testing. See [validation results](VALIDATION.md) for independently executed checks and remaining limitations. Before upload, run the CI matrix for Django 5.2, 6.0 and 6.1, verify browser behavior and staging integrations, and run `python -m twine check dist/*`. The manual publish workflow intentionally blocks prerelease versions.
477
+
478
+ ## License
479
+
480
+ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.