Ticket #12012: 12012-r11624.diff

File 12012-r11624.diff, 1.9 KB (added by Vinay Sajip, 15 years ago)

Improved patch to show hooks at settings read, pre app/model load and post app/model load

  • django/db/models/loading.py

     
    5252        try:
    5353            if self.loaded:
    5454                return
     55
     56            if hasattr(settings, 'PRE_MODEL_CALLBACKS'):
     57                callbacks = settings.PRE_MODEL_CALLBACKS
     58                for callback in callbacks:
     59                    callback()
     60
    5561            for app_name in settings.INSTALLED_APPS:
    5662                if app_name in self.handled:
    5763                    continue
     
    6066                for app_name in self.postponed:
    6167                    self.load_app(app_name)
    6268                self.loaded = True
     69
     70            if hasattr(settings, 'POST_MODEL_CALLBACKS'):
     71                callbacks = settings.POST_MODEL_CALLBACKS
     72                for callback in callbacks:
     73                    callback()
     74
    6375        finally:
    6476            self.write_lock.release()
    6577
  • django/conf/__init__.py

     
    8585                    setting_value = (setting_value,) # In case the user forgot the comma.
    8686                setattr(self, setting, setting_value)
    8787
     88        if hasattr(self, 'BOOTSTRAP_CALLBACKS'):
     89            try:
     90                callbacks = self.BOOTSTRAP_CALLBACKS
     91                for callback in callbacks:
     92                    try:
     93                        callback()
     94                    except Exception:
     95                        raise # TODO handle error in callback
     96            except TypeError:
     97                raise # TODO handle non-iterable
     98
    8899        # Expand entries in INSTALLED_APPS like "django.contrib.*" to a list
    89100        # of all those apps.
    90101        new_installed_apps = []
Back to Top