diff options
author | Dan McGee <dan@archlinux.org> | 2012-07-08 00:28:02 +0200 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2012-07-09 04:08:04 +0200 |
commit | 26a00cadcebc0b37775954d261ec73f927ceca12 (patch) | |
tree | 8a1246c72e014a92d6b4b98055b37d770e970812 /main | |
parent | 4cd588ae898c2abc8035cf0165ccdd038f2321bd (diff) | |
download | archweb-26a00cadcebc0b37775954d261ec73f927ceca12.tar.gz archweb-26a00cadcebc0b37775954d261ec73f927ceca12.tar.xz |
Don't log package updates in Python when we have DB trigger support
This adds a helper method to find the database engine in use, and then
skips code we shouldn't execute if we are doing this another way.
Note that this helper method could be useful for backend-specific code
paths elsewhere, such as custom SQL being called or lack of StdDev() in
sqlite3 out of the box.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'main')
-rw-r--r-- | main/utils.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/main/utils.py b/main/utils.py index b7cb19f..879abfb 100644 --- a/main/utils.py +++ b/main/utils.py @@ -8,6 +8,7 @@ import hashlib from pytz import utc from django.core.cache import cache +from django.db import connections, router CACHE_TIMEOUT = 1800 @@ -106,6 +107,16 @@ def set_created_field(sender, **kwargs): obj.created = utc_now() +def database_vendor(model, mode='read'): + if mode == 'read': + database = router.db_for_read(model) + elif mode == 'write': + database = router.db_for_write(model) + else: + raise Exception('Invalid database mode specified') + return connections[database].vendor + + def groupby_preserve_order(iterable, keyfunc): '''Take an iterable and regroup using keyfunc to determine whether items belong to the same group. The order of the iterable is preserved and |