Reviewed-by: Rodrigo Trujillo <rodrigo.trujillo(a)linux.vnet.ibm.com>
On 04/17/2014 06:04 PM, Aline Manera wrote:
From: Aline Manera <alinefm(a)br.ibm.com>
SimpleCollection is a collection of information that does not have a
Resource definition.
It can be useful in other situations so move it to a common place.
Signed-off-by: Aline Manera <alinefm(a)br.ibm.com>
---
src/kimchi/control/base.py | 17 +++++++++++++++++
src/kimchi/control/plugins.py | 19 ++-----------------
2 files changed, 19 insertions(+), 17 deletions(-)
diff --git a/src/kimchi/control/base.py b/src/kimchi/control/base.py
index 320239b..f8a5210 100644
--- a/src/kimchi/control/base.py
+++ b/src/kimchi/control/base.py
@@ -302,3 +302,20 @@ class AsyncCollection(Collection):
task = create(*args)
cherrypy.response.status = 202
return kimchi.template.render("Task", task)
+
+
+class SimpleCollection(Collection):
+ """
+ A Collection without Resource definition
+ """
+ def __init__(self, model):
+ super(SimpleCollection, self).__init__(model)
+
+ def get(self, filter_params):
+ res_list = []
+ try:
+ get_list = getattr(self.model, model_fn(self, 'get_list'))
+ res_list = get_list(*self.model_args)
+ except AttributeError:
+ pass
+ return kimchi.template.render(get_class_name(self), res_list)
diff --git a/src/kimchi/control/plugins.py b/src/kimchi/control/plugins.py
index 12c621e..6399e7c 100644
--- a/src/kimchi/control/plugins.py
+++ b/src/kimchi/control/plugins.py
@@ -17,26 +17,11 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-import kimchi.template
-from kimchi.control.base import Collection
-from kimchi.control.utils import get_class_name, model_fn
+from kimchi.control.base import SimpleCollection
from kimchi.control.utils import UrlSubNode
@UrlSubNode("plugins")
-class Plugins(Collection):
+class Plugins(SimpleCollection):
def __init__(self, model):
super(Plugins, self).__init__(model)
-
- @property
- def data(self):
- return self.info
-
- def get(self, filter_params):
- res_list = []
- try:
- get_list = getattr(self.model, model_fn(self, 'get_list'))
- res_list = get_list(*self.model_args)
- except AttributeError:
- pass
- return kimchi.template.render(get_class_name(self), res_list)