From e8261ef423d9cbb3af514258fa9c471ee9be411b Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Wed, 29 Mar 2017 22:46:32 -0400 Subject: [PATCH] add default prod and local confs +x manage.py, add .env to gitignore initial page, tests, change settings --- .gitignore | 2 +- manage.py | 0 requirements/local.txt | 2 + stagestatus/__init__.py | 0 stagestatus/apps/machines/__init__.py | 1 + stagestatus/apps/machines/admin.py | 21 +++++++--- stagestatus/apps/machines/apps.py | 1 + .../apps/machines/migrations/0001_initial.py | 20 +++++++--- stagestatus/apps/machines/models.py | 38 +++++++++++-------- stagestatus/apps/machines/tests.py | 20 +++++++++- stagestatus/apps/machines/urls.py | 6 +++ stagestatus/apps/machines/views.py | 2 - stagestatus/settings/base.py | 25 +++++------- stagestatus/settings/testing.py | 1 - stagestatus/templates/machines/index.html | 1 + stagestatus/urls.py | 3 +- 16 files changed, 93 insertions(+), 50 deletions(-) mode change 100644 => 100755 manage.py delete mode 100644 stagestatus/__init__.py create mode 100644 stagestatus/apps/machines/urls.py delete mode 100644 stagestatus/settings/testing.py create mode 100644 stagestatus/templates/machines/index.html diff --git a/.gitignore b/.gitignore index 549ad65..9f24f18 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,6 @@ dist build eggs parts -bin var sdist develop-eggs @@ -49,6 +48,7 @@ docs/_build env env* venv +.env # intellij *.ipr diff --git a/manage.py b/manage.py old mode 100644 new mode 100755 diff --git a/requirements/local.txt b/requirements/local.txt index 659f4dd..db7468a 100644 --- a/requirements/local.txt +++ b/requirements/local.txt @@ -1,3 +1,5 @@ -r testing.txt Sphinx +pdir2 +ipython diff --git a/stagestatus/__init__.py b/stagestatus/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/stagestatus/apps/machines/__init__.py b/stagestatus/apps/machines/__init__.py index e69de29..5eccf7c 100644 --- a/stagestatus/apps/machines/__init__.py +++ b/stagestatus/apps/machines/__init__.py @@ -0,0 +1 @@ +default_app_config = 'machines.apps.MachinesConfig' diff --git a/stagestatus/apps/machines/admin.py b/stagestatus/apps/machines/admin.py index 2a9372e..7feb3d3 100644 --- a/stagestatus/apps/machines/admin.py +++ b/stagestatus/apps/machines/admin.py @@ -1,13 +1,22 @@ from django.contrib import admin # Register your models here. -from .models import Machine, MachineStatus +from .models import Machine, MachineStatus, MachineNote -class MachineAdmnin(admin.ModelAdmin): - list_display = ('hostname',) -admin.site.register(Machine, MachineAdmnin) + +class MachineAdmin(admin.ModelAdmin): + list_display = ('hostname', 'db_server') class MachineStatusAdmin(admin.ModelAdmin): - list_display = ('machine', 'git_branch', 'notes', 'user') -admin.site.register(MachineStatus, MachineStatusAdmin) \ No newline at end of file + list_display = ('machine', 'last_db_refresh', + 'last_updated', 'git_branch', 'git_version') + + +class MachineNoteAdmin(admin.ModelAdmin): + list_display = ('machine', 'notes', 'user') + + +admin.site.register(Machine, MachineAdmin) +admin.site.register(MachineStatus, MachineStatusAdmin) +admin.site.register(MachineNote, MachineNoteAdmin) diff --git a/stagestatus/apps/machines/apps.py b/stagestatus/apps/machines/apps.py index 5ecf9d1..9815f8c 100644 --- a/stagestatus/apps/machines/apps.py +++ b/stagestatus/apps/machines/apps.py @@ -5,3 +5,4 @@ from django.apps import AppConfig class MachinesConfig(AppConfig): name = 'machines' + verbose_name = 'Machines' diff --git a/stagestatus/apps/machines/migrations/0001_initial.py b/stagestatus/apps/machines/migrations/0001_initial.py index a8e4277..8b10b56 100644 --- a/stagestatus/apps/machines/migrations/0001_initial.py +++ b/stagestatus/apps/machines/migrations/0001_initial.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.10.6 on 2017-03-30 02:31 +# Generated by Django 1.10.6 on 2017-04-01 17:08 from __future__ import unicode_literals from django.conf import settings @@ -9,7 +9,7 @@ import django.db.models.deletion class Migration(migrations.Migration): - replaces = [(b'machines', '0001_initial'), (b'machines', '0002_auto_20170330_0222'), (b'machines', '0003_auto_20170330_0228')] + initial = True dependencies = [ migrations.swappable_dependency(settings.AUTH_USER_MODEL), @@ -23,6 +23,15 @@ class Migration(migrations.Migration): ('db_server', models.CharField(help_text='Database server host', max_length=256)), ], ), + migrations.CreateModel( + name='MachineNote', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('notes', models.CharField(help_text='Reason you are checking out the server.', max_length=256)), + ('machine', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='machines.Machine')), + ('user', models.ForeignKey(help_text='Who checked out the server?', on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), migrations.CreateModel( name='MachineStatus', fields=[ @@ -31,9 +40,10 @@ class Migration(migrations.Migration): ('git_version', models.CharField(help_text='Current tag of the git branch', max_length=256)), ('last_db_refresh', models.DateTimeField(help_text='Time the last database refresh completed')), ('last_updated', models.DateTimeField(auto_now=True, help_text='The time this was last modified')), - ('notes', models.CharField(blank=True, help_text='Reason you are checking out the server.', max_length=256)), - ('machine', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='machines.Machine')), - ('user', models.ForeignKey(blank=True, help_text='Who checked out the server', on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ('machine', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='machines.Machine')), ], + options={ + 'verbose_name_plural': 'Machine Statuses', + }, ), ] diff --git a/stagestatus/apps/machines/models.py b/stagestatus/apps/machines/models.py index 3565940..e7510d8 100644 --- a/stagestatus/apps/machines/models.py +++ b/stagestatus/apps/machines/models.py @@ -16,39 +16,45 @@ class Machine(models.Model): db_server = models.CharField( max_length=256, - help_text="Database server host") + help_text='Database server host') def __unicode__(self): return self.hostname + class MachineStatus(models.Model): """ Represents the data that we store on each server. This data will change every time a machine is checked out, or nightly refreshes, or anything. """ - machine = models.ForeignKey('Machine') + machine = models.OneToOneField('Machine') git_branch = models.CharField( max_length=256, - help_text="Git branch checked out on server.") + help_text='Git branch checked out on server.') git_version = models.CharField( max_length=256, - help_text="Current tag of the git branch") + help_text='Current tag of the git branch') last_db_refresh = models.DateTimeField( - help_text="Time the last database refresh completed") + help_text='Time the last database refresh completed') last_updated = models.DateTimeField( auto_now=True, - help_text="The time this was last modified") - - notes = models.CharField( - blank=True, - max_length=256, - help_text="Reason you are checking out the server.") - user = models.ForeignKey( - User, - blank=True, - help_text="Who checked out the server") + help_text='The time this was last modified') class Meta: - verbose_name_plural = "Machine Statuses" \ No newline at end of file + verbose_name_plural = 'Machine Statuses' + + +class MachineNote(models.Model): + """ + Notes on the machine as well as who has it checked out. + """ + machine = models.OneToOneField('Machine') + + notes = models.CharField( + max_length=256, + help_text='Reason you are checking out the server.') + user = models.ForeignKey( + User, + help_text='Who checked out the server?') diff --git a/stagestatus/apps/machines/tests.py b/stagestatus/apps/machines/tests.py index 32c7c8b..2ab0cdc 100644 --- a/stagestatus/apps/machines/tests.py +++ b/stagestatus/apps/machines/tests.py @@ -1,6 +1,22 @@ +from __future__ import print_function + from django.test import TestCase -# Create your tests here. +from model_mommy import mommy + +# Models +from django.contrib.auth.models import User +from .models import MachineStatus + class MachineTest(TestCase): - pass + def setUp(self): + self.user = mommy.make(User) + self.machinestatus = mommy.make( + MachineStatus, + user=self.user, + make_m2m=True) + self.machine = self.machinestatus.machine + + def test_init(self): + pass diff --git a/stagestatus/apps/machines/urls.py b/stagestatus/apps/machines/urls.py new file mode 100644 index 0000000..8a7145d --- /dev/null +++ b/stagestatus/apps/machines/urls.py @@ -0,0 +1,6 @@ +from django.conf.urls import url +from django.views.generic import TemplateView + +urlpatterns = [ + url(r'^', TemplateView.as_view(template_name='machines/index.html')), +] diff --git a/stagestatus/apps/machines/views.py b/stagestatus/apps/machines/views.py index 91ea44a..2536b37 100644 --- a/stagestatus/apps/machines/views.py +++ b/stagestatus/apps/machines/views.py @@ -1,3 +1 @@ from django.shortcuts import render - -# Create your views here. diff --git a/stagestatus/settings/base.py b/stagestatus/settings/base.py index 499f4e1..74ac2e6 100644 --- a/stagestatus/settings/base.py +++ b/stagestatus/settings/base.py @@ -14,7 +14,6 @@ SECRET_KEY = 'CHANGE THIS!!!' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -IN_TESTING = sys.argv[1:2] == ['test'] ALLOWED_HOSTS = [] @@ -27,13 +26,13 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - # Local apps - 'machines', # Third Party apps 'rest_framework', ] -PROJECT_APPS = [] +PROJECT_APPS = [ + 'machines', +] INSTALLED_APPS += PROJECT_APPS @@ -57,20 +56,20 @@ WSGI_APPLICATION = 'stagestatus.wsgi.application' DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'ENGINE': 'django.db.backends.mysql', 'NAME': 'stagestatus', - 'USER': 'postgres', + 'USER': 'stagestatus', 'PASSWORD': '', - 'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP. - 'PORT': '', # Set to empty string for default. + 'HOST': '', + 'PORT': '', } } # Internationalization -LANGUAGE_CODE = 'en-gb' +LANGUAGE_CODE = 'en-us' -TIME_ZONE = 'UTC' +TIME_ZONE = 'EST' USE_I18N = False @@ -130,13 +129,7 @@ AUTH_PASSWORD_VALIDATORS = [ ] -# .local.py overrides all the common settings. try: from .local import * # noqa except ImportError: pass - - -# importing test settings file if necessary -if IN_TESTING: - from .testing import * # noqa diff --git a/stagestatus/settings/testing.py b/stagestatus/settings/testing.py deleted file mode 100644 index 4b40b38..0000000 --- a/stagestatus/settings/testing.py +++ /dev/null @@ -1 +0,0 @@ -from .base import * # noqa diff --git a/stagestatus/templates/machines/index.html b/stagestatus/templates/machines/index.html new file mode 100644 index 0000000..e965047 --- /dev/null +++ b/stagestatus/templates/machines/index.html @@ -0,0 +1 @@ +Hello diff --git a/stagestatus/urls.py b/stagestatus/urls.py index ede2ec9..53594e6 100644 --- a/stagestatus/urls.py +++ b/stagestatus/urls.py @@ -1,6 +1,7 @@ -from django.conf.urls import url +from django.conf.urls import url, include from django.contrib import admin urlpatterns = [ url(r'^admin/', admin.site.urls), + url(r'^$', include('machines.urls')), ]