Files
modoboa/extensions/amavis_quarantine/dbrouter.py
T
Antoine Nguyen 968f91be1a Quarantine plugin update:
* Using django's orm to access amavis database
* Many UI improvments
* Better use of the RS field

fixed #88 & #72
see #155
2011-08-23 16:36:57 +02:00

31 lines
1.1 KiB
Python

class AmavisRouter(object):
"""A router to control all database operations on models in
the amavis_quarantine application"""
def db_for_read(self, model, **hints):
"Point all operations on amavis_quarantine models to 'amavis'"
if model._meta.app_label == 'amavis_quarantine':
return 'amavis'
return None
def db_for_write(self, model, **hints):
"Point all operations on amavis_quarantine models to 'amavis'"
if model._meta.app_label == 'amavis_quarantine':
return 'amavis'
return None
def allow_relation(self, obj1, obj2, **hints):
"Allow any relation if a model in amavis_quarantine is involved"
if obj1._meta.app_label == 'amavis_quarantine' \
or obj2._meta.app_label == 'amavis_quarantine':
return True
return None
def allow_syncdb(self, db, model):
"Make sure the amavis_quarantine app only appears on the 'amavis' db"
if db == 'amavis':
return model._meta.app_label == 'amavis_quarantine'
elif model._meta.app_label == 'amavis_quarantine':
return False
return None