Skip to content

Commit

Permalink
Bump Django to 4.2 and Wagtail to 5.0
Browse files Browse the repository at this point in the history
- Django supported versions are 4.1, 4.2
- Wagtail supported versions are 4.0, 5.0
- removed unnecesary usage of pragma no-cover
- dropped support for older Django and Wagtail
  • Loading branch information
dinoperovic committed May 5, 2023
1 parent b81462c commit 31c0219
Show file tree
Hide file tree
Showing 18 changed files with 81 additions and 76 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry~=1.1.0
pip install poetry~=1.4.0
poetry config virtualenvs.create false
poetry install --no-dev
- name: Build and publish
Expand Down
21 changes: 11 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ on:
push:
branches:
- master
- 'release/**'
- "release/**"
paths:
- '**.py'
- "**.py"
pull_request:
paths:
- '**.py'
- "**.py"

jobs:
lint:
Expand All @@ -19,7 +19,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.8'
python-version: "3.11"
- uses: pre-commit/action@v2.0.3
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -30,22 +30,23 @@ jobs:
needs: lint
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10']
django-version: ['3.1', '3.2', '4.0']
python-version: ["3.8", "3.9", "3.10", "3.11"]
django-version: ["4.1", "4.2"]
wagtail-version: ["4.0", "5.0"]
include:
- python-version: '3.10'
django-version: '4.0'
- python-version: "3.11"
django-version: "4.2"
codecov: true
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies with Django ${{ matrix.django-version }}
- name: Install dependencies Django-${{ matrix.django-version }} Wagtail-${{ matrix.wagtail-version }}
run: |
python -m pip install --upgrade pip
pip install poetry~=1.1.0 django~=${{ matrix.django-version }}.0
pip install poetry~=1.4.0 Django~=${{ matrix.django-version }}.0 Wagtail~=${{ matrix.wagtail-version }}
poetry config virtualenvs.create false
poetry install --no-dev -E tests
- name: Test with pytest
Expand Down
6 changes: 3 additions & 3 deletions docs/reference/admin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ Widgets
Wagtail
=======

Edit handlers
-------------
Panels
------

.. automodule:: salesman.admin.wagtail.edit_handlers
.. automodule:: salesman.admin.wagtail.panels
:members:

Forms
Expand Down
18 changes: 18 additions & 0 deletions docs/releases/1.2.0.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#####
1.2.0
#####

*TBA*

Added
-----

- Added support for Django `4.2`
- Added support for Wagtail `5.0`
- Added option to disable anonymous checkout using ``SALESMAN_ALLOW_ANONYMOUS_USER_CHECKOUT`` setting. (`@laricko <https://github.com/laricko>`_)

Removed
-------

- Removed support for Django `3.1`, `3.2` and `4.0`
- Removed support for Wagtail `2.0` and `3.0`
11 changes: 0 additions & 11 deletions docs/releases/dev.rst

This file was deleted.

8 changes: 7 additions & 1 deletion docs/releases/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ Release notes and upgrade information. This project adheres to
- ``Fixed`` for any bug fixes.
- ``Security`` in case of vulnerabilities.

.. toctree::
:caption: v1.2
:maxdepth: 1

1.2.0


.. toctree::
:caption: v1.1
:maxdepth: 1

dev
1.1.6
1.1.5
1.1.4
Expand Down
2 changes: 1 addition & 1 deletion example/project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"wagtail.images",
"wagtail.search",
"wagtail.admin",
"wagtail.core",
"wagtail",
"modelcluster",
"taggit",
# shop
Expand Down
2 changes: 1 addition & 1 deletion example/project/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import include, path, re_path
from wagtail import urls as wagtail_urls
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.core import urls as wagtail_urls
from wagtail.documents import urls as wagtaildocs_urls

urlpatterns = [
Expand Down
4 changes: 2 additions & 2 deletions example/tests/admin/test_admin_panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

from salesman.admin import utils
from salesman.admin.mixins import OrderAdminMixin
from salesman.admin.wagtail.edit_handlers import (
from salesman.admin.wagtail.forms import WagtailOrderModelForm
from salesman.admin.wagtail.panels import (
OrderAdminPanel,
OrderCheckboxPanel,
OrderDatePanel,
OrderItemsPanel,
ReadOnlyPanel,
)
from salesman.admin.wagtail.forms import WagtailOrderModelForm
from salesman.admin.wagtail_hooks import OrderAdmin
from salesman.core.utils import get_salesman_model
from shop.models import Product
Expand Down
18 changes: 9 additions & 9 deletions example/tests/admin/test_admin_wagtail_hooks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from django.contrib.admin.sites import AdminSite
from django.contrib.messages.storage.fallback import FallbackStorage
from wagtail.admin.edit_handlers import EditHandler, FieldPanel, ObjectList
from wagtail.admin.panels import FieldPanel, ObjectList, Panel

from salesman.admin import wagtail_hooks
from salesman.core.utils import get_salesman_model
Expand Down Expand Up @@ -78,20 +78,20 @@ def test_order_admin(rf, client, django_user_model):
assert view.get_meta_title() == "Confirm Order refund"

# test get_edit_handler
edit_handler = modeladmin.get_edit_handler(order, request)
edit_handler = modeladmin.get_edit_handler()
assert edit_handler == modeladmin.default_edit_handler
modeladmin.default_edit_handler = None
edit_handler = modeladmin.get_edit_handler(order, request)
edit_handler = modeladmin.get_edit_handler()
assert isinstance(edit_handler, ObjectList)
modeladmin.model.panels = [FieldPanel("model_panel")]
edit_handler = modeladmin.get_edit_handler(order, request)
edit_handler = modeladmin.get_edit_handler()
assert edit_handler.children == modeladmin.model.panels
modeladmin.model.edit_handler = EditHandler(heading="model_edit_handler")
edit_handler = modeladmin.get_edit_handler(order, request)
modeladmin.model.edit_handler = Panel(heading="model_edit_handler")
edit_handler = modeladmin.get_edit_handler()
assert edit_handler == modeladmin.model.edit_handler
modeladmin.panels = [FieldPanel("admin_panel")]
edit_handler = modeladmin.get_edit_handler(order, request)
edit_handler = modeladmin.get_edit_handler()
assert edit_handler.children == modeladmin.panels
modeladmin.edit_handler = EditHandler(heading="admin_edit_handler")
edit_handler = modeladmin.get_edit_handler(order, request)
modeladmin.edit_handler = Panel(heading="admin_edit_handler")
edit_handler = modeladmin.get_edit_handler()
assert edit_handler == modeladmin.edit_handler
13 changes: 5 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ keywords = ["e-commerce", "headless", "rest-api", "shop", "framework"]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Framework :: Django",
"Framework :: Django :: 3.1",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.0",
"Framework :: Django :: 4.1",
"Framework :: Django :: 4.2",
"Framework :: Wagtail",
"Framework :: Wagtail :: 2",
"Framework :: Wagtail :: 3",
"Framework :: Wagtail :: 4",
"Framework :: Wagtail :: 5",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Topic :: Internet",
Expand All @@ -31,12 +28,12 @@ include = ["LICENSE"]

[tool.poetry.dependencies]
python = ">=3.8.1,<4.0"
django = ">=3.1,<4.2"
djangorestframework = ">=3.11,<3.15"
django = ">=4.1.3,<4.3"
djangorestframework = ">=3.11.1,<4.0"

# Optional
Pygments = {version = "^2.6", optional = true}
wagtail = {version = ">=2.9,<4.3", optional = true}
wagtail = {version = ">=4.0,<6.0", optional = true}
pytest = {version = "~7.0.0", optional = true}
pytest-django = {version = "~4.5.0", optional = true}
pytest-cov = {version = "~3.0.0", optional = true}
Expand Down
1 change: 0 additions & 1 deletion salesman/admin/wagtail/edit_handlers.py

This file was deleted.

2 changes: 1 addition & 1 deletion salesman/admin/wagtail/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.utils.html import format_html
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from wagtail.admin.edit_handlers import (
from wagtail.admin.panels import (
FieldPanel,
InlinePanel,
MultiFieldPanel,
Expand Down
35 changes: 15 additions & 20 deletions salesman/admin/wagtail/panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@
from django.utils.html import format_html
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from wagtail.admin.edit_handlers import EditHandler as Panel
from wagtail.utils.version import get_main_version as get_wagtail_version
from wagtail.admin.panels import Panel

from salesman.conf import app_settings

from ..utils import format_price

if get_wagtail_version() < "3.0.0": # pragma: no cover
# Attach dummy BoundPanel class for older Wagtail versions
Panel.BoundPanel = object


class ReadOnlyPanel(Panel):
"""
Expand Down Expand Up @@ -59,22 +54,22 @@ def on_model_bound(self) -> None:
if field and not self.help_text:
self.help_text: str = getattr(field, "help_text", "")

def get_value(self) -> Any: # pragma: no cover
def get_value(self) -> Any:
value = getattr(self.instance, self.attr)
if callable(value):
value = value(self.instance)
return value

def format_value(self, value: Any) -> Any: # pragma: no cover
def format_value(self, value: Any) -> Any:
if self.formatter and value is not None:
value = self.formatter(value, self.instance, self.request)
return value

def render(self) -> Any: # pragma: no cover
def render(self) -> Any:
value = self.get_value()
return self.format_value(value)

def render_as_object(self) -> Any: # pragma: no cover
def render_as_object(self) -> Any:
if self.renderer:
return self.renderer(self.get_value(), self.instance, self.request)
return format_html(
Expand All @@ -87,7 +82,7 @@ def render_as_object(self) -> Any: # pragma: no cover
self.render(),
)

def render_as_field(self) -> Any: # pragma: no cover
def render_as_field(self) -> Any:
if self.renderer:
return self.renderer(self.get_value(), self.instance, self.request)
help_html = (
Expand Down Expand Up @@ -184,7 +179,7 @@ def render_as_field(self) -> Any:


class OrderDatePanel(ReadOnlyPanel):
def format_value(self, value: Any) -> Any: # pragma: no cover
def format_value(self, value: Any) -> Any:
if value:
value = date_format(value, format="DATETIME_FORMAT")
return value
Expand All @@ -197,7 +192,7 @@ def format_value(self, value: Any) -> Any:


class OrderCheckboxPanel(ReadOnlyPanel):
def format_value(self, value: Any) -> str: # pragma: no cover
def format_value(self, value: Any) -> str:
icon, color = ("tick", "#157b57") if value else ("cross", "#cd3238")
template = '<span class="icon icon-{}" style="color: {};"></span>'
return format_html(template, icon, color)
Expand All @@ -210,26 +205,26 @@ def format_value(self, value: Any) -> str:


class OrderItemsPanel(ReadOnlyPanel):
def classes(self) -> list[str]: # pragma: no cover
def classes(self) -> list[str]:
return ["salesman-order-items"]

def render_as_field(self) -> str: # pragma: no cover
def render_as_field(self) -> str:
return self.render()

def render_as_object(self) -> str: # pragma: no cover
def render_as_object(self) -> str:
return self.render()

def format_json(
self,
value: dict[str, Any],
obj: Any,
request: HttpRequest,
) -> str: # pragma: no cover
) -> str:
return app_settings.SALESMAN_ADMIN_JSON_FORMATTER(
value, context={"order_item": True}
)

def render(self) -> str: # pragma: no cover
def render(self) -> str:
head = f"""<tr>
<td>{_('Name')}</td>
<td>{_('Code')}</td>
Expand Down Expand Up @@ -323,7 +318,7 @@ class OrderAdminPanel(ReadOnlyPanel):
def on_model_bound(self) -> None:
pass

def on_form_bound(self) -> None: # pragma: no cover
def on_form_bound(self) -> None:
if not hasattr(self.form, "model_admin"):
raise AssertionError("OrderAdminPanel can only be used in OrderModelAdmin.")

Expand All @@ -332,7 +327,7 @@ def on_form_bound(self) -> None: # pragma: no cover
if heading and not self.heading:
self.heading = heading

def get_value(self) -> Any: # pragma: no cover
def get_value(self) -> Any:
return getattr(self.form.model_admin, self.attr)(self.instance)

class BoundPanel(ReadOnlyPanel.BoundPanel):
Expand Down
2 changes: 1 addition & 1 deletion salesman/admin/wagtail/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def get_meta_title(self) -> str:
def refund_url(self) -> str | None:
try:
return str(self.url_helper.get_action_url("refund", self.pk_quoted))
except NoReverseMatch: # pragma: no cover
except NoReverseMatch:
return None


Expand Down

0 comments on commit 31c0219

Please sign in to comment.