Commit bbc68672 authored by Lukas Burgey's avatar Lukas Burgey

Change some model fields

parent 4da1239d
# Generated by Django 2.1.3 on 2018-11-12 12:36
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('backend', '0016_credentialstate__credential_deleted'),
]
operations = [
migrations.AlterField(
model_name='newdeployment',
name='state_target',
field=models.CharField(choices=[('deployed', 'Deployed'), ('not_deployed', 'Not Deployed')], default='not_deployed', max_length=50),
),
]
# Generated by Django 2.1.3 on 2018-11-12 14:10
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('backend', '0018_auto_20181112_1336'),
]
operations = [
migrations.RemoveField(
model_name='newdeployment',
name='service',
),
]
......@@ -149,6 +149,7 @@ class NewDeployment(models.Model):
on_delete=models.SET_NULL,
null=True,
)
# member ship in this group the authorization for service usage
group = models.ForeignKey(
Group,
related_name='deployments',
......@@ -156,18 +157,11 @@ class NewDeployment(models.Model):
null=True,
blank=True,
)
service = models.ForeignKey(
Service,
related_name='deployments',
on_delete=models.CASCADE,
null=True,
blank=True,
)
# which state do we currently want to reach?
state_target = models.CharField(
max_length=50,
choices=STATE_CHOICES,
choices=TARGET_CHOICES,
default=NOT_DEPLOYED,
)
......@@ -201,9 +195,8 @@ class NewDeployment(models.Model):
@property
def services(self):
if self.group is not None:
return self.group.services.all()
return [self.service]
return self.group.services.all()
@property
def sites(self):
......@@ -237,39 +230,21 @@ class NewDeployment(models.Model):
).save()
@classmethod
def get_deployment(cls, user, service=None, group=None, site=None):
if service is None and group is None:
def get_deployment(cls, user, group=None, site=None):
if group is None:
raise ValueError('get_deployment needs a service or a group')
try:
dep = None
if service is not None:
dep = cls.objects.get(
user=user,
service=service,
)
elif group is not None:
dep = cls.objects.get(
user=user,
group=group,
)
return dep
return cls.objects.get(
user=user,
group=group,
)
except cls.DoesNotExist:
deployment = None
if service is not None and group is None:
deployment = cls(
user=user,
service=service,
)
elif group is not None:
deployment = cls(
user=user,
group=group,
)
deployment = cls(
user=user,
group=group,
)
deployment.save()
deployment.create_state_items(site=site)
......@@ -323,31 +298,25 @@ class NewDeployment(models.Model):
data = NewDeploymentSerializer(self).data
msg = dumps(data)
if self.service is not None:
RabbitMQInstance.load().publish_by_service(
self.service,
msg,
)
elif self.group is not None:
RabbitMQInstance.load().publish_by_group(
self.group,
msg,
)
else:
raise ValueError('Deployment has neither a group or a service')
RabbitMQInstance.load().publish_by_group(
self.group,
msg,
)
# sends a state update via RabbitMQ / STOMP to the users webpage instance
def publish_to_user(self):
if self.user is not None:
# avoiding circular dependencies here
from .serializers.webpage import NewDeploymentSerializer
msg = dumps({
'deployment': NewDeploymentSerializer(self).data,
})
RabbitMQInstance.load().publish_to_user(
self.user,
msg,
)
if self.user is None:
raise ValueError('Unable to publish deployment to None user')
# avoiding circular dependencies here
from .serializers.webpage import NewDeploymentSerializer
msg = dumps({
'deployment': NewDeploymentSerializer(self).data,
})
RabbitMQInstance.load().publish_to_user(
self.user,
msg,
)
def publish(self):
self.publish_to_user()
......@@ -362,12 +331,6 @@ class NewDeployment(models.Model):
self.save()
def __str__(self):
if self.service is not None:
return 'SVC-Dep: ({}:{})#{}'.format(
self.service,
self.user,
self.id,
)
return 'VO-Dep: ({}:{})#{}'.format(
self.group,
self.user,
......
......@@ -41,7 +41,6 @@ class UserSerializer(serializers.ModelSerializer):
class NewDeploymentSerializer(serializers.ModelSerializer):
user = UserSerializer()
service = ServiceSerializer()
group = GroupSerializer()
credentials = CredentialSerializer
......@@ -50,7 +49,6 @@ class NewDeploymentSerializer(serializers.ModelSerializer):
fields = [
'state_target',
'id',
'service',
'group',
'user',
'credentials',
......
......@@ -55,7 +55,6 @@ class NewDeploymentStateItemSerializer(serializers.ModelSerializer):
class NewDeploymentSerializer(serializers.ModelSerializer):
sites = SiteSerializer(many=True)
service = ServiceSerializer()
services = ServiceSerializer(many=True)
state_items = NewDeploymentStateItemSerializer(many=True)
......@@ -63,7 +62,6 @@ class NewDeploymentSerializer(serializers.ModelSerializer):
model = models.NewDeployment
fields = [
'state_target',
'service',
'services',
'group',
'id',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment