From 3eb6fe5ad691c032ac94d169d80676a870266e2c Mon Sep 17 00:00:00 2001 From: Craig Blaszczyk Date: Sun, 11 Dec 2011 16:39:17 +0000 Subject: [PATCH] small changes from pull request feedback --- djangorestframework/builtins.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/djangorestframework/builtins.py b/djangorestframework/builtins.py index b9257d1c6..385da0db8 100644 --- a/djangorestframework/builtins.py +++ b/djangorestframework/builtins.py @@ -1,4 +1,5 @@ from django.conf.urls.defaults import patterns, url, include +from collections import defaultdict class ApiEntry(object): """ @@ -35,17 +36,16 @@ class ApiEntry(object): ) return urlpatterns - + @property def urls(self): return self.get_urls(), 'api', self.namespace - urls = property(urls) class DjangoRestFrameworkApi(object): app_name = 'api' namespace = 'api' def __init__(self, *args, **kwargs): - self._registry = {} + self._registry = defaultdict(lambda: defaultdict(list)) super(DjangoRestFrameworkApi, self).__init__(*args, **kwargs) def register(self, view, resource, namespace=None, name=None): @@ -62,12 +62,6 @@ class DjangoRestFrameworkApi(object): name = resource.__name__.lower() resource.api_name = name - - if namespace not in self._registry: - self._registry[namespace] = {} - - if name not in self._registry[namespace]: - self._registry[namespace][name] = [] api_entry = ApiEntry(resource, view, name, namespace) self._registry[namespace][name].append(api_entry)