summaryrefslogtreecommitdiff
path: root/horizon/browsers
diff options
context:
space:
mode:
authorGabriel Hurley <gabriel@strikeawe.com>2012-08-12 21:27:21 -0700
committerGabriel Hurley <gabriel@strikeawe.com>2012-08-13 16:48:06 -0700
commit801c2321bfd1a0036148e5f4d8b3a8c0674fe00d (patch)
tree58eabdd53e9a4df0d3d528b1979f7e39cd79c979 /horizon/browsers
parentee17b1588ba265666ef716401ab39f53e4a9464e (diff)
downloadhorizon-801c2321bfd1a0036148e5f4d8b3a8c0674fe00d.tar.gz
Switch to use python-swiftclient instead of cloudfiles.
This patch also resolves some thread-safety problems with when the browser and associated tables are constructed and where the request and data caches are stored on the table. Also includes stylistic and UX enhancments to the swift ResourceBrowser subclass. Implements blueprint swiftclient. Change-Id: I578277ff158b293ee50860528b069dc20e2136a9
Diffstat (limited to 'horizon/browsers')
-rw-r--r--horizon/browsers/base.py44
-rw-r--r--horizon/browsers/views.py33
2 files changed, 33 insertions, 44 deletions
diff --git a/horizon/browsers/base.py b/horizon/browsers/base.py
index 635cdc3c4..e4a897920 100644
--- a/horizon/browsers/base.py
+++ b/horizon/browsers/base.py
@@ -15,6 +15,7 @@
# under the License.
from django import template
+from django.utils.translation import ugettext_lazy as _
from horizon.tables import DataTable
from horizon.utils import html
@@ -32,6 +33,7 @@ class ResourceBrowser(html.HTMLElement):
A more verbose name for the browser meant for display purposes.
.. attribute:: navigation_table_class
+
This table displays data on the left side of the browser.
Set the ``navigation_table_class`` attribute with
the desired :class:`~horizon.tables.DataTable` class.
@@ -39,6 +41,7 @@ class ResourceBrowser(html.HTMLElement):
``"navigation"``.
.. attribute:: content_table_class
+
This table displays data on the right side of the browser.
Set the ``content_table_class`` attribute with
the desired :class:`~horizon.tables.DataTable` class.
@@ -59,44 +62,35 @@ class ResourceBrowser(html.HTMLElement):
verbose_name = None
navigation_table_class = None
content_table_class = None
+ navigable_item_name = _("Navigation Item")
template = "horizon/common/_resource_browser.html"
context_var_name = "browser"
- def __init__(self, request, tables=None, attrs=None,
- **kwargs):
+ def __init__(self, request, tables_dict=None, attrs=None, **kwargs):
super(ResourceBrowser, self).__init__()
- self.name = getattr(self, "name", self.__class__.__name__)
- self.verbose_name = getattr(self, "verbose_name", self.name.title())
+ self.name = self.name or self.__class__.__name__
+ self.verbose_name = self.verbose_name or self.name.title()
self.request = request
self.attrs.update(attrs or {})
-
- self.navigation_table_class = getattr(self, "navigation_table_class",
- None)
+ self.check_table_class(self.content_table_class, "content_table_class")
self.check_table_class(self.navigation_table_class,
"navigation_table_class")
-
- self.content_table_class = getattr(self, "content_table_class",
- None)
- self.check_table_class(self.content_table_class,
- "content_table_class")
-
- self.set_tables(tables)
+ if tables_dict:
+ self.set_tables(tables_dict)
def check_table_class(self, cls, attr_name):
- if not cls or not issubclass(cls, (DataTable, )):
- raise ValueError("You must specify a DataTable class for "
- "the %s attribute on %s "
+ if not cls or not issubclass(cls, DataTable):
+ raise ValueError("You must specify a DataTable subclass for "
+ "the %s attribute on %s."
% (attr_name, self.__class__.__name__))
def set_tables(self, tables):
- if tables:
- self.navigation_table = tables.get(self.navigation_table_class
- ._meta.name, None)
- self.content_table = tables.get(self.content_table_class
- ._meta.name, None)
- else:
- raise ValueError("There are no tables passed to class %s." %
- self.__class__.__name__)
+ """
+ Sets the table instances on the browser from a dictionary mapping table
+ names to table instances (as constructed by MultiTableView).
+ """
+ self.navigation_table = tables[self.navigation_table_class._meta.name]
+ self.content_table = tables[self.content_table_class._meta.name]
def render(self):
browser_template = template.loader.get_template(self.template)
diff --git a/horizon/browsers/views.py b/horizon/browsers/views.py
index 64e548a4b..933795e10 100644
--- a/horizon/browsers/views.py
+++ b/horizon/browsers/views.py
@@ -16,37 +16,32 @@
from collections import defaultdict
+from django.utils.translation import ugettext_lazy as _
+
from horizon.tables import MultiTableView
class ResourceBrowserView(MultiTableView):
browser_class = None
- data_method_pattern = "get_%s_data"
def __init__(self, *args, **kwargs):
- self.browser_class = getattr(self, "browser_class", None)
if not self.browser_class:
- raise ValueError("You must specify a ResourceBrowser class "
- " for the browser_class attribute on %s "
+ raise ValueError("You must specify a ResourceBrowser subclass "
+ "for the browser_class attribute on %s."
% self.__class__.__name__)
-
- self.navigation_table = self.browser_class.navigation_table_class
- self.content_table = self.browser_class.content_table_class
-
- # Check and set up the method the view would use to collect data
- self._data_methods = defaultdict(list)
- self.table_classes = (self.navigation_table, self.content_table)
- self.get_data_methods(self.table_classes, self._data_methods)
-
- self._tables = {}
- self._data = {}
+ self.table_classes = (self.browser_class.navigation_table_class,
+ self.browser_class.content_table_class)
+ super(ResourceBrowserView, self).__init__(*args, **kwargs)
+ self.navigation_selection = False
def get_browser(self):
if not hasattr(self, "browser"):
- tables = self.get_tables()
- self.browser = self.browser_class(self.request,
- tables,
- **self.kwargs)
+ self.browser = self.browser_class(self.request, **self.kwargs)
+ self.browser.set_tables(self.get_tables())
+ if not self.navigation_selection:
+ ct = self.browser.content_table
+ item = self.browser.navigable_item_name.lower()
+ ct._no_data_message = _("Select a %s to browse.") % item
return self.browser
def get_context_data(self, **kwargs):