diff --git a/stagestatus/apps/machines/admin.py b/stagestatus/apps/machines/admin.py index 7feb3d3..8a9750b 100644 --- a/stagestatus/apps/machines/admin.py +++ b/stagestatus/apps/machines/admin.py @@ -1,7 +1,7 @@ from django.contrib import admin # Register your models here. -from .models import Machine, MachineStatus, MachineNote +from .models import Machine, MachineStatus, MachineReservation class MachineAdmin(admin.ModelAdmin): @@ -13,10 +13,10 @@ class MachineStatusAdmin(admin.ModelAdmin): 'last_updated', 'git_branch', 'git_version') -class MachineNoteAdmin(admin.ModelAdmin): +class MachineReservationAdmin(admin.ModelAdmin): list_display = ('machine', 'notes', 'user') admin.site.register(Machine, MachineAdmin) admin.site.register(MachineStatus, MachineStatusAdmin) -admin.site.register(MachineNote, MachineNoteAdmin) +admin.site.register(MachineReservation, MachineReservationAdmin) diff --git a/stagestatus/apps/machines/api/__init__.py b/stagestatus/apps/machines/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/stagestatus/apps/machines/api/routers.py b/stagestatus/apps/machines/api/routers.py index 3593fdd..7ec1dba 100644 --- a/stagestatus/apps/machines/api/routers.py +++ b/stagestatus/apps/machines/api/routers.py @@ -3,5 +3,5 @@ from rest_framework import routers router = routers.SimpleRouter() router.register('machine', vs.MachineViewSet) -router.register('machine_note', vs.MachineNoteViewSet) +router.register('machine_reservation', vs.MachineReservationViewSet) router.register('machine_status', vs.MachineStatusViewSet) diff --git a/stagestatus/apps/machines/api/serializers.py b/stagestatus/apps/machines/api/serializers.py index b5cbf29..e7602cc 100644 --- a/stagestatus/apps/machines/api/serializers.py +++ b/stagestatus/apps/machines/api/serializers.py @@ -1,12 +1,12 @@ from rest_framework import serializers -from machines.models import Machine, MachineNote, MachineStatus +from machines.models import Machine, MachineReservation, MachineStatus -class MachineNoteSerializer(serializers.ModelSerializer): +class MachineReservationSerializer(serializers.ModelSerializer): class Meta: - model = MachineNote + model = MachineReservation fields = ( 'machine', 'user', @@ -28,7 +28,7 @@ class MachineStatusSerializer(serializers.ModelSerializer): class MachineSerializer(serializers.ModelSerializer): - machine_note = MachineNoteSerializer(read_only=True) + machine_reservation = MachineReservationSerializer(read_only=True) machine_status = MachineStatusSerializer(read_only=True) class Meta: @@ -36,6 +36,6 @@ class MachineSerializer(serializers.ModelSerializer): fields = ( 'hostname', 'db_server', - 'machine_note', + 'machine_reservation', 'machine_status', ) diff --git a/stagestatus/apps/machines/api/viewsets.py b/stagestatus/apps/machines/api/viewsets.py index f62ff36..ecf46f4 100644 --- a/stagestatus/apps/machines/api/viewsets.py +++ b/stagestatus/apps/machines/api/viewsets.py @@ -3,13 +3,13 @@ from rest_framework import viewsets from machines.api.serializers import ( MachineSerializer, - MachineNoteSerializer, + MachineReservationSerializer, MachineStatusSerializer ) -from machines.api.models import ( +from machines.models import ( Machine, - MachineNote, + MachineReservation, MachineStatus ) @@ -20,10 +20,10 @@ class MachineViewSet(mixins.ListModelMixin, queryset = Machine.objects.all() -class MachineNoteViewSet(mixins.ListModelMixin, - viewsets.GenericViewSet): - serializer_class = MachineNoteSerializer - queryset = MachineNote.objects.all() +class MachineReservationViewSet(mixins.ListModelMixin, + viewsets.GenericViewSet): + serializer_class = MachineReservationSerializer + queryset = MachineReservation.objects.all() class MachineStatusViewSet(mixins.ListModelMixin, diff --git a/stagestatus/apps/machines/migrations/0003_rename_machinenote_machinereservation.py b/stagestatus/apps/machines/migrations/0003_rename_machinenote_machinereservation.py new file mode 100644 index 0000000..f4f734e --- /dev/null +++ b/stagestatus/apps/machines/migrations/0003_rename_machinenote_machinereservation.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.6 on 2017-04-01 20:27 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('machines', '0002_auto_20170401_1258'), + ] + + operations = [ + migrations.RenameModel( + old_name='MachineNote', + new_name='MachineReservation', + ), + ] diff --git a/stagestatus/apps/machines/models.py b/stagestatus/apps/machines/models.py index 0364fd4..7989f8f 100644 --- a/stagestatus/apps/machines/models.py +++ b/stagestatus/apps/machines/models.py @@ -20,8 +20,8 @@ class Machine(models.Model): def is_reserved(self): try: - return bool(self.machinenote) - except MachineNote.DoesNotExist: + return bool(self.machinereservation) + except MachineReservation.DoesNotExist: return False def __unicode__(self): @@ -52,7 +52,7 @@ class MachineStatus(models.Model): verbose_name_plural = 'Machine Statuses' -class MachineNote(models.Model): +class MachineReservation(models.Model): """ Notes on the machine as well as who has it checked out. """ diff --git a/stagestatus/apps/machines/serializers.py b/stagestatus/apps/machines/serializers.py new file mode 100644 index 0000000..e7602cc --- /dev/null +++ b/stagestatus/apps/machines/serializers.py @@ -0,0 +1,41 @@ +from rest_framework import serializers + +from machines.models import Machine, MachineReservation, MachineStatus + + +class MachineReservationSerializer(serializers.ModelSerializer): + + class Meta: + model = MachineReservation + fields = ( + 'machine', + 'user', + 'notes', + ) + + +class MachineStatusSerializer(serializers.ModelSerializer): + + class Meta: + model = MachineStatus + fields = ( + 'machine', + 'git_branch', + 'git_version', + 'last_db_refresh', + 'last_updated' + ) + + +class MachineSerializer(serializers.ModelSerializer): + machine_reservation = MachineReservationSerializer(read_only=True) + machine_status = MachineStatusSerializer(read_only=True) + + class Meta: + model = Machine + fields = ( + 'hostname', + 'db_server', + 'machine_reservation', + 'machine_status', + ) diff --git a/stagestatus/apps/machines/tests/test_models.py b/stagestatus/apps/machines/tests/test_models.py index 6333547..0a04a79 100644 --- a/stagestatus/apps/machines/tests/test_models.py +++ b/stagestatus/apps/machines/tests/test_models.py @@ -6,7 +6,7 @@ from model_mommy import mommy # Models from django.contrib.auth.models import User -from machines.models import Machine, MachineStatus, MachineNote +from machines.models import Machine, MachineStatus, MachineReservation class ModelsTest(TestCase): @@ -17,14 +17,14 @@ class ModelsTest(TestCase): self.machine_status = mommy.make(MachineStatus, machine=self.machine ) - self.machine_note = mommy.make(MachineNote, - user=self.user, - machine=self.machine - ) + self.machine_reservation = mommy.make(MachineReservation, + user=self.user, + machine=self.machine + ) def test_mommy(self): """ General assertions to test models """ self.assertEqual(self.machine_status.machine, self.machine) - self.assertEqual(self.machine_note.machine, self.machine) + self.assertEqual(self.machine_reservation.machine, self.machine) self.assertEqual(self.machine_status.machine, - self.machine_note.machine) + self.machine_reservation.machine) diff --git a/stagestatus/apps/machines/tests/test_serializers.py b/stagestatus/apps/machines/tests/test_serializers.py index c13a58b..8c72237 100644 --- a/stagestatus/apps/machines/tests/test_serializers.py +++ b/stagestatus/apps/machines/tests/test_serializers.py @@ -7,7 +7,8 @@ from rest_framework.renderers import JSONRenderer # Models from django.contrib.auth.models import User -from machines.models import Machine, MachineStatus, MachineNote +from machines.models import Machine, MachineStatus, MachineReservation + from machines.api.serializers import MachineSerializer @@ -20,10 +21,10 @@ class SerializerTest(TestCase): self.machine_status = mommy.make(MachineStatus, machine=self.machine ) - self.machine_note = mommy.make(MachineNote, - user=self.user, - machine=self.machine - ) + self.machine_reservation = mommy.make(MachineReservation, + user=self.user, + machine=self.machine + ) def test_serializer(self): """ diff --git a/stagestatus/apps/machines/urls.py b/stagestatus/apps/machines/urls.py index c5b0e85..e67a2b9 100644 --- a/stagestatus/apps/machines/urls.py +++ b/stagestatus/apps/machines/urls.py @@ -1,6 +1,6 @@ from machines.views import MachineList, MachineDetail from django.conf.urls import url, include -from machines.routers import router +from machines.api.routers import router urlpatterns = [ url(r'^api/', include(router.urls)), diff --git a/stagestatus/templates/machines/machine_detail.html b/stagestatus/templates/machines/machine_detail.html index 2e51f33..c40fd89 100644 --- a/stagestatus/templates/machines/machine_detail.html +++ b/stagestatus/templates/machines/machine_detail.html @@ -5,10 +5,10 @@