CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-django-dynamic-preferences

Dynamic global and instance settings for your django project

Pending
Overview
Eval results
Files

signals.mddocs/

Signals

Django signal system integration for reacting to preference changes. The signals module provides Django signals that are emitted when preferences are updated, allowing you to hook into preference changes for custom logic, logging, or cache invalidation.

Capabilities

Preference Updated Signal

Signal emitted whenever a preference value is updated through any mechanism (manager, admin, API, forms). This signal is sent after the preference value has been successfully changed in the database.

from django.dispatch import Signal

preference_updated: Signal

Signal Arguments:

  • sender: The preference class that was updated
  • section: Section name of the updated preference
  • name: Name of the updated preference
  • old_value: Previous value of the preference
  • new_value: New value of the preference
  • instance: The preference model instance that was updated

Usage Examples

Connecting to the Signal:

from dynamic_preferences.signals import preference_updated
from django.dispatch import receiver

@receiver(preference_updated)
def handle_preference_change(sender, section, name, old_value, new_value, instance, **kwargs):
    """Handle preference updates for logging or cache invalidation."""
    print(f"Preference {section}__{name} changed from {old_value} to {new_value}")
    
    # Example: Clear cache when maintenance mode changes
    if section == 'general' and name == 'maintenance_mode':
        from django.core.cache import cache
        cache.clear()

# Alternative connection method
def notify_on_preference_update(sender, section, name, old_value, new_value, instance, **kwargs):
    """Send notification when important preferences change."""
    if section in ['email', 'notifications']:
        # Send notification to administrators
        pass

preference_updated.connect(notify_on_preference_update)

Using in Django Apps:

# apps.py
from django.apps import AppConfig
from dynamic_preferences.signals import preference_updated

class MyAppConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'myapp'
    
    def ready(self):
        preference_updated.connect(self.handle_preference_update)
        
    def handle_preference_update(self, sender, section, name, old_value, new_value, instance, **kwargs):
        # Custom handling logic
        pass

Filtering by Preference Type:

@receiver(preference_updated)
def handle_site_preferences(sender, section, name, old_value, new_value, instance, **kwargs):
    """Only handle site-wide configuration changes."""
    if section == 'site_config':
        # Rebuild static files, clear CDN cache, etc.
        pass

The signal is automatically emitted when preferences are updated through:

  • PreferencesManager (programmatic updates)
  • Django Admin interface
  • REST API endpoints
  • Form submissions

Install with Tessl CLI

npx tessl i tessl/pypi-django-dynamic-preferences

docs

admin-integration.md

core-models.md

django-integration.md

forms-views.md

index.md

preference-types.md

registries.md

rest-api.md

serialization.md

signals.md

user-preferences.md

tile.json