Source code for jmb.core.apps
# -*- coding: utf-8
"""
.. _app-config:
AppConfig
==========
.. autoclass:: JmbCoreConfig
:members:
"""
from __future__ import unicode_literals
import os
import warnings
from django.apps import AppConfig
from django.conf import settings
from . import monkey
[docs]class JmbCoreConfig(AppConfig):
"""An AppConfig that take care to monkey patch django
and apply control over DeprecationWarning
"""
name = 'jmb.core'
def __init__(self, app_name, app_module):
super(JmbCoreConfig, self).__init__(app_name, app_module)
self.tune_warnings()
[docs] def ready(self):
monkey.patch(
include=getattr(settings, 'JMB_MONKEY_PATCH_INCLUDE', None),
exclude=getattr(settings, 'JMB_MONKEY_PATCH_EXCLUDE', None)
)
[docs] def tune_warnings(self):
"""Add filter warnings rules so as to ignore warnings from
modules or matching pattern defined in WARNING_RULES
``WARNINGS_RULES`` must be a list of tuples whose first element is a module name
(e.g.: 'jmb', 'jmb.core', 'django.contrib.auth', 'cms') and the second element
is a regexp matching the text of the message.
These two values will be passed to warnings.filterwarning as module and message
parameters.
"""
WARNING_RULES = getattr(settings, 'WARNING_RULES', [])
if not WARNING_RULES:
return
for mod, text in reversed(WARNING_RULES):
warnings.filterwarnings(
'ignore', category=DeprecationWarning,
module=mod, message=text or '.*')