Commit 3342a545 authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Refactor minor details

parent 2ec58c45
...@@ -39,19 +39,6 @@ def questionnaire_default(): ...@@ -39,19 +39,6 @@ def questionnaire_default():
def credential_default(): def credential_default():
return {} return {}
# takes a list of states
# return '<state>' if all states are equal to '<state>'
# else it returns 'mixed'
def analyze_states(states):
_state = ''
for state in states:
if _state == '':
_state = state
elif _state != state:
return 'mixed'
return _state
# singleton for simple configs # singleton for simple configs
# https://steelkiwi.com/blog/practical-application-singleton-design-pattern/ # https://steelkiwi.com/blog/practical-application-singleton-design-pattern/
...@@ -529,9 +516,12 @@ class Service(models.Model): ...@@ -529,9 +516,12 @@ class Service(models.Model):
# all group deployments have the same keys # all group deployments have the same keys
# TODO check that assumption # TODO check that assumption
deployment = user.deployments.filter(group=group) try:
if deployment.exists(): deployment = user.deployments.get(group=group)
deployment.first().service_added(self) deployment.service_added(self)
except Deployment.DoesNotExist:
LOGGER.error('Inconsistency in group deployment')
raise
class SSHPublicKey(models.Model): class SSHPublicKey(models.Model):
...@@ -817,7 +807,22 @@ class DeploymentState(models.Model): ...@@ -817,7 +807,22 @@ class DeploymentState(models.Model):
@property @property
def state(self): def state(self):
return analyze_states(self.states) if self.states:
_state = ''
for state in self.states:
if _state == '':
_state = state
elif _state != state:
return 'mixed'
return _state
# if we have no states we have nothing to do
return self.state_target
@property
def target_reached(self):
return self.state_target == self.state
@property @property
def service(self): def service(self):
...@@ -831,10 +836,6 @@ class DeploymentState(models.Model): ...@@ -831,10 +836,6 @@ class DeploymentState(models.Model):
def group(self): def group(self):
return self.deployment.group return self.deployment.group
@property
def target_reached(self):
return self.state_target == self.state
# get a state for a user/service. # get a state for a user/service.
# if it does not exist it is created # if it does not exist it is created
@classmethod @classmethod
......
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