diff --git a/project/settings.py b/project/settings.py index 8855547e..da0cc8c3 100644 --- a/project/settings.py +++ b/project/settings.py @@ -43,7 +43,6 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'debug_toolbar', - 'welcome', ] MIDDLEWARE = [ diff --git a/project/urls.py b/project/urls.py index 5c6a8e36..87e8fb2b 100644 --- a/project/urls.py +++ b/project/urls.py @@ -2,15 +2,12 @@ from django.conf import settings from django.conf.urls import include, url from django.contrib import admin -from welcome.views import index, health - urlpatterns = [ # Examples: # url(r'^$', 'project.views.home', name='home'), # url(r'^blog/', include('blog.urls')), url(r'^$', index), - url(r'^health$', health), url(r'^admin/', include(admin.site.urls)), ] diff --git a/welcome/__init__.py b/test/__init__.py similarity index 100% rename from welcome/__init__.py rename to test/__init__.py diff --git a/test/admin.py b/test/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/test/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/test/apps.py b/test/apps.py new file mode 100644 index 00000000..92401991 --- /dev/null +++ b/test/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class TestConfig(AppConfig): + name = 'test' diff --git a/welcome/migrations/__init__.py b/test/migrations/__init__.py similarity index 100% rename from welcome/migrations/__init__.py rename to test/migrations/__init__.py diff --git a/test/models.py b/test/models.py new file mode 100644 index 00000000..71a83623 --- /dev/null +++ b/test/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/test/tests.py b/test/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/test/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/test/views.py b/test/views.py new file mode 100644 index 00000000..91ea44a2 --- /dev/null +++ b/test/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/welcome/admin.py b/welcome/admin.py deleted file mode 100644 index 5320025e..00000000 --- a/welcome/admin.py +++ /dev/null @@ -1,11 +0,0 @@ -from django.contrib import admin - -from .models import PageView - -# Register your models here. - - -class PageViewAdmin(admin.ModelAdmin): - list_display = ['hostname', 'timestamp'] - -admin.site.register(PageView, PageViewAdmin) diff --git a/welcome/database.py b/welcome/database.py deleted file mode 100644 index 2ac4a3fb..00000000 --- a/welcome/database.py +++ /dev/null @@ -1,22 +0,0 @@ -from django.conf import settings - - -def info(): - db_settings = settings.DATABASES['default'] - if 'postgres' in db_settings['ENGINE']: - engine = 'PostgreSQL' - url = '{HOST}:{PORT}/{NAME}'.format(**db_settings) - elif 'mysql' in db_settings['ENGINE']: - engine = 'MySQL' - url = '{HOST}:{PORT}/{NAME}'.format(**db_settings) - elif 'sqlite' in db_settings['ENGINE']: - engine = 'SQLite' - url = '{NAME}'.format(**db_settings) - else: - engine = 'unknown' - url = '' - return { - 'engine': engine, - 'url': url, - 'is_sqlite': engine == 'SQLite', - } diff --git a/welcome/migrations/0001_initial.py b/welcome/migrations/0001_initial.py deleted file mode 100644 index d607430f..00000000 --- a/welcome/migrations/0001_initial.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import models, migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ] - - operations = [ - migrations.CreateModel( - name='PageView', - fields=[ - ('id', models.AutoField(verbose_name='ID', auto_created=True, serialize=False, primary_key=True)), - ('hostname', models.CharField(max_length=32)), - ('timestamp', models.DateTimeField(auto_now_add=True)), - ], - ), - ] diff --git a/welcome/models.py b/welcome/models.py deleted file mode 100644 index 8567d5d8..00000000 --- a/welcome/models.py +++ /dev/null @@ -1,7 +0,0 @@ -from django.db import models - -# Create your models here. - -class PageView(models.Model): - hostname = models.CharField(max_length=32) - timestamp = models.DateTimeField(auto_now_add=True) diff --git a/welcome/templates/welcome/index.html b/welcome/templates/welcome/index.html deleted file mode 100644 index 1643f5de..00000000 --- a/welcome/templates/welcome/index.html +++ /dev/null @@ -1,322 +0,0 @@ - - - - - - Welcome to OpenShift - - - - - - - -
-
-

Welcome to your Django application on OpenShift

-
- - -
-
-
-

How to use this example application

-

For instructions on how to use this application with OpenShift, start by reading the Developer Guide.

- -

Deploying code changes

-

- The source code for this application is available to be forked from the OpenShift GitHub repository. - You can configure a webhook in your repository to make OpenShift automatically start a build whenever you push your code: -

- -
    -
  1. From the Web Console homepage, navigate to your project
  2. -
  3. Click on Browse > Builds
  4. -
  5. Click the link with your BuildConfig name
  6. -
  7. Click the Configuration tab
  8. -
  9. Click the "Copy to clipboard" icon to the right of the "GitHub webhook URL" field
  10. -
  11. Navigate to your repository on GitHub and click on repository settings > webhooks > Add webhook
  12. -
  13. Paste your webhook URL provided by OpenShift
  14. -
  15. From the "Content Type" dropdown, select "application/json"
  16. -
  17. Leave the defaults for the remaining fields — that's it!
  18. -
-

After you save your webhook, if you refresh your settings page you can see the status of the ping that Github sent to OpenShift to verify it can reach the server.

-

Note: adding a webhook requires your OpenShift server to be reachable from GitHub.

- -

Working in your local Git repository

-

If you forked the application from the OpenShift GitHub example, you'll need to manually clone the repository to your local system. Copy the application's source code Git URL and then run:

- -
$ git clone <git_url> <directory_to_create>
-
-# Within your project directory
-# Commit your changes and push to OpenShift
-
-$ git commit -a -m 'Some commit message'
-$ git push
- -

After pushing changes, you'll need to manually trigger a build if you did not setup a webhook as described above.

- -

Expanding on sample app

-

This project has just a skeleton for you to get started. It includes:

-
    -
  1. Django project created with python manage.py startproject project .
  2. -
  3. Appropriate database configuration
  4. -
  5. Sample Django app created with python manage.py startapp welcome
  6. -
-

- Now it is time to add your own code. - Follow along the Django tutorial to learn more about Django. -

-

- If you are running Django's development server in your local host, you can see more information - about this request using the toolbar on the right.
- Please note that by default your Django settings have DEBUG = True and that is not appropriate for production use, - but very handy during development.
- Refer to the Deployment Checklist - before taking this project into a production environment. -

- -
- -
-
- -

Managing your application

- -

Documentation on how to manage your application from the Web Console or Command Line is available at the Developer Guide.

- -

Web Console

-

You can use the Web Console to view the state of your application components and launch new builds.

- -

Command Line

-

With the OpenShift command line interface (CLI), you can create applications and manage projects from a terminal.

- -

Development Resources

- - -

Request information

-
-Server hostname: {{ hostname }}
-Database server: {{ database.engine }} ({{ database.url }})
-{% if database.is_sqlite %}Data persistence warning: You are currently using SQLite. This is fine for development, but your data won't be persisted across application deployments.{% endif %}
-Page views: {{ count }}
-
- -
-
- - -
- - - - diff --git a/welcome/tests.py b/welcome/tests.py deleted file mode 100644 index 6a5106c2..00000000 --- a/welcome/tests.py +++ /dev/null @@ -1,27 +0,0 @@ -import os - -from .models import PageView -from .database import info -from django.test import TestCase - -# These basic tests are to be used as an example for running tests in S2I -# and OpenShift when building an application image. -class PageViewModelTest(TestCase): - def test_viewpage_model(self): - pageview = PageView.objects.create(hostname='localhost') - pagetest = PageView.objects.get(hostname='localhost') - self.assertEqual(pagetest.hostname, 'localhost') - -class PageViewTest(TestCase): - def test_index(self): - resp = self.client.get('/') - self.assertEqual(resp.status_code, 200) - -class DbEngine(TestCase): - def setUp(self): - os.environ['ENGINE'] = 'SQLite' - - def test_engine_setup(self): - settings = info() - self.assertEqual(settings['engine'], 'SQLite') - self.assertEqual(settings['is_sqlite'], True) diff --git a/welcome/views.py b/welcome/views.py deleted file mode 100644 index 2b82a10c..00000000 --- a/welcome/views.py +++ /dev/null @@ -1,24 +0,0 @@ -import os -from django.shortcuts import render -from django.conf import settings -from django.http import HttpResponse - -from . import database -from .models import PageView - -# Create your views here. - -def index(request): - """Takes an request object as a parameter and creates an pageview object then responds by rendering the index view.""" - hostname = os.getenv('HOSTNAME', 'unknown') - PageView.objects.create(hostname=hostname) - - return render(request, 'welcome/index.html', { - 'hostname': hostname, - 'database': database.info(), - 'count': PageView.objects.count() - }) - -def health(request): - """Takes an request as a parameter and gives the count of pageview objects as reponse""" - return HttpResponse(PageView.objects.count())