Skip to content

Commit

Permalink
Updates supported Python and Django versions
Browse files Browse the repository at this point in the history
Also replaces lint and format tool to Ruff and updates dependencies.

The new supported Django versions are the ones currently supported by
Django Project. The Python versions supported by each Django version
are also based on Django Project's release notes for each Django
version.
  • Loading branch information
cuducos committed Apr 11, 2024
1 parent 9b1bd95 commit ac7e57e
Show file tree
Hide file tree
Showing 16 changed files with 682 additions and 790 deletions.
24 changes: 19 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,27 @@ jobs:
strategy:
matrix:
python-version:
- 3.12
- 3.11
- 3.10
- 3.9
- 3.8
- 3.7
- 3.6
django-version:
- 3
- 2
- 5.0
- 4.2
- 3.2
exclude:
- django-version: 3.2
python-version: 3.10
- django-version: 3.2
python-version: 3.11
- django-version: 3.2
python-version: 3.12
- django-version: 4.2
python-version: 3.11
- django-version: 4.2
python-version: 3.12
- django-version: 5.0
python-version: 3.9
name: Python ${{ matrix.python-version }} & Django ${{ matrix.django-version }}
steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os
import sys
from pathlib import Path
from pkg_resources import get_distribution
from typing import List

import django
from django.conf import settings
from pkg_resources import get_distribution

# add path to sys.path (this might be different in your project)
sys.path.insert(0, os.path.abspath(".."))
Expand Down
4 changes: 3 additions & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ In your ``urls.py``, import the `public_admin` (or whatever you've named it earl
Templates
---------

*Django Public Admin* comes with a template that hides from the UI elements related to non-logged-in users (elements such as login and logout links, recent actions panel, etc.). These templates are designed in a way to preserve the behavior of a regular instance of Django's native admin for logged-in users. To use it, add ``"public_admin"`` to your ``INSTALLED_APPS`` **before** ``"django.contrib.admin"``:
*Django Public Admin* comes with a template that hides from the UI elements related to non-logged-in users (elements such as login and logout links, recent actions panel, etc.). These templates are designed in a way to preserve the behavior of a regular instance of Django's native admin for logged-in users.

To use it, add ``"public_admin"`` to your ``INSTALLED_APPS`` **before** ``"django.contrib.admin"``:

::

Expand Down
1 change: 1 addition & 0 deletions example/manage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""

import os
import sys

Expand Down
1 change: 0 additions & 1 deletion example/my_open_house/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = []
Expand Down
3 changes: 1 addition & 2 deletions example/my_open_house/public_admin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from example.my_open_house.models import Beverage, Snack
from public_admin.admin import PublicModelAdmin
from public_admin.sites import PublicAdminSite, PublicApp

from example.my_open_house.models import Beverage, Snack


class BeverageModelAdmin(PublicModelAdmin):
list_display = ("name", "amount", "alcoholic")
Expand Down
1 change: 0 additions & 1 deletion example/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from example.my_open_house.public_admin import public_admin


urlpatterns = [
path("admin/", admin.site.urls),
path("dashboard/", public_admin.urls),
Expand Down
1 change: 1 addition & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""

import os
import sys

Expand Down
1,313 changes: 596 additions & 717 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions public_admin/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib.admin import ModelAdmin

from public_admin.sites import PublicAdminSite


Expand Down
41 changes: 18 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,34 @@ classifiers = [
"Intended Audience :: Developers",
"Topic :: Software Development",
"Framework :: Django",
"Framework :: Django :: 2.0",
"Framework :: Django :: 2.1",
"Framework :: Django :: 2.2",
"Framework :: Django :: 3.0",
"Framework :: Django :: 3.1",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9"
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.2",
"Framework :: Django :: 5.0",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
packages = [
{include = "public_admin"}
]

[tool.poetry.dependencies]
python = "^3.6"
django = ">=2"
python = "^3.9"
django = ">=3.2"

[tool.poetry.dev-dependencies]
black = { version = "*", allow-prereleases = true }
flake8 = "^3.7.9"
pip = "^20.0.2"
pytest-black = "^0.3.8"
pytest-flake8 = "^1.0.4"
pytest-mock = "^2.0.0"
readthedocs-sphinx-ext = "^1.0.1"
sphinx = "^2.4.4"
sphinx_rtd_theme = "^0.4.3"
tox = "^3.14.6"
pytest-ruff = "^0.3.1"
readthedocs-sphinx-ext = "^2.2.5"
sphinx = "^7.2.6"
sphinx-rtd-theme = "^2.0.0"
tox = "^4.14.2"

[tool.pytest.ini_options]
flake8-max-line-length = 88
addopts = "--black --flake8"
addopts = "--ruff --ruff-format"

[tool.ruff.lint]
select = ["E", "F", "I"]

[build-system]
requires = ["poetry>=0.12"]
Expand Down
4 changes: 2 additions & 2 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import django
from django.conf import settings


settings.configure(
SECRET_KEY="secret",
INSTALLED_APPS=[
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.sites",
]
],
)


Expand Down
1 change: 0 additions & 1 deletion tests/test_dummy_user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from public_admin.sites import DummyUser, PublicApp


PUBLIC_APPS = (
PublicApp("my_open_house", ("beverage", "snack")),
PublicApp("library", ("book", "journal")),
Expand Down
34 changes: 17 additions & 17 deletions tests/test_public_admin_site.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from unittest.mock import Mock, patch

import pytest
from django.db import models

from public_admin.exceptions import UnauthorizedModelError
from public_admin.sites import PublicAdminSite
from public_admin.sites import PublicApp

from django.db import models
from public_admin.sites import PublicAdminSite, PublicApp


class Beverage(models.Model):
Expand All @@ -23,41 +23,41 @@ class Meta:
)


def test_init(mocker):
def test_init():
public_admin = PublicAdminSite("dashboard", PUBLIC_APPS)
assert not public_admin.actions
assert not public_admin._global_actions
assert public_admin.name == "dashboard"


def test_valid_url(mocker):
def test_valid_url():
public_admin = PublicAdminSite("dashboard", PUBLIC_APPS)
valid, invalid = mocker.MagicMock(), mocker.MagicMock()
valid, invalid = Mock(), Mock()
valid.pattern.regex.pattern = "/my_open_house/"
invalid.pattern.regex.pattern = "/my_open_house/add/"
assert public_admin.valid_url(valid)
assert not public_admin.valid_url(invalid)


def test_urls(mocker):
def test_urls():
public_admin = PublicAdminSite("dashboard", PUBLIC_APPS)
get_urls = mocker.patch.object(PublicAdminSite, "get_urls")
get_urls.return_value = range(3)
valid_url = mocker.patch.object(PublicAdminSite, "valid_url")
valid_url.side_effect = (True, False, True)
assert public_admin.urls == ([0, 2], "admin", "dashboard")
with patch.object(PublicAdminSite, "get_urls") as get_urls:
get_urls.return_value = range(3)
with patch.object(PublicAdminSite, "valid_url") as valid_url:
valid_url.side_effect = (True, False, True)
assert public_admin.urls == ([0, 2], "admin", "dashboard")


def test_has_permission_get(mocker):
def test_has_permission_get():
public_admin = PublicAdminSite("dashboard", PUBLIC_APPS)
request = mocker.MagicMock()
request = Mock()
request.method = "GET"
assert public_admin.has_permission(request)


def test_has_permission_post(mocker):
def test_has_permission_post():
public_admin = PublicAdminSite("dashboard", PUBLIC_APPS)
request = mocker.MagicMock()
request = Mock()
request.method = "POST"
assert not public_admin.has_permission(request)

Expand Down
20 changes: 11 additions & 9 deletions tests/test_public_model_admin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from unittest.mock import Mock

from public_admin.admin import PublicModelAdmin


def test_permissions_with_get(mocker):
request = mocker.MagicMock()
def test_permissions_with_get():
request = Mock()
request.method = "GET"
public_model_admin = PublicModelAdmin(mocker.Mock(), mocker.Mock())
public_model_admin = PublicModelAdmin(Mock(), Mock())
assert public_model_admin.has_view_permission(request)
assert not any(
(
Expand All @@ -15,10 +17,10 @@ def test_permissions_with_get(mocker):
)


def test_permissions_with_post(mocker):
request = mocker.MagicMock()
def test_permissions_with_post():
request = Mock()
request.method = "POST"
public_model_admin = PublicModelAdmin(mocker.Mock(), mocker.Mock())
public_model_admin = PublicModelAdmin(Mock(), Mock())
assert not any(
(
public_model_admin.has_view_permission(request),
Expand All @@ -29,6 +31,6 @@ def test_permissions_with_post(mocker):
)


def test_urls(mocker):
public_model_admin = PublicModelAdmin(mocker.Mock(), mocker.Mock())
assert len(public_model_admin.get_urls()) == 5
def test_urls():
public_model_admin = PublicModelAdmin(Mock(), Mock())
assert len(public_model_admin.get_urls()) == 4
21 changes: 11 additions & 10 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@
isolated_build = True

envlist =
py{3.6,3.7,3.8,3.9}-django{2,3}

py3.9-django3.2
py{3.9,3.10}-django4.2
py{3.10,3.11,3.12}-django5.0

[gh-actions]
python =
3.6: py3.6
3.7: py3.7
3.8: py3.8
3.9: py3.9
3.10: py3.10
3.11: py3.11
3.12: py3.12

[testenv]
setenv =
PYTHONPATH={toxinidir}
deps =
django2: Django>=2.0,<3.0
django3: Django>=3.0,<4.0
django3.2: Django>=3.2,<4.0
django4.2: Django>=4.2,<5.0
django5.0: Django>=5.0,<5.1
pytest
pytest-black
pytest-flake8
pytest-mock
pytest-ruff
commands =
pytest

0 comments on commit ac7e57e

Please sign in to comment.