From cc87269b4a8f254fb3c550d98a77064f661b8f7b Mon Sep 17 00:00:00 2001 From: Solly Ross Date: Fri, 24 May 2013 12:00:19 -0400 Subject: [PATCH] Adds methods for [] & len into LazyURLPattern The Django 404 page currently depends on being able to call len() and index LazyURLPattern. However, the special methods for doing this (__len__() and __getitem__()) are not forwarded to the object wrapped by SimpleLazyObject by default. Thus, methods to foward these special methods to the wrapped object have been implemented in LazyURLPattern. Fixes: bug 1183578 Change-Id: I133e97ed66180fe78cfe1b7fd9c86bac4171a994 --- horizon/base.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/horizon/base.py b/horizon/base.py index bc2f37e28..d37885257 100644 --- a/horizon/base.py +++ b/horizon/base.py @@ -561,6 +561,16 @@ class LazyURLPattern(SimpleLazyObject): self._setup() return reversed(self._wrapped) + def __len__(self): + if self._wrapped is empty: + self._setup() + return len(self._wrapped) + + def __getitem__(self, idx): + if self._wrapped is empty: + self._setup() + return self._wrapped[idx] + class Site(Registry, HorizonComponent): """ The overarching class which encompasses all dashboards and panels. """