diff --git a/leaflet/__init__.py b/leaflet/__init__.py index 10e4a8b..944735e 100644 --- a/leaflet/__init__.py +++ b/leaflet/__init__.py @@ -6,15 +6,15 @@ from django.core.exceptions import ImproperlyConfigured from django.templatetags.static import static from django.utils.translation import gettext_lazy as _ +from django.utils.functional import lazy -from .utils import memoized_lazy_function, ListWithLazyItems, ListWithLazyItemsRawIterator +from .utils import ListWithLazyItems, ListWithLazyItemsRawIterator DEFAULT_TILES = [(_('OSM'), '//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', '© OpenStreetMap contributors')] LEAFLET_CONFIG = getattr(settings, 'LEAFLET_CONFIG', {}) - app_settings = dict({ 'TILES': DEFAULT_TILES, 'OVERLAYS': [], @@ -168,7 +168,7 @@ def _normalize_plugins_config(): pass else: # pass relative URL through django.contrib.staticfiles - urls[i] = memoized_lazy_function(static, url) # lazy variant of `static(url)` + urls[i] = lazy(static, str)(url) # lazy variant of `static(url)` urls = ListWithLazyItems(urls) plugin_dict[resource_type] = urls diff --git a/leaflet/utils.py b/leaflet/utils.py index c694824..7f38b4d 100644 --- a/leaflet/utils.py +++ b/leaflet/utils.py @@ -3,30 +3,6 @@ from django.utils.functional import Promise -class memoized_lazy_function(Promise): - """ - Represents a lazy value which is calculated by calling - func(*args, **kwargs) and then is memoized. - - >>> f = memoized_lazy_function(lambda a: print('.') or a, 'hello') - >>> f() - . - 'hello' - >>> f() - 'hello' - """ - - def __init__(self, func, *args, **kwargs): - self._func = func - self._args = args - self._kwargs = kwargs - - def __call__(self): - if not hasattr(self, '_result'): - self._result = self._func(*self._args, **self._kwargs) - return self._result - - class ListWithLazyItems(Sequence): """ Mimics a lazy list. @@ -45,13 +21,13 @@ def __init__(self, iterable=()): def __iter__(self): for item in self._list: - yield self._resolve_lazy_item(item) + yield item def __len__(self): return len(self._list) def __getitem__(self, index): - return self._resolve_lazy_item(self._list[index]) + return self._list[index] def extend(self, iterable): if isinstance(iterable, ListWithLazyItems): @@ -68,13 +44,6 @@ def __add__(self, iterable): lazy_list.extend(iterable) return lazy_list - @classmethod - def _resolve_lazy_item(cls, item): - if cls.is_lazy_item(item): - item = item() - - return item - @classmethod def is_lazy_item(cls, item): return isinstance(item, Promise)