1
|
|
|
from django.apps import AppConfig |
2
|
|
|
from django.conf import settings |
3
|
|
|
from django.core.checks import register, Tags, Error, Warning |
4
|
|
|
|
5
|
|
|
from .monkey_patch import patch |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
VALID_DATABASE_ENGINES = { |
9
|
|
|
'django.db.backends.sqlite3', |
10
|
|
|
'django.db.backends.postgresql_psycopg2', |
11
|
|
|
'django.db.backends.mysql', |
12
|
|
|
|
13
|
|
|
# GeoDjango |
14
|
|
|
'django.contrib.gis.db.backends.spatialite', |
15
|
|
|
'django.contrib.gis.db.backends.postgis', |
16
|
|
|
'django.contrib.gis.db.backends.mysql', |
17
|
|
|
|
18
|
|
|
# django-transaction-hooks |
19
|
|
|
'transaction_hooks.backends.sqlite3', |
20
|
|
|
'transaction_hooks.backends.postgis', |
21
|
|
|
'transaction_hooks.backends.postgresql_psycopg2', |
22
|
|
|
'transaction_hooks.backends.mysql', |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
VALID_CACHE_BACKENDS = { |
27
|
|
|
'django.core.cache.backends.dummy.DummyCache', |
28
|
|
|
'django.core.cache.backends.locmem.LocMemCache', |
29
|
|
|
'django.core.cache.backends.filebased.FileBasedCache', |
30
|
|
|
'django_redis.cache.RedisCache', |
31
|
|
|
'django.core.cache.backends.memcached.MemcachedCache', |
32
|
|
|
'django.core.cache.backends.memcached.PyLibMCCache', |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
@register(Tags.compatibility) |
37
|
|
|
def check_compatibility(app_configs, **kwargs): |
38
|
|
|
errors = [] |
39
|
|
|
for setting, k, valid_values in ( |
40
|
|
|
(settings.DATABASES, 'ENGINE', VALID_DATABASE_ENGINES), |
41
|
|
|
(settings.CACHES, 'BACKEND', VALID_CACHE_BACKENDS)): |
42
|
|
|
for alias, d in setting.items(): |
43
|
|
|
value = d[k] |
44
|
|
|
if value not in valid_values: |
45
|
|
|
error_class = Error if alias == 'default' else Warning |
46
|
|
|
errors.append( |
47
|
|
|
error_class( |
48
|
|
|
'`%s` is not compatible with django-cachalot.' % value, |
49
|
|
|
id='cachalot.E001', |
50
|
|
|
) |
51
|
|
|
) |
52
|
|
|
return errors |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
class CachalotConfig(AppConfig): |
56
|
|
|
name = 'cachalot' |
57
|
|
|
patched = False |
58
|
|
|
|
59
|
|
|
def ready(self): |
60
|
|
|
if not self.patched: |
61
|
|
|
patch() |
62
|
|
|
self.patched = True |
63
|
|
|
|