django-admin-contexts 0.2.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_admin_contexts-0.2.0/.gitignore +92 -0
- django_admin_contexts-0.2.0/AUTHORS.md +7 -0
- django_admin_contexts-0.2.0/LICENSE +21 -0
- django_admin_contexts-0.2.0/PKG-INFO +121 -0
- django_admin_contexts-0.2.0/README.md +80 -0
- django_admin_contexts-0.2.0/django_admin_contexts/__about__.py +1 -0
- django_admin_contexts-0.2.0/django_admin_contexts/__init__.py +0 -0
- django_admin_contexts-0.2.0/django_admin_contexts/admin.py +14 -0
- django_admin_contexts-0.2.0/django_admin_contexts/apps.py +6 -0
- django_admin_contexts-0.2.0/django_admin_contexts/forms.py +12 -0
- django_admin_contexts-0.2.0/django_admin_contexts/migrations/0001_initial.py +29 -0
- django_admin_contexts-0.2.0/django_admin_contexts/migrations/__init__.py +0 -0
- django_admin_contexts-0.2.0/django_admin_contexts/models.py +19 -0
- django_admin_contexts-0.2.0/django_admin_contexts/templates/admin/app_list.html +51 -0
- django_admin_contexts-0.2.0/django_admin_contexts/templatetags/django_admin_contexts_tags.py +54 -0
- django_admin_contexts-0.2.0/django_admin_contexts/urls.py +0 -0
- django_admin_contexts-0.2.0/django_admin_contexts/views.py +0 -0
- django_admin_contexts-0.2.0/pyproject.toml +116 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
### OSX ###
|
|
2
|
+
.DS_Store
|
|
3
|
+
.AppleDouble
|
|
4
|
+
.LSOverride
|
|
5
|
+
|
|
6
|
+
### SublimeText ###
|
|
7
|
+
# cache files for sublime text
|
|
8
|
+
*.tmlanguage.cache
|
|
9
|
+
*.tmPreferences.cache
|
|
10
|
+
*.stTheme.cache
|
|
11
|
+
|
|
12
|
+
# workspace files are user-specific
|
|
13
|
+
*.sublime-workspace
|
|
14
|
+
|
|
15
|
+
# project files should be checked into the repository, unless a significant
|
|
16
|
+
# proportion of contributors will probably not be using SublimeText
|
|
17
|
+
# *.sublime-project
|
|
18
|
+
|
|
19
|
+
# sftp configuration file
|
|
20
|
+
sftp-config.json
|
|
21
|
+
|
|
22
|
+
# Basics
|
|
23
|
+
*.py[cod]
|
|
24
|
+
__pycache__
|
|
25
|
+
|
|
26
|
+
# Logs
|
|
27
|
+
*.log
|
|
28
|
+
pip-log.txt
|
|
29
|
+
|
|
30
|
+
# Unit test / coverage reports
|
|
31
|
+
.coverage
|
|
32
|
+
coverage.json
|
|
33
|
+
coverage.xml
|
|
34
|
+
.tox
|
|
35
|
+
nosetests.xml
|
|
36
|
+
htmlcov
|
|
37
|
+
|
|
38
|
+
# Translations
|
|
39
|
+
*.mo
|
|
40
|
+
*.pot
|
|
41
|
+
|
|
42
|
+
# Pycharm
|
|
43
|
+
.idea/*
|
|
44
|
+
|
|
45
|
+
# Vim
|
|
46
|
+
|
|
47
|
+
*~
|
|
48
|
+
*.swp
|
|
49
|
+
*.swo
|
|
50
|
+
|
|
51
|
+
# npm
|
|
52
|
+
node_modules/
|
|
53
|
+
|
|
54
|
+
# Compass
|
|
55
|
+
.sass-cache
|
|
56
|
+
|
|
57
|
+
# virtual environments
|
|
58
|
+
.env
|
|
59
|
+
|
|
60
|
+
# User-uploaded media
|
|
61
|
+
matorral/media/
|
|
62
|
+
staticfiles/
|
|
63
|
+
|
|
64
|
+
# Hitch directory
|
|
65
|
+
tests/.hitch
|
|
66
|
+
|
|
67
|
+
# sqlite db
|
|
68
|
+
*.db
|
|
69
|
+
*.db-journal
|
|
70
|
+
|
|
71
|
+
# celery beat
|
|
72
|
+
celerybeat-schedule.db
|
|
73
|
+
celerybeat.pid
|
|
74
|
+
|
|
75
|
+
# pyenv
|
|
76
|
+
.python-version
|
|
77
|
+
|
|
78
|
+
.idea
|
|
79
|
+
|
|
80
|
+
.editorconfig
|
|
81
|
+
|
|
82
|
+
matorral.egg-info/
|
|
83
|
+
.pytest_cache/
|
|
84
|
+
celerybeat-schedule
|
|
85
|
+
|
|
86
|
+
TODO.md
|
|
87
|
+
|
|
88
|
+
data/
|
|
89
|
+
|
|
90
|
+
# Build files
|
|
91
|
+
dist/
|
|
92
|
+
build/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present, Matias Agustin Mendez and django-admin-contexts contributors
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: django-admin-contexts
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Contexts for Django Admin homepage
|
|
5
|
+
Project-URL: Homepage, https://github.com/matagus/django-admin-contexts
|
|
6
|
+
Project-URL: Issues, https://.github.com/matagus/django-admin-contexts/issues
|
|
7
|
+
Project-URL: Repository, https://github.com/matagus/django-admin-contexts
|
|
8
|
+
Project-URL: Changelog, https://githib.com/matagus/django-admin-contexts/releases
|
|
9
|
+
Project-URL: Pypi, https://pypi.org/project/django-admin-contexts
|
|
10
|
+
Author-email: Matias Agustin Mendez <matagus@gmail.com>
|
|
11
|
+
License-Expression: BSD-3-Clause
|
|
12
|
+
License-File: AUTHORS.md
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
15
|
+
Classifier: Environment :: Console
|
|
16
|
+
Classifier: Environment :: Web Environment
|
|
17
|
+
Classifier: Framework :: Django
|
|
18
|
+
Classifier: Framework :: Django :: 4.0
|
|
19
|
+
Classifier: Framework :: Django :: 4.1
|
|
20
|
+
Classifier: Framework :: Django :: 4.2
|
|
21
|
+
Classifier: Framework :: Django :: 5.0
|
|
22
|
+
Classifier: Intended Audience :: Developers
|
|
23
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
24
|
+
Classifier: Natural Language :: English
|
|
25
|
+
Classifier: Programming Language :: Python
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
27
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
28
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
29
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
30
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
31
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
32
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
33
|
+
Requires-Python: >=3.9
|
|
34
|
+
Requires-Dist: django>=4.0
|
|
35
|
+
Provides-Extra: dev
|
|
36
|
+
Requires-Dist: django-debug-toolbar; extra == 'dev'
|
|
37
|
+
Requires-Dist: django-extensions; extra == 'dev'
|
|
38
|
+
Requires-Dist: ipython; extra == 'dev'
|
|
39
|
+
Requires-Dist: werkzeug; extra == 'dev'
|
|
40
|
+
Description-Content-Type: text/markdown
|
|
41
|
+
|
|
42
|
+
# django-admin-contexts
|
|
43
|
+
|
|
44
|
+
 [](https://pypi.python.org/pypi/django-admin-contexts)  [](https://codecov.io/gh/matagus/django-admin-contexts) [](https://opensource.org/licenses/BSD-3-Clause)
|
|
45
|
+
|
|
46
|
+
Display only a set of apps and models in the Django Admin homepage, based on the chosen context. This is useful when
|
|
47
|
+
you have a lot of apps and models and you want to focus on a specific set of them.
|
|
48
|
+
|
|
49
|
+

|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
Installation
|
|
53
|
+
============
|
|
54
|
+
|
|
55
|
+
Via `pip` command:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install django-admin-contexts
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
...or you can clone the repo and install it using `pip` too:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
git clone git://github.com/matagus/django-admin-contexts.git
|
|
65
|
+
cd django-admin-contexts
|
|
66
|
+
pip install -e .
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
then add `django_admin_contexts` to your `settings.py` **before** `django.contrib.admin`:
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
INSTALLED_APPS = (
|
|
73
|
+
# ...
|
|
74
|
+
"django_admin_contexts",
|
|
75
|
+
# ...
|
|
76
|
+
"django.contrib.admin",
|
|
77
|
+
# ...
|
|
78
|
+
)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
then run the migrations:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
python manage.py migrate
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Usage
|
|
88
|
+
=====
|
|
89
|
+
|
|
90
|
+
Browse to the Django Admin and create some contexts in the "Django Admin Contexts" section, associating them with one
|
|
91
|
+
or more models.
|
|
92
|
+
|
|
93
|
+
Then, you can see the contexts in the Django Admin homepage.
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
Contributing
|
|
97
|
+
============
|
|
98
|
+
|
|
99
|
+
Contributions are welcome! ❤️
|
|
100
|
+
|
|
101
|
+
Please read [Contributing.md](CONTRIBUTING.md) for detailed instructions on how to help.
|
|
102
|
+
|
|
103
|
+
Running Tests
|
|
104
|
+
-------------
|
|
105
|
+
|
|
106
|
+
`hatch run test:test` will run the tests in every Python + Django versions combination.
|
|
107
|
+
|
|
108
|
+
`hatch run test.py3.12-5.0:test will run them for python 3.12 and Django 5.0. Please see possible combinations using
|
|
109
|
+
`hatch env show` ("test" matrix).
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
License
|
|
113
|
+
=======
|
|
114
|
+
|
|
115
|
+
`django-admin-contexts` is released under an BSD License - see the `LICENSE` file for more information.
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
Acknowledgements
|
|
119
|
+
================
|
|
120
|
+
|
|
121
|
+
Develop & built using [](https://github.com/pypa/hatch) [](https://github.com/astral-sh/ruff) [](https://github.com/psf/black)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# django-admin-contexts
|
|
2
|
+
|
|
3
|
+
 [](https://pypi.python.org/pypi/django-admin-contexts)  [](https://codecov.io/gh/matagus/django-admin-contexts) [](https://opensource.org/licenses/BSD-3-Clause)
|
|
4
|
+
|
|
5
|
+
Display only a set of apps and models in the Django Admin homepage, based on the chosen context. This is useful when
|
|
6
|
+
you have a lot of apps and models and you want to focus on a specific set of them.
|
|
7
|
+
|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
Installation
|
|
12
|
+
============
|
|
13
|
+
|
|
14
|
+
Via `pip` command:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install django-admin-contexts
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
...or you can clone the repo and install it using `pip` too:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
git clone git://github.com/matagus/django-admin-contexts.git
|
|
24
|
+
cd django-admin-contexts
|
|
25
|
+
pip install -e .
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
then add `django_admin_contexts` to your `settings.py` **before** `django.contrib.admin`:
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
INSTALLED_APPS = (
|
|
32
|
+
# ...
|
|
33
|
+
"django_admin_contexts",
|
|
34
|
+
# ...
|
|
35
|
+
"django.contrib.admin",
|
|
36
|
+
# ...
|
|
37
|
+
)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
then run the migrations:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
python manage.py migrate
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Usage
|
|
47
|
+
=====
|
|
48
|
+
|
|
49
|
+
Browse to the Django Admin and create some contexts in the "Django Admin Contexts" section, associating them with one
|
|
50
|
+
or more models.
|
|
51
|
+
|
|
52
|
+
Then, you can see the contexts in the Django Admin homepage.
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
Contributing
|
|
56
|
+
============
|
|
57
|
+
|
|
58
|
+
Contributions are welcome! ❤️
|
|
59
|
+
|
|
60
|
+
Please read [Contributing.md](CONTRIBUTING.md) for detailed instructions on how to help.
|
|
61
|
+
|
|
62
|
+
Running Tests
|
|
63
|
+
-------------
|
|
64
|
+
|
|
65
|
+
`hatch run test:test` will run the tests in every Python + Django versions combination.
|
|
66
|
+
|
|
67
|
+
`hatch run test.py3.12-5.0:test will run them for python 3.12 and Django 5.0. Please see possible combinations using
|
|
68
|
+
`hatch env show` ("test" matrix).
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
License
|
|
72
|
+
=======
|
|
73
|
+
|
|
74
|
+
`django-admin-contexts` is released under an BSD License - see the `LICENSE` file for more information.
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
Acknowledgements
|
|
78
|
+
================
|
|
79
|
+
|
|
80
|
+
Develop & built using [](https://github.com/pypa/hatch) [](https://github.com/astral-sh/ruff) [](https://github.com/psf/black)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
version = "0.2.0"
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from django.contrib import admin
|
|
2
|
+
from django.utils.translation import gettext_lazy as _
|
|
3
|
+
|
|
4
|
+
from django_admin_contexts.models import AdminContext
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@admin.register(AdminContext)
|
|
8
|
+
class AdminContextAdmin(admin.ModelAdmin):
|
|
9
|
+
list_display = ["name", "slug", "description", "created_at", "updated_at"]
|
|
10
|
+
prepopulated_fields = {"slug": ("name",)}
|
|
11
|
+
|
|
12
|
+
class Meta:
|
|
13
|
+
verbose_name = _("Admin Context")
|
|
14
|
+
verbose_name_plural = _("Admin Contexts")
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from django import forms
|
|
2
|
+
|
|
3
|
+
from django_admin_contexts.models import AdminContext
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class AdminContextForm(forms.Form):
|
|
7
|
+
context = forms.ModelChoiceField(
|
|
8
|
+
queryset=AdminContext.objects.all(),
|
|
9
|
+
required=False,
|
|
10
|
+
empty_label="Any",
|
|
11
|
+
widget=forms.Select(attrs={"onchange": "this.form.submit()"}),
|
|
12
|
+
)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Generated by Django 5.0.3 on 2024-03-30 08:31
|
|
2
|
+
|
|
3
|
+
from django.db import migrations, models
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Migration(migrations.Migration):
|
|
7
|
+
|
|
8
|
+
initial = True
|
|
9
|
+
|
|
10
|
+
dependencies = [
|
|
11
|
+
("contenttypes", "0002_remove_content_type_name"),
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
operations = [
|
|
15
|
+
migrations.CreateModel(
|
|
16
|
+
name="AdminContext",
|
|
17
|
+
fields=[
|
|
18
|
+
("slug", models.CharField(max_length=100, primary_key=True, serialize=False)),
|
|
19
|
+
("name", models.CharField(max_length=100)),
|
|
20
|
+
("description", models.TextField(blank=True, null=True)),
|
|
21
|
+
("created_at", models.DateTimeField(auto_now_add=True)),
|
|
22
|
+
("updated_at", models.DateTimeField(auto_now=True)),
|
|
23
|
+
("models", models.ManyToManyField(to="contenttypes.contenttype")),
|
|
24
|
+
],
|
|
25
|
+
options={
|
|
26
|
+
"indexes": [models.Index(fields=["name"], name="django_admi_name_ba627c_idx")],
|
|
27
|
+
},
|
|
28
|
+
),
|
|
29
|
+
]
|
|
File without changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from django.db import models
|
|
2
|
+
from django.contrib.contenttypes.models import ContentType
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class AdminContext(models.Model):
|
|
6
|
+
slug = models.CharField(max_length=100, primary_key=True)
|
|
7
|
+
name = models.CharField(max_length=100)
|
|
8
|
+
description = models.TextField(blank=True, null=True)
|
|
9
|
+
|
|
10
|
+
created_at = models.DateTimeField(auto_now_add=True)
|
|
11
|
+
updated_at = models.DateTimeField(auto_now=True)
|
|
12
|
+
|
|
13
|
+
models = models.ManyToManyField(ContentType)
|
|
14
|
+
|
|
15
|
+
class Meta:
|
|
16
|
+
indexes = [models.Index(fields=["name"])]
|
|
17
|
+
|
|
18
|
+
def __str__(self):
|
|
19
|
+
return self.name
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{% load i18n django_admin_contexts_tags %}
|
|
2
|
+
|
|
3
|
+
{% if app_list %}
|
|
4
|
+
{% get_contexts_form as contexts_form %}
|
|
5
|
+
{% if contexts_form %}
|
|
6
|
+
<form action="{% url 'admin:index' %}" method="get">
|
|
7
|
+
{{ contexts_form }}
|
|
8
|
+
</form>
|
|
9
|
+
{% endif %}
|
|
10
|
+
{% filter_by_context app_list as filtered_app_list %}
|
|
11
|
+
{% for app in filtered_app_list %}
|
|
12
|
+
<div class="app-{{ app.app_label }} module{% if app.app_url in request.path|urlencode %} current-app{% endif %}">
|
|
13
|
+
<table>
|
|
14
|
+
<caption>
|
|
15
|
+
<a href="{{ app.app_url }}" class="section" title="{% blocktranslate with name=app.name %}Models in the {{ name }} application{% endblocktranslate %}">{{ app.name }}</a>
|
|
16
|
+
</caption>
|
|
17
|
+
{% for model in app.models %}
|
|
18
|
+
{% with model_name=model.object_name|lower %}
|
|
19
|
+
<tr class="model-{{ model_name }}{% if model.admin_url in request.path|urlencode %} current-model{% endif %}">
|
|
20
|
+
<th scope="row" id="{{ app.app_label }}-{{ model_name }}">
|
|
21
|
+
{% if model.admin_url %}
|
|
22
|
+
<a href="{{ model.admin_url }}"{% if model.admin_url in request.path|urlencode %} aria-current="page"{% endif %}>{{ model.name }}</a>
|
|
23
|
+
{% else %}
|
|
24
|
+
{{ model.name }}
|
|
25
|
+
{% endif %}
|
|
26
|
+
</th>
|
|
27
|
+
|
|
28
|
+
{% if model.add_url %}
|
|
29
|
+
<td><a href="{{ model.add_url }}" class="addlink" aria-describedby="{{ app.app_label }}-{{ model_name }}">{% translate 'Add' %}</a></td>
|
|
30
|
+
{% else %}
|
|
31
|
+
<td></td>
|
|
32
|
+
{% endif %}
|
|
33
|
+
|
|
34
|
+
{% if model.admin_url and show_changelinks %}
|
|
35
|
+
{% if model.view_only %}
|
|
36
|
+
<td><a href="{{ model.admin_url }}" class="viewlink" aria-describedby="{{ app.app_label }}-{{ model_name }}">{% translate 'View' %}</a></td>
|
|
37
|
+
{% else %}
|
|
38
|
+
<td><a href="{{ model.admin_url }}" class="changelink" aria-describedby="{{ app.app_label }}-{{ model_name }}">{% translate 'Change' %}</a></td>
|
|
39
|
+
{% endif %}
|
|
40
|
+
{% elif show_changelinks %}
|
|
41
|
+
<td></td>
|
|
42
|
+
{% endif %}
|
|
43
|
+
</tr>
|
|
44
|
+
{% endwith %}
|
|
45
|
+
{% endfor %}
|
|
46
|
+
</table>
|
|
47
|
+
</div>
|
|
48
|
+
{% endfor %}
|
|
49
|
+
{% else %}
|
|
50
|
+
<p>{% translate 'You don’t have permission to view or edit anything.' %}</p>
|
|
51
|
+
{% endif %}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
from collections import defaultdict
|
|
2
|
+
|
|
3
|
+
from django import template
|
|
4
|
+
from django.urls import reverse
|
|
5
|
+
|
|
6
|
+
from django_admin_contexts.forms import AdminContextForm
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
register = template.Library()
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@register.simple_tag(takes_context=True)
|
|
13
|
+
def get_contexts_form(context):
|
|
14
|
+
request = context["request"]
|
|
15
|
+
|
|
16
|
+
# Only show the form on the admin index page
|
|
17
|
+
if request.path == reverse("admin:index"):
|
|
18
|
+
return AdminContextForm(request.GET)
|
|
19
|
+
|
|
20
|
+
return None
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@register.simple_tag(takes_context=True)
|
|
24
|
+
def filter_by_context(context, app_list):
|
|
25
|
+
context_app_dict = defaultdict(list)
|
|
26
|
+
request = context["request"]
|
|
27
|
+
form = AdminContextForm(request.GET)
|
|
28
|
+
if form.is_valid():
|
|
29
|
+
context = form.cleaned_data.get("context")
|
|
30
|
+
|
|
31
|
+
if context is None:
|
|
32
|
+
return app_list
|
|
33
|
+
|
|
34
|
+
for context_type in context.models.all():
|
|
35
|
+
context_app_dict[context_type.app_label].append(context_type.model)
|
|
36
|
+
|
|
37
|
+
filtered_app_list = []
|
|
38
|
+
|
|
39
|
+
for app in app_list:
|
|
40
|
+
if app["app_label"] in context_app_dict:
|
|
41
|
+
app_with_filterred_models = {
|
|
42
|
+
"app_label": app["app_label"],
|
|
43
|
+
"app_url": app["app_url"],
|
|
44
|
+
"name": app["name"],
|
|
45
|
+
"has_module_perms": app["has_module_perms"],
|
|
46
|
+
"models": [
|
|
47
|
+
model
|
|
48
|
+
for model in app["models"]
|
|
49
|
+
if model["object_name"].lower() in context_app_dict[app["app_label"]]
|
|
50
|
+
],
|
|
51
|
+
}
|
|
52
|
+
filtered_app_list.append(app_with_filterred_models)
|
|
53
|
+
|
|
54
|
+
return filtered_app_list
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "django-admin-contexts"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Contexts for Django Admin homepage"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "BSD-3-clause"
|
|
11
|
+
authors = [
|
|
12
|
+
{ name = "Matias Agustin Mendez", email = "matagus@gmail.com" },
|
|
13
|
+
]
|
|
14
|
+
keywords = []
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 5 - Production/Stable",
|
|
17
|
+
"Environment :: Console",
|
|
18
|
+
"Environment :: Web Environment",
|
|
19
|
+
"Framework :: Django",
|
|
20
|
+
"Framework :: Django :: 4.0",
|
|
21
|
+
"Framework :: Django :: 4.1",
|
|
22
|
+
"Framework :: Django :: 4.2",
|
|
23
|
+
"Framework :: Django :: 5.0",
|
|
24
|
+
"Intended Audience :: Developers",
|
|
25
|
+
"License :: OSI Approved :: BSD License",
|
|
26
|
+
"Natural Language :: English",
|
|
27
|
+
"Programming Language :: Python",
|
|
28
|
+
"Programming Language :: Python :: 3.9",
|
|
29
|
+
"Programming Language :: Python :: 3.10",
|
|
30
|
+
"Programming Language :: Python :: 3.11",
|
|
31
|
+
"Programming Language :: Python :: 3.12",
|
|
32
|
+
"Programming Language :: Python :: Implementation :: CPython",
|
|
33
|
+
"Programming Language :: Python :: Implementation :: PyPy",
|
|
34
|
+
"Topic :: Software Development :: Libraries",
|
|
35
|
+
]
|
|
36
|
+
requires-python = ">=3.9"
|
|
37
|
+
dependencies = [
|
|
38
|
+
"Django>=4.0",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
[project.optional-dependencies]
|
|
42
|
+
dev = [
|
|
43
|
+
"ipython",
|
|
44
|
+
"django-extensions",
|
|
45
|
+
"Werkzeug",
|
|
46
|
+
"django-debug-toolbar",
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
[project.urls]
|
|
50
|
+
Homepage = "https://github.com/matagus/django-admin-contexts"
|
|
51
|
+
Issues = "https://.github.com/matagus/django-admin-contexts/issues"
|
|
52
|
+
Repository = "https://github.com/matagus/django-admin-contexts"
|
|
53
|
+
Changelog = "https://githib.com/matagus/django-admin-contexts/releases"
|
|
54
|
+
Pypi = "https://pypi.org/project/django-admin-contexts"
|
|
55
|
+
|
|
56
|
+
[tool.hatch.version]
|
|
57
|
+
path = "django_admin_contexts/__about__.py"
|
|
58
|
+
|
|
59
|
+
[tool.hatch.build.targets.sdist]
|
|
60
|
+
include = [
|
|
61
|
+
"django_admin_contexts/",
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
[tool.hatch.build.targets.wheel]
|
|
65
|
+
include = [
|
|
66
|
+
"django_admin_contexts/",
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
[tool.hatch.envs.default]
|
|
70
|
+
features = ["dev"]
|
|
71
|
+
|
|
72
|
+
[tool.hatch.envs.project]
|
|
73
|
+
template = "default"
|
|
74
|
+
extra-dependencies = [
|
|
75
|
+
"django-taggit", "django-waffle", "django-guardian", "django-organizations", "django-helpdesk",
|
|
76
|
+
"django-user-accounts", "pinax", "django-payments", "easy-thumbnails", "django-activity-stream",
|
|
77
|
+
]
|
|
78
|
+
|
|
79
|
+
[tool.hatch.envs.project.scripts]
|
|
80
|
+
runserver = "python example_project/manage.py runserver_plus {args}"
|
|
81
|
+
shell = "python example_project/manage.py shell_plus {args}"
|
|
82
|
+
migrate = "python example_project/manage.py migrate {args}"
|
|
83
|
+
makemigrations = "python example_project/manage.py makemigrations {args}"
|
|
84
|
+
createsuperuser = "python example_project/manage.py createsuperuser {args}"
|
|
85
|
+
|
|
86
|
+
# Test environment
|
|
87
|
+
[[tool.hatch.envs.test.matrix]]
|
|
88
|
+
django = ["4.0"]
|
|
89
|
+
python = ["3.9", "3.10"]
|
|
90
|
+
|
|
91
|
+
[[tool.hatch.envs.test.matrix]]
|
|
92
|
+
django = ["4.1"]
|
|
93
|
+
python = ["3.9", "3.10", "3.11"]
|
|
94
|
+
|
|
95
|
+
[[tool.hatch.envs.test.matrix]]
|
|
96
|
+
django = ["4.2"]
|
|
97
|
+
python = ["3.9", "3.10", "3.11", "3.12"]
|
|
98
|
+
|
|
99
|
+
[[tool.hatch.envs.test.matrix]]
|
|
100
|
+
django = ["5.0"]
|
|
101
|
+
python = ["3.10", "3.11", "3.12"]
|
|
102
|
+
|
|
103
|
+
[tool.hatch.envs.test]
|
|
104
|
+
dependencies = ["coverage[toml]", "django~={matrix:django}.0"]
|
|
105
|
+
|
|
106
|
+
[tool.hatch.envs.test.scripts]
|
|
107
|
+
test = "python -m django test --settings tests.settings"
|
|
108
|
+
test-cov = "coverage run -m django test --settings tests.settings"
|
|
109
|
+
cov-report = ["coverage json", "coverage report"]
|
|
110
|
+
cov = ["test-cov", "cov-report"]
|
|
111
|
+
|
|
112
|
+
[tool.ruff]
|
|
113
|
+
line-length = 120
|
|
114
|
+
|
|
115
|
+
[tool.black]
|
|
116
|
+
line-length = 120
|