From 8b28d601b53135f28e44a389f8131832ffd33e15 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Thu, 14 Dec 2023 10:22:25 +0100 Subject: [PATCH] Add support for multiple attributes of the same type Closes #149 --- strongMan/apps/pools/forms.py | 1 - strongMan/apps/pools/models/pools.py | 2 +- strongMan/apps/pools/views/AddHandler.py | 7 ++----- strongMan/apps/pools/views/EditHandler.py | 7 ++----- 4 files changed, 5 insertions(+), 12 deletions(-) diff --git a/strongMan/apps/pools/forms.py b/strongMan/apps/pools/forms.py index 3e89ae56..0eb9fb01 100644 --- a/strongMan/apps/pools/forms.py +++ b/strongMan/apps/pools/forms.py @@ -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() diff --git a/strongMan/apps/pools/models/pools.py b/strongMan/apps/pools/models/pools.py index b02f4a96..6550bcb5 100644 --- a/strongMan/apps/pools/models/pools.py +++ b/strongMan/apps/pools/models/pools.py @@ -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): diff --git a/strongMan/apps/pools/views/AddHandler.py b/strongMan/apps/pools/views/AddHandler.py index 70009df6..67c95318 100644 --- a/strongMan/apps/pools/views/AddHandler.py +++ b/strongMan/apps/pools/views/AddHandler.py @@ -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, @@ -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)) diff --git a/strongMan/apps/pools/views/EditHandler.py b/strongMan/apps/pools/views/EditHandler.py index a56fe365..34560d16 100644 --- a/strongMan/apps/pools/views/EditHandler.py +++ b/strongMan/apps/pools/views/EditHandler.py @@ -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: