diff options
-rw-r--r-- | src/lib/Bcfg2/Reporting/models.py | 17 | ||||
-rwxr-xr-x | tools/upgrade/1.3/migrate_dbstats.py | 17 |
2 files changed, 22 insertions, 12 deletions
diff --git a/src/lib/Bcfg2/Reporting/models.py b/src/lib/Bcfg2/Reporting/models.py index 8e2c644fb..6ba7d3765 100644 --- a/src/lib/Bcfg2/Reporting/models.py +++ b/src/lib/Bcfg2/Reporting/models.py @@ -1,9 +1,10 @@ """Django models for Bcfg2 reports.""" import sys +import django from django.core.exceptions import ImproperlyConfigured try: - from django.db import models, backend, connections + from django.db import models, connections except ImproperlyConfigured: e = sys.exc_info()[1] print("Reports: unable to import django models: %s" % e) @@ -61,11 +62,15 @@ def _quote(value): """ global _our_backend if not _our_backend: - try: - _our_backend = backend.DatabaseOperations( - connections[get_db_label('Reporting')]) - except TypeError: - _our_backend = backend.DatabaseOperations() + if django.VERSION[0] == 1 and django.VERSION[1] >= 7: + _our_backend = connections[get_db_label('Reporting')].ops + else: + from django.db import backend + try: + _our_backend = backend.DatabaseOperations( + connections[get_db_label('Reporting')]) + except TypeError: + _our_backend = backend.DatabaseOperations() return _our_backend.quote_name(value) diff --git a/tools/upgrade/1.3/migrate_dbstats.py b/tools/upgrade/1.3/migrate_dbstats.py index c788aae37..8911266fb 100755 --- a/tools/upgrade/1.3/migrate_dbstats.py +++ b/tools/upgrade/1.3/migrate_dbstats.py @@ -9,7 +9,8 @@ import time import Bcfg2.Logger import Bcfg2.Options from Bcfg2.DBSettings import get_db_label -from django.db import transaction, backend, connections +import django +from django.db import transaction, connections from Bcfg2.Server.Admin import UpdateReports from Bcfg2.Reporting.utils import BatchFetch from Bcfg2.Reporting.Compat import transaction @@ -28,11 +29,15 @@ def _quote(value): """ global _our_backend if not _our_backend: - try: - _our_backend = backend.DatabaseOperations( - connections[get_db_label('Reporting')]) - except TypeError: - _our_backend = backend.DatabaseOperations() + if django.VERSION[0] == 1 and django.VERSION[1] >= 7: + _our_backend = connections[get_db_label('Reporting')].ops + else: + from django.db import backend + try: + _our_backend = backend.DatabaseOperations( + connections[get_db_label('Reporting')]) + except TypeError: + _our_backend = backend.DatabaseOperations() return _our_backend.quote_name(value) |