Skip to content

Commit

Permalink
Remove duplicate is_postgres function from inventory.views.
Browse files Browse the repository at this point in the history
  • Loading branch information
sheagcraig committed Mar 1, 2018
1 parent 51dd67f commit 0f57969
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
14 changes: 4 additions & 10 deletions inventory/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def _get_filtered_queryset(self):

def _get_unique_items(self, details):
"""Use optimized DB methods for getting unique items if possible."""
if is_postgres():
if utils.is_postgres():
versions = details.order_by("version").distinct(
"version").values_list("version", flat=True)
paths = details.order_by("path").distinct("path").values_list(
Expand Down Expand Up @@ -459,7 +459,7 @@ def get(self, request, *args, **kwargs):
if group_type != "all":
self.components.append(group_id)

if is_postgres():
if utils.is_postgres():
apps = [self.get_application_entry(item, queryset) for item in
queryset.select_related("application").order_by(
).distinct("application")]
Expand Down Expand Up @@ -565,14 +565,14 @@ def inventory_submit(request):
path=item.get('path', ''),
machine=machine
)
if is_postgres():
if utils.is_postgres():
inventory_items_to_be_created.append(i_item)
else:
i_item.save()
machine.last_inventory_update = timezone.now()
inventory_meta.save()

if is_postgres():
if utils.is_postgres():
InventoryItem.objects.bulk_create(
inventory_items_to_be_created)
machine.save()
Expand All @@ -598,9 +598,3 @@ def inventory_hash(request, serial):
else:
return HttpResponse("MACHINE NOT FOUND")
return HttpResponse(sha256hash)


def is_postgres():
postgres_backend = 'django.db.backends.postgresql_psycopg2'
db_setting = settings.DATABASES['default']['ENGINE']
return db_setting == postgres_backend
7 changes: 3 additions & 4 deletions server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,9 @@ def listify_condition_data(data):


def is_postgres():
if settings.DATABASES['default']['ENGINE'] == 'django.db.backends.postgresql_psycopg2':
return True
else:
return False
postgres_backend = 'django.db.backends.postgresql_psycopg2'
db_setting = settings.DATABASES['default']['ENGINE']
return db_setting == postgres_backend


def flatten_and_sort_list(the_list):
Expand Down

0 comments on commit 0f57969

Please sign in to comment.