Login

easy signal registration

Author:
aisbaa
Posted:
October 5, 2011
Language:
Python
Version:
Not specified
Score:
2 (after 2 ratings)

Django signals can live anywhere you like. I like them in app/signals.py file. This snippet imports signal modules from all installed apps.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
import logging

from importlib import import_module

from django.conf import settings

print logging, logging.__name__

logger = logging.getLogger(__name__)

signal_modules = {}

for app in settings.INSTALLED_APPS:
    signals_module = '%s.signals' % app
    try:
        signal_modules[app] = import_module(signals_module)
    except ImportError as e:
        logger.warning(
            'failed to import "%s", reason: %s' % (signals_module, str(e)))

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 2 months, 2 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 2 months, 3 weeks ago
  3. Serializer factory with Django Rest Framework by julio 9 months, 3 weeks ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 10 months, 1 week ago
  5. Help text hyperlinks by sa2812 11 months ago

Comments

aisbaa (on October 5, 2011):

sry left prin by mistake XD,, can edit this snippet ?

#

Please login first before commenting.