Permalink
Browse files

Changed ``get_multiple`` URLs to work without a trailing slash.

  • Loading branch information...
1 parent daca57a commit fd9f0581160a7dfc31cc55469fa4ea5368d19280 @jterrace jterrace committed with toastdriven Jun 14, 2012
Showing with 6 additions and 15 deletions.
  1. +0 −5 docs/settings.rst
  2. +1 −3 tastypie/resources.py
  3. +5 −7 tests/slashless/tests.py
View
@@ -78,11 +78,6 @@ integrating with other systems.
You must also have ``settings.APPEND_SLASH = False`` so that Django does not
emit HTTP 302 redirects.
-.. warning::
-
- This setting causes the ``Resource.get_multiple()`` method to fail. If you
- need this method, you will have to override the URLconf to meet your needs.
-
An example::
TASTYPIE_ALLOW_MISSING_SLASH = True
@@ -285,12 +285,10 @@ def base_urls(self):
"""
The standard URLs this ``Resource`` should respond to.
"""
- # Due to the way Django parses URLs, ``get_multiple`` won't work without
- # a trailing slash.
return [
url(r"^(?P<resource_name>%s)%s$" % (self._meta.resource_name, trailing_slash()), self.wrap_view('dispatch_list'), name="api_dispatch_list"),
url(r"^(?P<resource_name>%s)/schema%s$" % (self._meta.resource_name, trailing_slash()), self.wrap_view('get_schema'), name="api_get_schema"),
- url(r"^(?P<resource_name>%s)/set/(?P<%s_list>\w[\w/;-]*)/$" % (self._meta.resource_name, self._meta.detail_uri_name), self.wrap_view('get_multiple'), name="api_get_multiple"),
+ url(r"^(?P<resource_name>%s)/set/(?P<%s_list>\w[\w/;-]*)%s$" % (self._meta.resource_name, self._meta.detail_uri_name, trailing_slash()), self.wrap_view('get_multiple'), name="api_get_multiple"),
url(r"^(?P<resource_name>%s)/(?P<%s>\w[\w/-]*)%s$" % (self._meta.resource_name, self._meta.detail_uri_name, trailing_slash()), self.wrap_view('dispatch_detail'), name="api_dispatch_detail"),
]
@@ -38,11 +38,9 @@ def test_gets_without_trailing_slash(self):
self.assertEqual(len(deserialized), 9)
self.assertEqual(deserialized['title'], u'First Post!')
- # Due to the way Django parses URLs, ``get_multiple`` won't work without
- # a trailing slash. This will cause the ``get_detail`` to match
- # instead, resulting in a 500.
resp = self.client.get('/api/v1/notes/set/2;1', data={'format': 'json'})
- self.assertEqual(resp.status_code, 404)
- # This behavior is inconsistent across versions of Django. 1.3+ doesn't
- # seem to cause this error to be available.
- # self.assertEqual(json.loads(resp.content)["error_message"], "Invalid resource lookup data provided (mismatched type).")
+ self.assertEqual(resp.status_code, 200)
+ deserialized = json.loads(resp.content)
+ obj_ids = [o["id"] for o in deserialized["objects"]]
+ self.assertEqual(sorted(obj_ids), [1,2])
+

0 comments on commit fd9f058

Please sign in to comment.