Skip to content
Closed
Changes from all commits
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
11 changes: 4 additions & 7 deletions src/adminactions/mass_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def __getitem__(self, field_class: type[AnyField]) -> dict[str, TOperation]:
(add_percent, True, True, _("add <arg> percent to existing value")),
),
("sub percent", (sub_percent, True, True, "")),
("sub", (sub_percent, True, True, "")),
("sub", (sub, True, True, "")),
("add", (add, True, True, "")),
],
df.BooleanField: [("toggle", (negate, False, True, ""))],
Expand Down Expand Up @@ -283,10 +283,8 @@ def _clean_fields(self) -> None:
if function:
func, hasparm, __, __ = OPERATIONS.get_for_field(field_object)[function]
self.update_using_queryset_allowed &= func is None
if func is None:
if func is None or hasparm:
pass
elif hasparm:
value = curry(func, value)
else:
value = func
if hasattr(self, f"clean_{name}"):
Expand Down Expand Up @@ -355,7 +353,7 @@ def mass_update_execute( # noqa: C901
func = OPERATIONS.get_function(func_name)
if callable(func):
old_value = getattr(record, field_name)
setattr(record, field_name, func(old_value))
setattr(record, field_name, func(value, old_value))
else:
changed_attr = getattr(record, field_name, None)
if changed_attr.__class__.__name__ == "ManyRelatedManager":
Expand Down Expand Up @@ -491,8 +489,7 @@ def _get_sample() -> dict[str, list[tuple[Any, str] | dict[str, Any]]]:
enabler = f"chk_id_{field_name}"
if form.data.get(enabler, False) == "on":
op = form.data.get(f"func_id_{field_name}")
if callable(value):
value = None

if isinstance(value, QuerySet):
rules[field_name] = (op, list(value.values_list("pk", flat=True)))
else:
Expand Down
Loading