From 25e334bd6985d33ed6dff315ef761a6cec0d50c9 Mon Sep 17 00:00:00 2001 From: Rodolfo Carvalho Date: Mon, 25 May 2015 20:57:28 +0200 Subject: [PATCH] Include database info in welcome page --- openshift/templates/openshift/index.html | 1 + openshift/views.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/openshift/templates/openshift/index.html b/openshift/templates/openshift/index.html index 3bba971..75e58c3 100644 --- a/openshift/templates/openshift/index.html +++ b/openshift/templates/openshift/index.html @@ -51,6 +51,7 @@

Server hostname: {{ hostname }}
+ Database server: {{ database_info }}
Page views: {{ count }}

diff --git a/openshift/views.py b/openshift/views.py index 679bbe9..120c9f6 100644 --- a/openshift/views.py +++ b/openshift/views.py @@ -1,14 +1,31 @@ import os from django.shortcuts import render +from django.conf import settings from .models import PageView # Create your views here. + +def _database_info(): + db_settings = settings.DATABASES['default'] + if 'postgres' in db_settings['ENGINE']: + engine = 'PostgreSQL' + info = '{HOST}:{PORT}/{NAME}'.format(**db_settings) + else: + engine = 'SQLite' + info = '{NAME}'.format(**db_settings) + return '{} ({})'.format(engine, info) + +database_info = _database_info() + + def index(request): hostname = os.getenv('HOSTNAME', 'unknown') PageView.objects.create(hostname=hostname) + return render(request, 'openshift/index.html', { 'hostname': hostname, + 'database_info': database_info, 'count': PageView.objects.count() })