Skip to content

Commit

Permalink
Add support for multiple attributes of the same type
Browse files Browse the repository at this point in the history
Closes #149
  • Loading branch information
tobiasbrunner committed Dec 14, 2023
1 parent 5fcf872 commit 8b28d60
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 12 deletions.
1 change: 0 additions & 1 deletion strongMan/apps/pools/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def update_pool(self, pool):
else:
pool.attribute = self.cleaned_data['attribute']
pool.attributevalues = self.cleaned_data['attributevalues']
pool.save()

def is_valid(self):
valid = super(AddOrEditForm, self).is_valid()
Expand Down
2 changes: 1 addition & 1 deletion strongMan/apps/pools/models/pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def dict(self):
elif self.attribute is None:
pools = {self.poolname: {'addrs': self.addresses}}
else:
pools = {self.poolname: {'addrs': self.addresses, self.attribute: [self.attributevalues]}}
pools = {self.poolname: {'addrs': self.addresses, self.attribute: self.attributevalues.split(',')}}
return pools

def __str__(self):
Expand Down
7 changes: 2 additions & 5 deletions strongMan/apps/pools/views/AddHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def handle(self):
'Can\'t add pool: Attribute values unclear for Attribute "None"')
return self._render(self.form)
pool = Pool(poolname=self.form.my_poolname, addresses=self.form.my_addresses)
vici_pool = {self.form.my_poolname: {'addrs': self.form.my_addresses}}
else:
if self.form.my_attributevalues == "":
messages.add_message(self.request, messages.ERROR,
Expand All @@ -55,13 +54,11 @@ def handle(self):
pool = Pool(poolname=self.form.my_poolname, addresses=self.form.my_addresses,
attribute=attr,
attributevalues=self.form.my_attributevalues)
vici_pool = {self.form.my_poolname: {'addrs': self.form.my_addresses,
attr: [self.form.my_attributevalues]}}
try:
pool.clean()
pool.save()
vici = ViciWrapper()
vici.load_pool(vici_pool)
vici.load_pool(pool.dict())
pool.save()

except ViciException as e:
messages.add_message(self.request, messages.ERROR, str(e))
Expand Down
7 changes: 2 additions & 5 deletions strongMan/apps/pools/views/EditHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,17 @@ def update_pool(self, vici):
messages.add_message(self.request, messages.ERROR,
'Won\'t update: Attribute values unclear for Attribute "None"')
return render(self.request, 'pools/edit.html', {"form": self.form})
vici_pool = {self.form.my_poolname: {'addrs': self.form.my_addresses}}

else:
if self.form.my_attributevalues == "":
messages.add_message(self.request, messages.ERROR,
'Won\'t update: Attribute values mandatory if attribute is set.')
return render(self.request, 'pools/edit.html', {"form": self.form})
vici_pool = {self.form.my_poolname: {'addrs': self.form.my_addresses,
self.form.my_attribute: [self.form.my_attributevalues]}}
msg = 'Successfully updated pool'

try:
vici.load_pool(vici_pool)
self.form.update_pool(self.pool)
self.pool.clean()
vici.load_pool(self.pool.dict())
self.pool.save()
messages.add_message(self.request, messages.SUCCESS, msg)
except ViciException as e:
Expand Down

0 comments on commit 8b28d60

Please sign in to comment.