Commit f8c0b4f3 authored by Lukas Burgey's avatar Lukas Burgey

Add answers field to DeploymentState

Also changes the defaults of questionnaire and answers.
parent f9198a2e
# Generated by Django 2.1.4 on 2018-12-15 23:33
from django.db import migrations
import django_mysql.models
class Migration(migrations.Migration):
dependencies = [
('backend', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='deploymentstate',
name='answers',
field=django_mysql.models.JSONField(blank=True, default=dict, null=True),
),
migrations.AlterField(
model_name='deploymentstate',
name='questionnaire',
field=django_mysql.models.JSONField(blank=True, default=dict, null=True),
),
]
......@@ -44,6 +44,10 @@ def questionnaire_default():
return {}
def answers_default():
return {}
def credential_default():
return {}
......@@ -399,7 +403,12 @@ class DeploymentState(models.Model):
# questions for the user (needed for deployment
questionnaire = JSONField(
default=questionnaire_default,
null=True,
blank=True,
)
# the users answers for the questionnaire
answers = JSONField(
null=True,
blank=True,
)
......@@ -661,6 +670,7 @@ class DeploymentState(models.Model):
if credential_states is not None:
self.client_credential_states(credential_states)
questionnaire = output.get('questionnaire', None)
self.message = output.get('message', '')
# update values
......@@ -671,11 +681,18 @@ class DeploymentState(models.Model):
elif state == NOT_DEPLOYED:
# reset credentials and questionnaire
self._reset()
self.save()
elif state == QUESTIONNAIRE:
self.questionnaire = output.get('questionnaire', {})
self.save()
elif state == QUESTIONNAIRE and questionnaire is not None:
self.questionnaire = questionnaire
if self.state != QUESTIONNAIRE and self.answers is not None:
# just republish the answers
self._hacked_answer_publish()
elif self.state == QUESTIONNAIRE:
# the republished answers are wrong
# we need new answers from the user
pass
elif state == REJECTED:
pass
elif state == FAILED:
......@@ -705,7 +722,6 @@ class DeploymentState(models.Model):
# resets all client sent values
def _reset(self):
self.credentials = credential_default()
self.questionnaire = questionnaire_default()
self.message = ''
def _assure_credential_states_exist(self):
......@@ -755,6 +771,21 @@ class DeploymentState(models.Model):
for deployment in self.deployments.filter(state_target=self.state_target):
deployment.publish_to_client()
def _hacked_answer_publish(self):
# hack from hell:
# we have deploy the answers.
# so we act like this DeploymentState is a ServiceDeployment
# what could go wrong??
from .serializers.clients import DeploymentStateSerializer
msg = dumps(DeploymentStateSerializer(self).data)
from .brokers import RabbitMQInstance
RabbitMQInstance.load().publish(
self,
msg,
)
def msg(self, msg):
return ' {} - {}'.format(self, msg)
......
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