def install_middleware():
 name = u'raven.contrib.django.middleware.SentryMiddleware'
 all_names = (name, u'raven.contrib.django.middleware.SentryLogMiddleware')
 with settings_lock:
  middleware_attr = (u'MIDDLEWARE' if (getattr(settings, u'MIDDLEWARE', None) is not None) else u'MIDDLEWARE_CLASSES')
  middleware = (getattr(settings, middleware_attr, ()) or ())
  if set(all_names).isdisjoint(set(middleware)):
   setattr(settings, middleware_attr, (type(middleware)((name,)) + middleware))

def install_middleware ( ) : name = u'raven.contrib.django.middleware.SentryMiddleware' all_names = ( name , u'raven.contrib.django.middleware.SentryLogMiddleware' ) with settings_lock : middleware_attr = ( u'MIDDLEWARE' if ( getattr ( settings , u'MIDDLEWARE' , None ) is not None ) else u'MIDDLEWARE_CLASSES' ) middleware = ( getattr ( settings , middleware_attr , ( ) ) or ( ) ) if set ( all_names ) . isdisjoint ( set ( middleware ) ) : setattr ( settings , middleware_attr , ( type ( middleware ) ( ( name , ) ) + middleware ) )
force installation of sentrymiddlware if its not explicitly present .