From 654ed9bbfe48ecdf9b8237c73bd811374b1b350b Mon Sep 17 00:00:00 2001 From: Sawyer Bergeron Date: Wed, 10 Jan 2018 11:44:23 -0500 Subject: Add Nullable Lab Field to Resources Jira: PHAROS-347 Resources are now possible to associate with lab instances upon creation Change-Id: Id8abbcc448a6d840d55e4bf5130dbec22c8bc58f --- .../account/migrations/0002_auto_20180109_2002.py | 33 ---------------------- .../account/migrations/0002_auto_20180110_1636.py | 33 ++++++++++++++++++++++ .../account/migrations/0003_auto_20180110_1639.py | 24 ++++++++++++++++ dashboard/src/account/models.py | 3 +- dashboard/src/api/serializers.py | 2 +- .../migrations/0003_resource_resource_lab.py | 22 +++++++++++++++ dashboard/src/dashboard/models.py | 2 ++ 7 files changed, 83 insertions(+), 36 deletions(-) delete mode 100644 dashboard/src/account/migrations/0002_auto_20180109_2002.py create mode 100644 dashboard/src/account/migrations/0002_auto_20180110_1636.py create mode 100644 dashboard/src/account/migrations/0003_auto_20180110_1639.py create mode 100644 dashboard/src/dashboard/migrations/0003_resource_resource_lab.py diff --git a/dashboard/src/account/migrations/0002_auto_20180109_2002.py b/dashboard/src/account/migrations/0002_auto_20180109_2002.py deleted file mode 100644 index 5cf8a70..0000000 --- a/dashboard/src/account/migrations/0002_auto_20180109_2002.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10 on 2018-01-09 20:02 -from __future__ import unicode_literals - -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ('account', '0001_initial'), - ] - - operations = [ - migrations.CreateModel( - name='Lab', - fields=[ - ('id', models.AutoField(primary_key=True, serialize=False)), - ('name', models.CharField(max_length=200, unique=True)), - ('contact_email', models.EmailField(blank=True, max_length=200, null=True)), - ('contact_phone', models.CharField(blank=True, max_length=20, null=True)), - ('lab_user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), - ], - ), - migrations.AddField( - model_name='userprofile', - name='email_addr', - field=models.CharField(default='email@mail.com', max_length=300), - ), - ] diff --git a/dashboard/src/account/migrations/0002_auto_20180110_1636.py b/dashboard/src/account/migrations/0002_auto_20180110_1636.py new file mode 100644 index 0000000..6170acb --- /dev/null +++ b/dashboard/src/account/migrations/0002_auto_20180110_1636.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2018-01-10 16:36 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('account', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Lab', + fields=[ + ('id', models.CharField(max_length=200, primary_key=True, serialize=False)), + ('name', models.CharField(max_length=200, unique=True)), + ('contact_email', models.EmailField(blank=True, max_length=200, null=True)), + ('contact_phone', models.CharField(blank=True, max_length=20, null=True)), + ('lab_user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + migrations.AddField( + model_name='userprofile', + name='email_addr', + field=models.CharField(default='email@mail.com', max_length=300), + ), + ] diff --git a/dashboard/src/account/migrations/0003_auto_20180110_1639.py b/dashboard/src/account/migrations/0003_auto_20180110_1639.py new file mode 100644 index 0000000..d0bc4d6 --- /dev/null +++ b/dashboard/src/account/migrations/0003_auto_20180110_1639.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2018-01-10 16:39 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('account', '0002_auto_20180110_1636'), + ] + + operations = [ + migrations.RemoveField( + model_name='lab', + name='id', + ), + migrations.AlterField( + model_name='lab', + name='name', + field=models.CharField(max_length=200, primary_key=True, serialize=False, unique=True), + ), + ] diff --git a/dashboard/src/account/models.py b/dashboard/src/account/models.py index 1e493b9..aad4c50 100644 --- a/dashboard/src/account/models.py +++ b/dashboard/src/account/models.py @@ -36,9 +36,8 @@ class UserProfile(models.Model): return self.user.username class Lab(models.Model): - id = models.AutoField(primary_key=True) lab_user = models.OneToOneField(User, on_delete=models.CASCADE) - name = models.CharField(max_length=200, unique=True, null=False, blank=False) + name = models.CharField(max_length=200, primary_key=True, unique=True, null=False, blank=False) contact_email = models.EmailField(max_length=200, null=True, blank=True) contact_phone = models.CharField(max_length=20, null=True, blank=True) diff --git a/dashboard/src/api/serializers.py b/dashboard/src/api/serializers.py index 794e139..ad9b800 100644 --- a/dashboard/src/api/serializers.py +++ b/dashboard/src/api/serializers.py @@ -33,7 +33,7 @@ class ServerSerializer(serializers.ModelSerializer): class ResourceSerializer(serializers.ModelSerializer): class Meta: model = Resource - fields = ('id', 'name', 'description', 'url', 'server_set', 'dev_pod') + fields = ('id', 'name', 'description', 'resource_lab', 'url', 'server_set', 'dev_pod') class ResourceStatusSerializer(serializers.ModelSerializer): class Meta: diff --git a/dashboard/src/dashboard/migrations/0003_resource_resource_lab.py b/dashboard/src/dashboard/migrations/0003_resource_resource_lab.py new file mode 100644 index 0000000..fff93fd --- /dev/null +++ b/dashboard/src/dashboard/migrations/0003_resource_resource_lab.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2018-01-10 16:36 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('account', '0002_auto_20180110_1636'), + ('dashboard', '0002_auto_20170505_0815'), + ] + + operations = [ + migrations.AddField( + model_name='resource', + name='resource_lab', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='lab_resource_set', to='account.Lab'), + ), + ] diff --git a/dashboard/src/dashboard/models.py b/dashboard/src/dashboard/models.py index 3de7db3..ff55232 100644 --- a/dashboard/src/dashboard/models.py +++ b/dashboard/src/dashboard/models.py @@ -15,6 +15,7 @@ from django.db import models from django.utils import timezone from jenkins.models import JenkinsSlave +from account.models import Lab class Resource(models.Model): @@ -22,6 +23,7 @@ class Resource(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=300, blank=True, null=True) url = models.CharField(max_length=100, blank=True, null=True) + resource_lab = models.ForeignKey(Lab, related_name='lab_resource_set', null=True, blank=True) owner = models.ForeignKey(User, related_name='user_lab_owner', null=True, blank=True) vpn_users = models.ManyToManyField(User, related_name='user_vpn_users', blank=True) slave = models.ForeignKey(JenkinsSlave, on_delete=models.DO_NOTHING, null=True, blank=True) -- cgit 1.2.3-korg