forked from cartwheelweb/packaginator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
38 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from django.core.urlresolvers import reverse | ||
from django.http import HttpResponse | ||
|
||
from tastypie.api import Api as TastyPieApi | ||
from tastypie.serializers import Serializer | ||
from tastypie.utils.mime import build_content_type | ||
|
||
class Api(TastyPieApi): | ||
|
||
def top_level(self, request, api_name=None): | ||
""" | ||
A view that returns a serialized list of all resources registers | ||
to the ``Api``. Useful for discovery. | ||
""" | ||
serializer = Serializer() | ||
available_resources = {} | ||
|
||
if api_name is None: | ||
api_name = self.api_name | ||
|
||
for name in sorted(self._registry.keys()): | ||
available_resources[name] = reverse("api_dispatch_list", kwargs={ | ||
'api_name': api_name, | ||
'resource_name': name, | ||
}) | ||
|
||
desired_format = "application/json" | ||
serialized = serializer.serialize(available_resources, desired_format) | ||
return HttpResponse(content=serialized, content_type=build_content_type(desired_format)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters