2015-05-24 13:56:43 +02:00
|
|
|
import os
|
2015-05-24 13:10:47 +02:00
|
|
|
from django.shortcuts import render
|
2015-05-25 20:57:28 +02:00
|
|
|
from django.conf import settings
|
2015-05-24 13:10:47 +02:00
|
|
|
|
2015-05-25 16:12:22 +02:00
|
|
|
from .models import PageView
|
|
|
|
|
2015-05-24 13:10:47 +02:00
|
|
|
# Create your views here.
|
|
|
|
|
2015-05-25 20:57:28 +02:00
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
|
2015-05-24 13:10:47 +02:00
|
|
|
def index(request):
|
2015-05-25 16:12:22 +02:00
|
|
|
hostname = os.getenv('HOSTNAME', 'unknown')
|
|
|
|
PageView.objects.create(hostname=hostname)
|
2015-05-25 20:57:28 +02:00
|
|
|
|
2015-05-25 16:12:22 +02:00
|
|
|
return render(request, 'openshift/index.html', {
|
2015-05-25 20:54:23 +02:00
|
|
|
'hostname': hostname,
|
2015-05-25 20:57:28 +02:00
|
|
|
'database_info': database_info,
|
2015-05-25 16:12:22 +02:00
|
|
|
'count': PageView.objects.count()
|
|
|
|
})
|