Commit bbc68672 authored by Lukas Burgey's avatar Lukas Burgey
Browse files

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): ...@@ -149,6 +149,7 @@ class NewDeployment(models.Model):
on_delete=models.SET_NULL, on_delete=models.SET_NULL,
null=True, null=True,
) )
# member ship in this group the authorization for service usage
group = models.ForeignKey( group = models.ForeignKey(
Group, Group,
related_name='deployments', related_name='deployments',
...@@ -156,18 +157,11 @@ class NewDeployment(models.Model): ...@@ -156,18 +157,11 @@ class NewDeployment(models.Model):
null=True, null=True,
blank=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? # which state do we currently want to reach?
state_target = models.CharField( state_target = models.CharField(
max_length=50, max_length=50,
choices=STATE_CHOICES, choices=TARGET_CHOICES,
default=NOT_DEPLOYED, default=NOT_DEPLOYED,
) )
...@@ -201,9 +195,8 @@ class NewDeployment(models.Model): ...@@ -201,9 +195,8 @@ class NewDeployment(models.Model):
@property @property
def services(self): def services(self):
if self.group is not None: return self.group.services.all()
return self.group.services.all()
return [self.service]
@property @property
def sites(self): def sites(self):
...@@ -237,39 +230,21 @@ class NewDeployment(models.Model): ...@@ -237,39 +230,21 @@ class NewDeployment(models.Model):
).save() ).save()
@classmethod @classmethod
def get_deployment(cls, user, service=None, group=None, site=None): def get_deployment(cls, user, group=None, site=None):
if service is None and group is None: if group is None:
raise ValueError('get_deployment needs a service or a group') raise ValueError('get_deployment needs a service or a group')
try: try:
dep = None return cls.objects.get(
if service is not None: user=user,
dep = cls.objects.get( group=group,
user=user, )
service=service,
)
elif group is not None:
dep = cls.objects.get(
user=user,
group=group,
)
return dep
except cls.DoesNotExist: except cls.DoesNotExist:
deployment = None deployment = cls(
if service is not None and group is None: user=user,
deployment = cls( group=group,
user=user, )
service=service,
)
elif group is not None:
deployment = cls(
user=user,
group=group,
)
deployment.save() deployment.save()
deployment.create_state_items(site=site) deployment.create_state_items(site=site)
...@@ -323,31 +298,25 @@ class NewDeployment(models.Model): ...@@ -323,31 +298,25 @@ class NewDeployment(models.Model):
data = NewDeploymentSerializer(self).data data = NewDeploymentSerializer(self).data
msg = dumps(data) msg = dumps(data)
if self.service is not None: RabbitMQInstance.load().publish_by_group(
RabbitMQInstance.load().publish_by_service( self.group,
self.service, msg,
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')
# sends a state update via RabbitMQ / STOMP to the users webpage instance # sends a state update via RabbitMQ / STOMP to the users webpage instance
def publish_to_user(self): def publish_to_user(self):
if self.user is not None: if self.user is None:
# avoiding circular dependencies here raise ValueError('Unable to publish deployment to None user')
from .serializers.webpage import NewDeploymentSerializer
msg = dumps({ # avoiding circular dependencies here
'deployment': NewDeploymentSerializer(self).data, from .serializers.webpage import NewDeploymentSerializer
}) msg = dumps({
RabbitMQInstance.load().publish_to_user( 'deployment': NewDeploymentSerializer(self).data,
self.user, })
msg, RabbitMQInstance.load().publish_to_user(
) self.user,
msg,
)
def publish(self): def publish(self):
self.publish_to_user() self.publish_to_user()
...@@ -362,12 +331,6 @@ class NewDeployment(models.Model): ...@@ -362,12 +331,6 @@ class NewDeployment(models.Model):
self.save() self.save()
def __str__(self): def __str__(self):
if self.service is not None:
return 'SVC-Dep: ({}:{})#{}'.format(
self.service,
self.user,
self.id,
)
return 'VO-Dep: ({}:{})#{}'.format( return 'VO-Dep: ({}:{})#{}'.format(
self.group, self.group,
self.user, self.user,
......
...@@ -41,7 +41,6 @@ class UserSerializer(serializers.ModelSerializer): ...@@ -41,7 +41,6 @@ class UserSerializer(serializers.ModelSerializer):
class NewDeploymentSerializer(serializers.ModelSerializer): class NewDeploymentSerializer(serializers.ModelSerializer):
user = UserSerializer() user = UserSerializer()
service = ServiceSerializer()
group = GroupSerializer() group = GroupSerializer()
credentials = CredentialSerializer credentials = CredentialSerializer
...@@ -50,7 +49,6 @@ class NewDeploymentSerializer(serializers.ModelSerializer): ...@@ -50,7 +49,6 @@ class NewDeploymentSerializer(serializers.ModelSerializer):
fields = [ fields = [
'state_target', 'state_target',
'id', 'id',
'service',
'group', 'group',
'user', 'user',
'credentials', 'credentials',
......
...@@ -55,7 +55,6 @@ class NewDeploymentStateItemSerializer(serializers.ModelSerializer): ...@@ -55,7 +55,6 @@ class NewDeploymentStateItemSerializer(serializers.ModelSerializer):
class NewDeploymentSerializer(serializers.ModelSerializer): class NewDeploymentSerializer(serializers.ModelSerializer):
sites = SiteSerializer(many=True) sites = SiteSerializer(many=True)
service = ServiceSerializer()
services = ServiceSerializer(many=True) services = ServiceSerializer(many=True)
state_items = NewDeploymentStateItemSerializer(many=True) state_items = NewDeploymentStateItemSerializer(many=True)
...@@ -63,7 +62,6 @@ class NewDeploymentSerializer(serializers.ModelSerializer): ...@@ -63,7 +62,6 @@ class NewDeploymentSerializer(serializers.ModelSerializer):
model = models.NewDeployment model = models.NewDeployment
fields = [ fields = [
'state_target', 'state_target',
'service',
'services', 'services',
'group', 'group',
'id', '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