Skip to content

Commit 4e1c7f1

Browse files
Add the preference model instance to the parameters of the preference_updated signal's.
1 parent 3017fde commit 4e1c7f1

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

docs/react_to_updates.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ of the signal, which are:
2020
* ``name`` - the name of the changed preference
2121
* ``old_value`` - the value of the preference before changing
2222
* ``new_value`` - the value assigned to the preference after the change
23-
23+
* ``instance`` - the preference Model instance
2424
An example that just prints a message that the preference was changed is
2525
below.
2626

2727
.. code-block:: python
2828
2929
# yourapp/util.py
3030
31-
def notify_on_preference_update(sender, section, name, old_value, new_value, **kwargs):
31+
def notify_on_preference_update(sender, section, name, old_value, new_value, instance, **kwargs):
3232
print("Preference {} in section {} changed from {} to {}".format(
3333
name, section, old, new))
3434

dynamic_preferences/managers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ def update_db_pref(self, section, name, value):
173173
name=name,
174174
old_value=old_value,
175175
new_value=value,
176+
instance=db_pref
176177
)
177178
except self.model.DoesNotExist:
178179
return self.create_db_pref(section, name, value)

tests/test_preferences.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ class P(StringPreference):
192192
def test_preferences_manager_signal(db):
193193
global_preferences = global_preferences_registry.manager()
194194
global_preferences["no_section"] = False
195+
pref = global_preferences.get_db_pref(name="no_section", section=None)
196+
195197
receiver = MagicMock()
196198
preference_updated.connect(receiver)
197199
global_preferences["no_section"] = True
@@ -203,4 +205,5 @@ def test_preferences_manager_signal(db):
203205
"name": "no_section",
204206
"old_value": False,
205207
"new_value": True,
208+
"instance": pref
206209
}.items() <= call_args.items()

0 commit comments

Comments
 (0)