Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/

# because this is a package, we don't want to commit the lock file
poetry.lock
Expand Down
12 changes: 9 additions & 3 deletions inertia/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,20 @@
**(self.request.inertia),
**self.props,
}
delete_queue = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be a set() instead of an ordered list.


for key, value in _props.items():
if isinstance(value, AlwaysProp):

Check failure on line 98 in inertia/http.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F821)

inertia/http.py:98:34: F821 Undefined name `AlwaysProp`
continue

for key in list(_props.keys()):
if self.request.is_a_partial_render(self.component):
if key not in self.request.partial_keys():
del _props[key]
delete_queue.append(key)
else:
if isinstance(_props[key], IgnoreOnFirstLoadProp):
del _props[key]
delete_queue.append(key)

_props = {key: val for key, val in _props.items() if key not in delete_queue}

return deep_transform_callables(_props)

Expand Down
4 changes: 4 additions & 0 deletions inertia/prop_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class IgnoreOnFirstLoadProp:
pass


class AlwaysProp(CallableProp):
pass


class OptionalProp(CallableProp, IgnoreOnFirstLoadProp):
pass

Expand Down
6 changes: 5 additions & 1 deletion inertia/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import warnings

from django.core.serializers.json import DjangoJSONEncoder
from django.db import models
from django.db.models.query import QuerySet
from django.forms.models import model_to_dict as base_model_to_dict

from .prop_classes import DeferredProp, MergeProp, OptionalProp
from .prop_classes import DeferredProp, MergeProp, OptionalProp, AlwaysProp

Check failure on line 8 in inertia/utils.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

inertia/utils.py:1:1: I001 Import block is un-sorted or un-formatted


def model_to_dict(model):
Expand Down Expand Up @@ -41,6 +41,10 @@
return optional(prop)


def always(prop):
return AlwaysProp(prop)


def optional(prop):
return OptionalProp(prop)

Expand Down
Loading