aboutsummaryrefslogtreecommitdiffstats
path: root/src/dashboard/utils.py
diff options
context:
space:
mode:
authorParker Berberian <pberberian@iol.unh.edu>2020-03-16 17:54:09 +0000
committerGerrit Code Review <gerrit@opnfv.org>2020-03-16 17:54:09 +0000
commit0db3a84d9d9ed213983a517efd35c339537ef472 (patch)
treea6d7ac7ba2f2d70e18cb984bda4020c736082c62 /src/dashboard/utils.py
parent176ec9aacbc87e6077e8807c60f95a1ccbbc26e3 (diff)
parent064f145f218385a6401fa6be2ccbbc462e915c26 (diff)
Merge "Test resource templates now use the same lab as the image generated alongside it."
Diffstat (limited to 'src/dashboard/utils.py')
-rw-r--r--src/dashboard/utils.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/dashboard/utils.py b/src/dashboard/utils.py
new file mode 100644
index 0000000..3d63366
--- /dev/null
+++ b/src/dashboard/utils.py
@@ -0,0 +1,42 @@
+##############################################################################
+# Copyright (c) 2020 Parker Berberian and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+from django.core.exceptions import ObjectDoesNotExist
+
+
+class AbstractModelQuery():
+ """
+ This is a class made for querying abstract models.
+
+ This class is itself abstract. create subclasses to
+ query your own abstract models.
+ """
+
+ model_list = []
+
+ @classmethod
+ def filter(cls, *args, **kwargs):
+ """
+ Query all concrete model classes.
+
+ Iterates over the model list and returns a list of all
+ matching models from the classes given.
+ Filter queries are given here as normal and are passed into the Django ORM
+ for each concrete model
+ """
+ result = []
+ for model in cls.model_list:
+ result += list(model.objects.filter(*args, **kwargs))
+
+ @classmethod
+ def get(cls, *args, **kwargs):
+ try:
+ return cls.filter(*args, **kwargs)[0]
+ except IndexError:
+ raise ObjectDoesNotExist()