Skip to content

Commit f6da0d0

Browse files
committed
fixes #131
1 parent 5f8ed64 commit f6da0d0

File tree

6 files changed

+68
-29
lines changed

6 files changed

+68
-29
lines changed

doc/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ sphinxcontrib-jsmath==1.0.1; python_version >= "3.5"
77
sphinxcontrib-qthelp==1.0.3; python_version >= "3.5"
88
sphinxcontrib-serializinghtml==1.1.5; python_version >= "3.5"
99
sphinx-js==3.2.2; python_version >= "3.5"
10-
django-render-static==2.1.0
10+
django-render-static==2.1.1

doc/source/changelog.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
Change Log
33
==========
44

5+
v2.1.1
6+
======
7+
8+
* Fixed `include_properties can result in non-deterministic ordering of constructor parameters that changes render to render <https://github.com/bckohan/django-render-static/issues/131>`_
9+
510
v2.1.0
611
======
712
* Implemented `Support templating of destination paths. <https://github.com/bckohan/django-render-static/issues/129>`_

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "django-render-static"
3-
version = "2.1.0"
3+
version = "2.1.1"
44
description = "Use Django's template engine to render static files at deployment or package time. Includes transpilers for extending Django's url reversal and enums to JavaScript."
55
authors = ["Brian Kohan <bckohan@gmail.com>"]
66
license = "MIT"

render_static/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from .transpilers.enums_to_js import EnumClassWriter
1515
from .transpilers.urls_to_js import ClassURLWriter, SimpleURLWriter
1616

17-
VERSION = (2, 1, 0)
17+
VERSION = (2, 1, 1)
1818

1919
__title__ = 'Django Render Static'
2020
__version__ = '.'.join(str(i) for i in VERSION)

render_static/tests/js_tests.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3697,6 +3697,35 @@ def test_chained_enum_values(self):
36973697
self.assertIn('static VALUE1 = new DependentEnum(1, "VALUE1", IndependentEnum.VALUE1, "DependentEnum.VALUE1");', contents)
36983698
self.assertIn('static VALUE2 = new DependentEnum(2, "VALUE2", IndependentEnum.VALUE0, "DependentEnum.VALUE2");', contents)
36993699

3700+
@override_settings(
3701+
STATIC_TEMPLATES={
3702+
'ENGINES': [{
3703+
'BACKEND': 'render_static.backends.StaticDjangoTemplates',
3704+
'OPTIONS': {
3705+
'loaders': [
3706+
('render_static.loaders.StaticLocMemLoader', {
3707+
'enum_app/test.js': """
3708+
{% enums_to_js enums='render_static.tests.enum_app.models.EnumTester.Color' include_properties="hex,name,value,rgb,label"|split:"," %}
3709+
{% enums_to_js enums='render_static.tests.enum_app.models.EnumTester.MapBoxStyle' include_properties="value,name,label,uri,slug,version"|split:"," %}
3710+
{% enums_to_js enums='render_static.tests.enum_app.models.EnumTester.AddressRoute' include_properties="name,value,alt"|split:"," %}
3711+
"""
3712+
})
3713+
]
3714+
},
3715+
}],
3716+
}
3717+
)
3718+
def test_property_order_determinism_bug131(self):
3719+
enum_js = GLOBAL_STATIC_DIR / 'enum_app/test.js'
3720+
for _ in range(0,10):
3721+
call_command('renderstatic', 'enum_app/test.js')
3722+
transpilation = enum_js.read_text()
3723+
self.assertIn('constructor (value, name, label, rgb, hex)', transpilation)
3724+
self.assertIn('constructor (value, name, label, slug, version, uri, str)', transpilation)
3725+
self.assertIn('constructor (value, name, alt, str)', transpilation)
3726+
os.remove(enum_js)
3727+
3728+
37003729
def tearDown(self):
37013730
pass
37023731

render_static/transpilers/enums_to_js.py

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -200,36 +200,41 @@ def properties(self, enum: Type[Enum]):
200200
"""
201201
builtins = [
202202
bltin for bltin in self.builtins_
203-
if bltin not in self.exclude_properties_
203+
if bltin == 'value' or bltin not in self.exclude_properties_
204204
]
205-
if self.include_properties_ is True:
205+
if (
206+
hasattr(list(enum)[0], 'label') and
207+
'label' not in builtins and
208+
'label' not in self.exclude_properties_ and
209+
self.include_properties_
210+
):
211+
builtins.append('label')
212+
213+
props_on_class = [
214+
str(name)
215+
for name, member in vars(enum).items()
206216
if (
207-
hasattr(list(enum)[0], 'label') and
208-
'label' not in builtins and
209-
'label' not in self.exclude_properties_
210-
):
211-
builtins.append('label')
212-
props_on_class = [
213-
str(name)
214-
for name, member in vars(enum).items()
215-
if (
216-
isinstance(member, property) and
217-
name not in self.exclude_properties_
218-
and str(name) not in builtins
219-
)
220-
]
217+
isinstance(member, property) and
218+
name not in self.exclude_properties_
219+
and str(name) not in builtins
220+
)
221+
]
222+
prop_def_order = [
223+
*builtins,
224+
*[
225+
prop for prop in getattr(enum, '_properties_', [])
226+
if prop not in self.exclude_properties_
227+
and prop not in builtins and prop not in props_on_class
228+
],
229+
*props_on_class
230+
]
231+
if self.include_properties_ is True:
232+
self.properties_ = prop_def_order
233+
elif self.include_properties_:
221234
self.properties_ = [
222-
*builtins,
223-
*props_on_class,
224-
# handle enum-properties defined properties
225-
*[
226-
prop for prop in getattr(enum, '_properties_', [])
227-
if prop not in self.exclude_properties_
228-
and prop not in builtins and prop not in props_on_class
229-
]
235+
prop for prop in prop_def_order
236+
if prop in self.include_properties_ or prop == 'value'
230237
]
231-
elif self.include_properties_:
232-
self.properties_ = list({*self.include_properties_, 'value'})
233238
else:
234239
self.properties_ = builtins
235240

0 commit comments

Comments
 (0)