UserEventPreferences
pretalx.person.models.preferences.UserEventPreferences source
Per-user preferences, scoped to an event. event=None is for global preferences, e.g. tables outside of an event context.
Fields 6
idAutoFieldpkuserForeignKeysource
user = models.ForeignKey(
to="User", on_delete=models.CASCADE, related_name="event_preferences"
)
eventForeignKeynullsource
event = models.ForeignKey(
to="event.Event",
on_delete=models.CASCADE,
related_name="user_preferences",
null=True,
)
preferencesJSONFieldsource
preferences = models.JSONField(default=dict, blank=True)
createdDateTimeFieldnullTimestampedModelsource
on pretalx.common.models.mixins.TimestampedModel source
created = models.DateTimeField(
verbose_name=_("Created"), auto_now_add=True, blank=True, null=True
)
updatedDateTimeFieldnullTimestampedModelsource
on pretalx.common.models.mixins.TimestampedModel source
updated = models.DateTimeField(
verbose_name=_("Updated"), auto_now=True, blank=True, null=True
)
Attributes 1
objects<pretalx.common.models.managers.PretalxManager>Methods 29
Defined here
clear(path, commit=False)sourceDelete a preference parameter specified by its dotted path.
The key and any child keys will be deleted. Invalid keys will be ignored silently.
def clear(self, path, commit=False):
"""Delete a preference parameter specified by its dotted path.
The key and any child keys will be deleted. Invalid keys will be ignored
silently.
"""
parent, key = self._retrieve_parent(path, create=False)
if isinstance(parent, dict):
parent.pop(key, None)
if commit:
self.save()
get(path)sourceRetrieve a preference parameter specified by its dotted path.
For example, preferences.get('tables.SubmissionTable.columns') returns self.preferences["tables"]["SubmissionTable"]["columns"]. Returns None if the key does not exist.
def get(self, path):
"""Retrieve a preference parameter specified by its dotted path.
For example, ``preferences.get('tables.SubmissionTable.columns')`` returns
``self.preferences["tables"]["SubmissionTable"]["columns"]``.
Returns ``None`` if the key does not exist.
"""
with suppress(TypeError, KeyError, AttributeError):
parent, key = self._retrieve_parent(path)
return parent.get(key)
set(path, value, commit=False)sourceDefine or overwrite a preference parameter.
Usage: preferences.set('tables.SubmissionTable.columns', ['title', 'state'])
Leaf nodes CAN be overridden with dicts, changing the data structure. Setting a branch node to a new dict will override the branch, NOT merge it. Branch nodes cannot be overwritten as single values, the existing key must first be cleared.
def set(self, path, value, commit=False):
"""Define or overwrite a preference parameter.
Usage: ``preferences.set('tables.SubmissionTable.columns', ['title', 'state'])``
Leaf nodes CAN be overridden with dicts, changing the data structure. Setting
a branch node to a new dict will override the branch, NOT merge it.
Branch nodes cannot be overwritten as single values, the existing key must
first be cleared.
"""
parent, key = self._retrieve_parent(path, create=True)
# Set a key based on the last item in the path.
# Raise TypeError if attempting to overwrite a non-leaf node.
if (
key in parent
and isinstance(parent[key], dict)
and not isinstance(value, dict)
):
raise TypeError(
f"Key '{path}' is a dictionary; cannot assign a non-dictionary value"
)
parent[key] = value
if commit:
self.save()
__str__()sourceReturn str(self).
on pretalx.person.models.preferences.UserEventPreferences source
def __str__(self):
if not self.event:
return f"Global preferences for {self.user}"
return f"Preferences for {self.user} and {self.event}"
Return str(self).
def __str__(self):
return "%s object (%s)" % (self.__class__.__name__, self.pk)