From f019e9254ec0c42f670fda7183c300263ee65c1e Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 23 Sep 2015 01:38:24 +0200 Subject: Reporting: Do not use django.db.backend in newer django versions The private API django.db.backend is deprecated in django 1.7 and removed in django 1.8, so we use another way to get the DatabaseOperations from the connection. --- src/lib/Bcfg2/Reporting/models.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src') 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) -- cgit v1.2.3-1-g7c22