Script 'mail_helper' called by obssrc
Hello community,
here is the log from the commit of package python-django-js-asset for
openSUSE:Factory checked in at 2026-04-04 19:06:56
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-django-js-asset (Old)
and /work/SRC/openSUSE:Factory/.python-django-js-asset.new.21863 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-django-js-asset"
Sat Apr 4 19:06:56 2026 rev:8 rq:1344473 version:3.1.2
Changes:
--------
---
/work/SRC/openSUSE:Factory/python-django-js-asset/python-django-js-asset.changes
2024-03-28 14:30:38.913455500 +0100
+++
/work/SRC/openSUSE:Factory/.python-django-js-asset.new.21863/python-django-js-asset.changes
2026-04-04 19:08:56.208862795 +0200
@@ -1,0 +2,16 @@
+Fri Apr 3 13:05:49 UTC 2026 - Dirk Müller <[email protected]>
+
+- update to 3.1.2:
+ * Made the ``id`` argument to ``JSON`` keyword-only. Also made
+ the ``inline`` argument to ``CSS`` keyword-only.
+ * Added the ``media`` attribute to ``CSS`` classes.
+ * Added experimental support for shipping importmaps.
+ * Rewrite the internals using dataclasses, drop compatibility
+ with Django < 4.2 and Python < 3.10.
+ * Added a ``CSS`` and ``JSON`` class which can also be used with
+ ``forms.Media``. It's recommended to pass them as JavaScript entries to
+ ``forms.Media(js=[])`` because the ``js`` list doesn't use a media
+ dictionary.
+ * Added Django 5.1, Python 3.1
+
+-------------------------------------------------------------------
Old:
----
2.2.tar.gz
New:
----
3.1.2.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ python-django-js-asset.spec ++++++
--- /var/tmp/diff_new_pack.UuHQiO/_old 2026-04-04 19:08:56.772885919 +0200
+++ /var/tmp/diff_new_pack.UuHQiO/_new 2026-04-04 19:08:56.772885919 +0200
@@ -1,7 +1,7 @@
#
# spec file for package python-django-js-asset
#
-# Copyright (c) 2023 SUSE LLC
+# Copyright (c) 2026 SUSE LLC and contributors
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@@ -15,10 +15,10 @@
# Please submit bugfixes or comments via https://bugs.opensuse.org/
#
+
%{?sle15_python_module_pythons}
Name: python-django-js-asset
-Version: 2.2
-%define intversion %{version}.0
+Version: 3.1.2
Release: 0
Summary: Script tag with additional attributes for django.formsMedia
License: BSD-3-Clause
@@ -57,5 +57,5 @@
%doc README.rst
%license LICENSE
%{python_sitelib}/js_asset/
-%{python_sitelib}/django_js_asset-%{intversion}.dist-info
+%{python_sitelib}/django_js_asset-%{version}.dist-info
++++++ 2.2.tar.gz -> 3.1.2.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/django-js-asset-2.2/.github/workflows/tests.yml
new/django-js-asset-3.1.2/.github/workflows/tests.yml
--- old/django-js-asset-2.2/.github/workflows/tests.yml 2023-12-12
19:03:33.000000000 +0100
+++ new/django-js-asset-3.1.2/.github/workflows/tests.yml 2025-03-04
16:22:35.000000000 +0100
@@ -6,7 +6,7 @@
pull_request:
branches: [main]
schedule:
- - cron: "37 1 1 * *"
+ - cron: 37 1 1 * *
jobs:
tests:
@@ -16,22 +16,21 @@
fail-fast: false
matrix:
python-version:
- - "3.8"
- - "3.9"
- - "3.10"
- - "3.11"
- - "3.12"
+ - '3.10'
+ - '3.11'
+ - '3.12'
+ - '3.13'
steps:
- - uses: actions/checkout@v3
- - name: Set up Python ${{ matrix.python-version }}
- uses: actions/setup-python@v4
- with:
- python-version: ${{ matrix.python-version }}
- - name: Install dependencies
- run: |
- python -m pip install --upgrade pip wheel setuptools tox
- - name: Run tox targets for ${{ matrix.python-version }}
- run: |
- ENV_PREFIX=$(tr -C -d "0-9" <<< "${{ matrix.python-version }}")
- TOXENV=$(tox --listenvs | grep "^py$ENV_PREFIX" | tr '\n' ',')
python -m tox
+ - uses: actions/checkout@v4
+ - name: Set up Python ${{ matrix.python-version }}
+ uses: actions/setup-python@v5
+ with:
+ python-version: ${{ matrix.python-version }}
+ - name: Install dependencies
+ run: |
+ python -m pip install --upgrade pip wheel setuptools tox
+ - name: Run tox targets for ${{ matrix.python-version }}
+ run: |
+ ENV_PREFIX=$(tr -C -d "0-9" <<< "${{ matrix.python-version }}")
+ TOXENV=$(tox --listenvs | grep "^py$ENV_PREFIX" | tr '\n' ',') python
-m tox
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/django-js-asset-2.2/.pre-commit-config.yaml
new/django-js-asset-3.1.2/.pre-commit-config.yaml
--- old/django-js-asset-2.2/.pre-commit-config.yaml 2023-12-12
19:03:33.000000000 +0100
+++ new/django-js-asset-3.1.2/.pre-commit-config.yaml 2025-03-04
16:22:35.000000000 +0100
@@ -1,7 +1,7 @@
exclude: ".yarn/|yarn.lock|\\.min\\.(css|js)$"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
- rev: v4.5.0
+ rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-builtin-literals
@@ -14,30 +14,20 @@
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/adamchainz/django-upgrade
- rev: 1.15.0
+ rev: 1.22.2
hooks:
- id: django-upgrade
args: [--target-version, "3.2"]
- repo: https://github.com/astral-sh/ruff-pre-commit
- rev: "v0.1.7"
+ rev: "v0.8.3"
hooks:
- id: ruff
- - repo: https://github.com/psf/black
- rev: 23.12.0
- hooks:
- - id: black
- - repo: https://github.com/pre-commit/mirrors-prettier
- rev: v4.0.0-alpha.4
- hooks:
- - id: prettier
- entry: env PRETTIER_LEGACY_CLI=1 prettier
- args: [--list-different, --no-semi]
- exclude: "^conf/|.*\\.html$"
+ - id: ruff-format
- repo: https://github.com/tox-dev/pyproject-fmt
- rev: 1.5.3
+ rev: v2.5.0
hooks:
- id: pyproject-fmt
- repo: https://github.com/abravalheri/validate-pyproject
- rev: v0.15
+ rev: v0.23
hooks:
- id: validate-pyproject
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/django-js-asset-2.2/CHANGELOG.rst
new/django-js-asset-3.1.2/CHANGELOG.rst
--- old/django-js-asset-2.2/CHANGELOG.rst 2023-12-12 19:03:33.000000000
+0100
+++ new/django-js-asset-3.1.2/CHANGELOG.rst 2025-03-04 16:22:35.000000000
+0100
@@ -7,6 +7,29 @@
Next version
~~~~~~~~~~~~
+- Added a ``static_lazy`` helper.
+
+
+3.1 (2025-02-28)
+~~~~~~~~~~~~~~~~
+
+- Made the ``id`` argument to ``JSON`` keyword-only. Also made the ``inline``
+ argument to ``CSS`` keyword-only.
+- Added the ``media`` attribute to ``CSS`` classes.
+- Added experimental support for shipping importmaps.
+
+
+3.0 (2024-12-17)
+~~~~~~~~~~~~~~~~
+
+- Rewrite the internals using dataclasses, drop compatibility with Django < 4.2
+ and Python < 3.10.
+- Added a ``CSS`` and ``JSON`` class which can also be used with
+ ``forms.Media``. It's recommended to pass them as JavaScript entries to
+ ``forms.Media(js=[])`` because the ``js`` list doesn't use a media
+ dictionary.
+- Added Django 5.1, Python 3.13.
+
2.2 (2023-12-12)
~~~~~~~~~~~~~~~~
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/django-js-asset-2.2/README.rst
new/django-js-asset-3.1.2/README.rst
--- old/django-js-asset-2.2/README.rst 2023-12-12 19:03:33.000000000 +0100
+++ new/django-js-asset-3.1.2/README.rst 2025-03-04 16:22:35.000000000
+0100
@@ -1,10 +1,15 @@
-===============================================================================
-django-js-asset -- script tag with additional attributes for django.forms.Media
-===============================================================================
+==================================================================
+django-js-asset -- JS, CSS and JSON support for django.forms.Media
+==================================================================
.. image::
https://github.com/matthiask/django-js-asset/workflows/Tests/badge.svg
:target: https://github.com/matthiask/django-js-asset
+**Note!** `Django 5.2 adds its own support for JavaScript objects
+<https://docs.djangoproject.com/en/dev/topics/forms/media/#script-objects>`__.
+This library has a slightly different API and also supports much older versions
+of Django, *and* it also supports CSS and JSON tags.
+
Usage
=====
@@ -44,27 +49,104 @@
``js_asset.static`` function is provided which does the right thing
automatically.
-When adding external script assets, you should pass ``static=False`` to the
-``JS`` object to avoid passing the script URL through ``static()``. In this
-case, you probably want to add ``defer`` or ``async``, and maybe also
-``integrity`` and ``crossorigin`` attributes. Please note that boolean
-attributes are not properly supported when using Django before 4.1 so specify
-them as follows:
+
+CSS and JSON support
+====================
+
+Since 3.0 django-js-asset also ships a ``CSS`` and ``JSON`` media object which
+can be used to ship stylesheets, inline styles and JSON blobs to the frontend.
+It's recommended to pass those through ``forms.Media(js=[])`` as well since
+``js`` is a simple list while ``css`` uses a dictionary keyed with the media to
+use for the stylesheet.
+
+So, you can add everything at once:
.. code-block:: python
- JS(
- "https://cdn.example.com/script.js",
- {"defer": "defer"},
- static=False,
- )
+ from js_asset import CSS, JS, JSON
+
+ forms.Media(js=[
+ JSON({"configuration": 42}, id="widget-configuration"),
+ CSS("widget/style.css"),
+ CSS("p{color:red;}", inline=True),
+ JS("widget/script.js", {"type": "module"}),
+ ])
+
+This produces:
+
+.. code-block:: html
+
+ <script id="widget-configuration"
type="application/json">{"configuration": 42}</script>
+ <link href="/static/widget/style.css" media="all" rel="stylesheet">
+ <style media="all">p{color:red;}</style>
+ <script src="/static/widget/script.js" type="module"></script>
+
Compatibility
=============
-At the time of writing this app is compatible with Django 1.8 and better
-(up to and including the Django master branch), but have a look at the
+At the time of writing this app is compatible with Django 4.2 and better
+(up to and including the Django main branch), but have a look at the
`tox configuration
<https://github.com/matthiask/django-js-asset/blob/main/tox.ini>`_ for
definitive answers.
+
+
+Extremely experimental importmap support
+========================================
+
+django-js-asset ships an extremely experimental implementation adding support
+for using `importmaps
+<https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap>`_.
+
+One of the reasons why importmaps are useful when used with Django is that this
+easily allows us to use the file name mangling offered for example by Django
+``ManifestStaticFilesStorage`` without having to rewrite import statements in
+scripts themselves.
+
+Browser support for multiple importmaps is not generally available; at the time
+of writing (February 2025) it's not even clear if Mozilla wants to support them
+ever, so merging importmaps is -- for now -- the only viable way to use them in
+production. Because of this the implementation uses a global importmap variable
+where new entries can be added to and a context processor to make the importmap
+available to templates.
+
+The ``importmap`` object can be imported from ``js_asset``. Usage is as
follows:
+
+.. code-block:: python
+
+ # static is an alias for Django's static() function used in the
+ # {% static %} template tag.
+ from js_asset import JS, static, importmap
+
+ # Run this during project initialization, e.g. in App.ready or whereever.
+ importmap.update({
+ "imports": {
+ "my-library": static("my-library.js"),
+ },
+ })
+
+You have to add ``js_asset.context_processors.importmap`` to the list of
+context processors in your settings (or choose some other way of making the
+``importmap`` object available in templates) and add ``{{ importmap }}``
+somewhere in your base template, preferrably at the top before including any
+scripts.
+
+When you've done that you can start profiting from the importmap by adding
+JavaScript modules:
+
+.. code-block:: python
+
+ # Example for adding a code.js JavaScript *module*
+ forms.Media(js=[
+ JS("code.js", {"type": "module"}),
+ ])
+
+The code in ``code.js`` can now use a JavaScript import to import assets from
+the library, even though the library's filename may contain hashes not known at
+programming time:
+
+.. code-block:: javascript
+
+ import { Stuff } from "my-library"
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/django-js-asset-2.2/js_asset/__init__.py
new/django-js-asset-3.1.2/js_asset/__init__.py
--- old/django-js-asset-2.2/js_asset/__init__.py 2023-12-12
19:03:33.000000000 +0100
+++ new/django-js-asset-3.1.2/js_asset/__init__.py 2025-03-04
16:22:35.000000000 +0100
@@ -1,4 +1,4 @@
-__version__ = "2.2.0"
+__version__ = "3.1.2"
import contextlib
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/django-js-asset-2.2/js_asset/context_processors.py
new/django-js-asset-3.1.2/js_asset/context_processors.py
--- old/django-js-asset-2.2/js_asset/context_processors.py 1970-01-01
01:00:00.000000000 +0100
+++ new/django-js-asset-3.1.2/js_asset/context_processors.py 2025-03-04
16:22:35.000000000 +0100
@@ -0,0 +1,5 @@
+from js_asset.js import importmap as _importmap
+
+
+def importmap(request):
+ return {"importmap": _importmap}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/django-js-asset-2.2/js_asset/js.py
new/django-js-asset-3.1.2/js_asset/js.py
--- old/django-js-asset-2.2/js_asset/js.py 2023-12-12 19:03:33.000000000
+0100
+++ new/django-js-asset-3.1.2/js_asset/js.py 2025-03-04 16:22:35.000000000
+0100
@@ -1,94 +1,106 @@
-import json
-import warnings
+from dataclasses import dataclass, field
+from typing import Any
-from django import VERSION
from django.forms.utils import flatatt
from django.templatetags.static import static
-from django.utils.html import format_html, html_safe, mark_safe
+from django.utils.functional import lazy
+from django.utils.html import format_html, html_safe, json_script, mark_safe
-__all__ = ("JS", "static")
+__all__ = ["CSS", "ImportMap", "JS", "JSON", "importmap", "static",
"static_lazy"]
-_sentinel = object()
+def static_if_relative(path):
+ return path if path.startswith(("http://", "https://", "/")) else
static(path)
+static_lazy = lazy(static, str)
+
+
+@html_safe
+@dataclass(eq=True)
+class CSS:
+ src: str
+ inline: bool = field(default=False, kw_only=True)
+ media: str = "all"
+
+ def __hash__(self):
+ return hash(self.__str__())
+
+ def __str__(self):
+ if self.inline:
+ return format_html('<style media="{}">{}</style>', self.media,
self.src)
+ return format_html(
+ '<link href="{}" media="{}" rel="stylesheet">',
+ static_if_relative(self.src),
+ self.media,
+ )
+
+
+@html_safe
+@dataclass(eq=True)
class JS:
- """
- Use this to insert a script tag via ``forms.Media`` containing additional
- attributes (such as ``id`` and ``data-*`` for CSP-compatible data
- injection.)::
-
- forms.Media(js=[
- JS('asset.js', {
- 'id': 'asset-script',
- 'data-answer': '"42"',
- }),
- ])
-
- The rendered media tag (via ``{{ media.js }}`` or ``{{ media }}`` will
- now contain a script tag as follows, without line breaks::
-
- <script type="text/javascript" src="/static/asset.js"
- data-answer=""42"" id="asset-script"></script>
-
- The attributes are automatically escaped. The data attributes may now be
- accessed inside ``asset.js``::
-
- var answer = document.querySelector('#asset-script').dataset.answer;
- """
-
- def __init__(self, js, attrs=None, static=_sentinel):
- self.js = js
- self.attrs = attrs or {}
- if static is not _sentinel:
- warnings.warn(
- "JS automatically determines whether it received an absolute"
- " path or not. Stop passing the 'static' argument please.",
- DeprecationWarning,
- stacklevel=2,
- )
+ src: str
+ attrs: dict[str, Any] = field(default_factory=dict)
- def startswith(self, _):
- # Masquerade as absolute path so that we are returned as-is.
- return True
-
- def __repr__(self):
- return f"JS({self.js}, {json.dumps(self.attrs, sort_keys=True)})"
-
- if VERSION >= (4, 1):
-
- def __str__(self):
- return format_html(
- '<script src="{}"{}></script>',
- self.js
- if self.js.startswith(("http://", "https://", "/"))
- else static(self.js),
- mark_safe(flatatt(self.attrs)),
- )
+ def __hash__(self):
+ return hash(self.__str__())
- else:
+ def __str__(self):
+ return format_html(
+ '<script src="{}"{}></script>',
+ static_if_relative(self.src),
+ mark_safe(flatatt(self.attrs)),
+ )
- def __html__(self):
- js = (
- self.js
- if self.js.startswith(("http://", "https://", "/"))
- else static(self.js)
- )
- return (
- format_html('{}"{}', js, mark_safe(flatatt(self.attrs)))[:-1]
- if self.attrs
- else js
- )
- def __eq__(self, other):
- if isinstance(other, JS):
- return self.js == other.js and self.attrs == other.attrs
- return self.js == other and not self.attrs
+@html_safe
+@dataclass(eq=True)
+class JSON:
+ data: dict[str, Any]
+ id: str | None = field(default="", kw_only=True)
def __hash__(self):
- return hash((self.js, json.dumps(self.attrs, sort_keys=True)))
+ return hash(self.__str__())
+
+ def __str__(self):
+ return json_script(self.data, self.id)
+
+
+@html_safe
+class ImportMap:
+ def __init__(self, importmap):
+ self._importmap = importmap
+
+ def __str__(self):
+ if self._importmap:
+ html = json_script(self._importmap).removeprefix(
+ '<script type="application/json">'
+ )
+ return mark_safe(f'<script type="importmap">{html}')
+ return ""
+
+ def update(self, other):
+ if isinstance(other, ImportMap):
+ other = other._importmap
+
+ if imports := other.get("imports"):
+ self._importmap.setdefault("imports", {}).update(imports)
+ if integrity := other.get("integrity"):
+ self._importmap.setdefault("integrity", {}).update(integrity)
+ if scopes := other.get("scopes"):
+ for scope, imports in scopes.items():
+ self._importmap.setdefault("scopes", {}).setdefault(scope,
{}).update(
+ imports
+ )
+
+ def __or__(self, other):
+ if isinstance(other, ImportMap):
+ combined = self.__class__({})
+ combined.update(self)
+ combined.update(other)
+ return combined
+ return NotImplemented
-if VERSION >= (4, 1):
- JS = html_safe(JS)
+importmap = ImportMap({})
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/django-js-asset-2.2/pyproject.toml
new/django-js-asset-3.1.2/pyproject.toml
--- old/django-js-asset-2.2/pyproject.toml 2023-12-12 19:03:33.000000000
+0100
+++ new/django-js-asset-3.1.2/pyproject.toml 2025-03-04 16:22:35.000000000
+0100
@@ -8,11 +8,11 @@
name = "django-js-asset"
description = "script tag with additional attributes for django.forms.Media"
readme = "README.rst"
-license = {text = "BSD-3-Clause"}
+license = { text = "BSD-3-Clause" }
authors = [
- { name = "Matthias Kestenholz", email = "[email protected]" },
+ { name = "Matthias Kestenholz", email = "[email protected]" },
]
-requires-python = ">=3.8"
+requires-python = ">=3.10"
classifiers = [
"Environment :: Web Environment",
"Framework :: Django",
@@ -21,11 +21,10 @@
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
- "Programming Language :: Python :: 3.8",
- "Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
+ "Programming Language :: Python :: 3.13",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
"Topic :: Software Development",
"Topic :: Software Development :: Libraries :: Application Frameworks",
@@ -34,81 +33,78 @@
"version",
]
dependencies = [
- "Django>=3.2",
+ "django>=4.2",
]
-[project.optional-dependencies]
-tests = [
+optional-dependencies.tests = [
"coverage",
]
-[project.urls]
-Homepage = "https://github.com/matthiask/django-js-asset/"
+urls.Homepage = "https://github.com/matthiask/django-js-asset/"
[tool.hatch.build.targets.wheel]
-packages = ["js_asset"]
+packages = [
+ "js_asset",
+]
[tool.hatch.version]
path = "js_asset/__init__.py"
[tool.ruff]
-extend-select = [
- # pyflakes, pycodestyle
- "F", "E", "W",
- # mmcabe
- "C90",
- # isort
- "I",
- # pep8-naming
- "N",
- # pyupgrade
- "UP",
- # flake8-2020
- "YTT",
- # flake8-boolean-trap
- "FBT",
+target-version = "py38"
+
+fix = true
+show-fixes = true
+lint.extend-select = [
# flake8-bugbear
"B",
# flake8-comprehensions
"C4",
+ # mmcabe
+ "C90",
# flake8-django
"DJ",
+ "E",
+ # pyflakes, pycodestyle
+ "F",
+ # flake8-boolean-trap
+ "FBT",
# flake8-logging-format
"G",
- # flake8-pie
- "PIE",
- # flake8-simplify
- "SIM",
- # flake8-tidy-imports
- "TID",
+ # isort
+ "I",
# flake8-gettext
"INT",
+ # pep8-naming
+ "N",
# pygrep-hooks
"PGH",
+ # flake8-pie
+ "PIE",
# pylint
"PL",
# unused noqa
"RUF100",
+ # flake8-simplify
+ "SIM",
+ # flake8-tidy-imports
+ "TID",
+ # pyupgrade
+ "UP",
+ "W",
+ # flake8-2020
+ "YTT",
]
-extend-ignore = [
+lint.extend-ignore = [
# Allow zip() without strict=
"B905",
# No line length errors
"E501",
]
-fix = true
-show-fixes = true
-target-version = "py38"
-
-[tool.ruff.isort]
-combine-as-imports = true
-lines-after-imports = 2
-
-[tool.ruff.mccabe]
-max-complexity = 15
-
-[tool.ruff.per-file-ignores]
-"*/migrat*/*" = [
+lint.per-file-ignores."*/migrat*/*" = [
# Allow using PascalCase model names in migrations
"N806",
# Ignore the fact that migration files are invalid module names
"N999",
]
+lint.isort.combine-as-imports = true
+lint.isort.lines-after-imports = 2
+lint.mccabe.max-complexity = 15
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/django-js-asset-2.2/tests/testapp/test_importmap.py
new/django-js-asset-3.1.2/tests/testapp/test_importmap.py
--- old/django-js-asset-2.2/tests/testapp/test_importmap.py 1970-01-01
01:00:00.000000000 +0100
+++ new/django-js-asset-3.1.2/tests/testapp/test_importmap.py 2025-03-04
16:22:35.000000000 +0100
@@ -0,0 +1,42 @@
+from django.test import TestCase
+
+from js_asset.js import ImportMap
+
+
+class MediaTest(TestCase):
+ def test_merging(self):
+ a = ImportMap(
+ {
+ "imports": {"a": "/static/a.js"},
+ "integrity": {"/static/a.js": "sha384-blub-a"},
+ "_unknown_": "Automatically dropped when merging.",
+ }
+ )
+ b = ImportMap(
+ {
+ "imports": {"b": "/static/b.js"},
+ "integrity": {"/static/b.js": "sha384-blub-b"},
+ }
+ )
+
+ self.assertEqual(
+ str(a | b),
+ """\
+<script type="importmap">{"imports": {"a": "/static/a.js", "b":
"/static/b.js"}, "integrity": {"/static/a.js": "sha384-blub-a", "/static/b.js":
"sha384-blub-b"}}</script>""",
+ )
+
+ c = ImportMap(
+ {
+ "imports": {
+ "/app/": "./original-app/",
+ "/app/helper": "./helper/index.mjs",
+ },
+ "scopes": {"/js": {"/app/": "./js-app/"}},
+ }
+ )
+
+ self.assertEqual(
+ str(a | b | c),
+ """\
+<script type="importmap">{"imports": {"a": "/static/a.js", "b":
"/static/b.js", "/app/": "./original-app/", "/app/helper":
"./helper/index.mjs"}, "integrity": {"/static/a.js": "sha384-blub-a",
"/static/b.js": "sha384-blub-b"}, "scopes": {"/js": {"/app/":
"./js-app/"}}}</script>""",
+ )
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/django-js-asset-2.2/tests/testapp/test_js_asset.py
new/django-js-asset-3.1.2/tests/testapp/test_js_asset.py
--- old/django-js-asset-2.2/tests/testapp/test_js_asset.py 2023-12-12
19:03:33.000000000 +0100
+++ new/django-js-asset-3.1.2/tests/testapp/test_js_asset.py 2025-03-04
16:22:35.000000000 +0100
@@ -1,14 +1,7 @@
-from unittest import skipIf
-
-import django
from django.forms import Media
from django.test import TestCase
-from js_asset.js import JS
-
-
-CSS_TYPE = ' type="text/css"' if django.VERSION < (4, 1) else ""
-JS_TYPE = ' type="text/javascript"' if django.VERSION < (3, 1) else ""
+from js_asset.js import CSS, JS, JSON
class AssetTest(TestCase):
@@ -21,33 +14,33 @@
JS("app/asset-without.js", {}),
],
)
- html = "%s" % media
+ html = str(media)
# print(html)
self.assertInHTML(
- f'<link href="/static/app/print.css"{CSS_TYPE} media="print"
rel="stylesheet" />',
+ '<link href="/static/app/print.css" media="print" rel="stylesheet"
/>',
html,
)
self.assertInHTML(
- f'<script{JS_TYPE} src="/static/app/test.js"></script>',
+ '<script src="/static/app/test.js"></script>',
html,
)
self.assertInHTML(
- f'<script{JS_TYPE} src="/static/app/asset.js" data-the-answer="42"
id="asset-script"></script>',
+ '<script src="/static/app/asset.js" data-the-answer="42"
id="asset-script"></script>',
html,
)
self.assertInHTML(
- f'<script{JS_TYPE} src="/static/app/asset-without.js"></script>',
+ '<script src="/static/app/asset-without.js"></script>',
html,
)
def test_absolute(self):
- media = Media(js=[JS("https://cdn.example.org/script.js",
static=False)])
- html = "%s" % media
+ media = Media(js=[JS("https://cdn.example.org/script.js")])
+ html = str(media)
self.assertInHTML(
- f'<script{JS_TYPE}
src="https://cdn.example.org/script.js"></script>',
+ '<script src="https://cdn.example.org/script.js"></script>',
html,
)
@@ -59,14 +52,6 @@
self.assertEqual(media._js[0], "thing.js")
self.assertEqual(media._js[2], "some.js")
- def test_repr(self):
- self.assertEqual(
- repr(
- JS("app/asset.js", {"id": "asset-script", "data-the-answer":
42})
- ).lstrip("u"),
- 'JS(app/asset.js, {"data-the-answer": 42, "id": "asset-script"})',
- )
-
def test_set(self):
media = [
JS("app/asset.js", {"id": "asset-script", "data-the-answer": 42}),
@@ -76,12 +61,35 @@
self.assertEqual(len(set(media)), 2)
- @skipIf(
- django.VERSION < (4, 1),
- "django-js-asset doesn't support boolean attributes yet",
- )
def test_boolean_attributes(self):
self.assertEqual(
str(JS("app/asset.js", {"bool": True, "cool": False})),
'<script src="/static/app/asset.js" bool></script>',
)
+
+ def test_css(self):
+ self.assertEqual(
+ str(CSS("app/style.css")),
+ '<link href="/static/app/style.css" media="all" rel="stylesheet">',
+ )
+
+ self.assertEqual(
+ str(CSS("app/style.css", media="screen")),
+ '<link href="/static/app/style.css" media="screen"
rel="stylesheet">',
+ )
+
+ self.assertEqual(
+ str(CSS("p{color:red}", inline=True)),
+ '<style media="all">p{color:red}</style>',
+ )
+
+ def test_json(self):
+ self.assertEqual(
+ str(JSON({"hello": "world"}, id="hello")),
+ '<script id="hello" type="application/json">{"hello":
"world"}</script>',
+ )
+
+ self.assertEqual(
+ str(JSON({"hello": "world"})),
+ '<script type="application/json">{"hello": "world"}</script>',
+ )
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/django-js-asset-2.2/tox.ini
new/django-js-asset-3.1.2/tox.ini
--- old/django-js-asset-2.2/tox.ini 2023-12-12 19:03:33.000000000 +0100
+++ new/django-js-asset-3.1.2/tox.ini 2025-03-04 16:22:35.000000000 +0100
@@ -1,8 +1,8 @@
[tox]
envlist =
- py{38,39,310}-dj{32,41,42}
- py{310,311}-dj{32,41,42,50,main}
- py{312}-dj{42,50,main}
+ py{310,311}-dj{42,50,51}
+ py{312}-dj{42,50,51,52,main}
+ py{313}-dj{51,52,main}
[testenv]
usedevelop = true
@@ -11,8 +11,8 @@
python -Wd {envbindir}/coverage run tests/manage.py test -v2 --keepdb
{posargs:testapp}
coverage report -m
deps =
- dj32: Django>=3.2,<4.0
- dj41: Django>=4.1,<4.2
dj42: Django>=4.2,<5.0
dj50: Django>=5.0,<5.1
+ dj51: Django>=5.1,<5.2
+ dj52: Django>=5.2a1,<6.0
djmain: https://github.com/django/django/archive/main.tar.gz