From ff7725f05e8ca624e54d707f7c655e3d5c8b8888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Gro=C3=9F?= Date: Wed, 31 Oct 2012 15:30:01 +0100 Subject: [PATCH 01/42] added support for custom slug field and kwargs without subclassing HyperlinkedRelatedField and overwriting slug_url_kwarg and slug_field there is no possibility to use other fields / arguments. now you can do something like this: url(r'^users/(?P\w[\w-]*)$', UserInstance.as_view(), name='user-detail') class ProjectSerializer(serializers.HyperlinkedModelSerializer): created_by = serializers.HyperlinkedRelatedField(view_name='user-detail', slug_url_kwargs='username', slug_field='username') --- rest_framework/fields.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 1d6d760e3..63e159235 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -342,6 +342,8 @@ class HyperlinkedRelatedField(RelatedField): self.view_name = kwargs.pop('view_name') except: raise ValueError("Hyperlinked field requires 'view_name' kwarg") + self.slug_url_kwarg = kwargs.pop('slug_url_kwargs', self.slug_url_kwarg) + self.slug_field = kwargs.pop('slug_field', self.slug_field) self.format = kwargs.pop('format', None) super(HyperlinkedRelatedField, self).__init__(*args, **kwargs) From d3aedd5fb1d8c50e9b7047469163dc75ac3de022 Mon Sep 17 00:00:00 2001 From: Pavel Savchenko Date: Thu, 1 Nov 2012 15:00:22 +0200 Subject: [PATCH 02/42] return choices as unicode and not string, might as well have jsonp return unicode --- rest_framework/renderers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rest_framework/renderers.py b/rest_framework/renderers.py index 8dff0c773..fd6f9499c 100644 --- a/rest_framework/renderers.py +++ b/rest_framework/renderers.py @@ -100,7 +100,7 @@ class JSONPRenderer(JSONRenderer): callback = self.get_callback(renderer_context) json = super(JSONPRenderer, self).render(data, accepted_media_type, renderer_context) - return "%s(%s);" % (callback, json) + return u"%s(%s);" % (callback, json) class XMLRenderer(BaseRenderer): @@ -306,7 +306,7 @@ class BrowsableAPIRenderer(BaseRenderer): if getattr(widget, 'choices', None): choices = widget.choices if any([ident != desc for (ident, desc) in choices]): - choices = [(ident, "%s (%s)" % (desc, ident)) + choices = [(ident, u"%s (%s)" % (desc, ident)) for (ident, desc) in choices] widget.choices = choices kwargs['widget'] = widget From 9a0cc7c720d40f7d2408672c49a5d8bfb62c3979 Mon Sep 17 00:00:00 2001 From: Pavel Savchenko Date: Thu, 1 Nov 2012 15:06:11 +0200 Subject: [PATCH 03/42] since MultipleObjectBaseView was renamed MultipleObjectAPIView, it stands to reason to complete the renaming in docs and comments as well. --- docs/tutorial/3-class-based-views.md | 4 ++-- rest_framework/mixins.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/tutorial/3-class-based-views.md b/docs/tutorial/3-class-based-views.md index a31dccb2f..91ef40387 100644 --- a/docs/tutorial/3-class-based-views.md +++ b/docs/tutorial/3-class-based-views.md @@ -92,7 +92,7 @@ Let's take a look at how we can compose our views by using the mixin classes. class SnippetList(mixins.ListModelMixin, mixins.CreateModelMixin, - generics.MultipleObjectBaseView): + generics.MultipleObjectAPIView): model = Snippet serializer_class = SnippetSerializer @@ -102,7 +102,7 @@ Let's take a look at how we can compose our views by using the mixin classes. def post(self, request, *args, **kwargs): return self.create(request, *args, **kwargs) -We'll take a moment to examine exactly what's happening here - We're building our view using `MultipleObjectBaseView`, and adding in `ListModelMixin` and `CreateModelMixin`. +We'll take a moment to examine exactly what's happening here - We're building our view using `MultipleObjectAPIView`, and adding in `ListModelMixin` and `CreateModelMixin`. The base class provides the core functionality, and the mixin classes provide the `.list()` and `.create()` actions. We're then explicitly binding the `get` and `post` methods to the appropriate actions. Simple enough stuff so far. diff --git a/rest_framework/mixins.py b/rest_framework/mixins.py index 0f2a0d937..47e4edf72 100644 --- a/rest_framework/mixins.py +++ b/rest_framework/mixins.py @@ -29,7 +29,7 @@ class CreateModelMixin(object): class ListModelMixin(object): """ List a queryset. - Should be mixed in with `MultipleObjectBaseView`. + Should be mixed in with `MultipleObjectAPIView`. """ empty_error = u"Empty list and '%(class_name)s.allow_empty' is False." From 600289a8153eb70542551bab00d59fb7ff0065f0 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Thu, 1 Nov 2012 13:31:22 +0000 Subject: [PATCH 04/42] Added @ottoyiu. Thanks! --- docs/topics/credits.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/topics/credits.md b/docs/topics/credits.md index a74f79838..df0223410 100644 --- a/docs/topics/credits.md +++ b/docs/topics/credits.md @@ -52,6 +52,7 @@ The following people have helped make REST framework great. * Madis Väin - [madisvain] * Stephan Groß - [minddust] * Pavel Savchenko - [asfaltboy] +* Otto Yiu - [ottoyiu] Many thanks to everyone who's contributed to the project. @@ -139,3 +140,4 @@ To contact the author directly: [madisvain]: https://github.com/madisvain [minddust]: https://github.com/minddust [asfaltboy]: https://github.com/asfaltboy +[ottoyiu]: https://github.com/OttoYiu From d327c5f531b341ad980d20454211b02b87f34d0e Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Thu, 1 Nov 2012 23:04:13 +0000 Subject: [PATCH 05/42] Relational field support in browseable API. Add slug relational fields. Add quickstart. --- djangorestframework.egg-info/PKG-INFO | 19 ++++ djangorestframework.egg-info/SOURCES.txt | 86 ++++++++++++++ .../dependency_links.txt | 1 + djangorestframework.egg-info/top_level.txt | 7 ++ docs/index.md | 2 - docs/template.html | 2 +- docs/tutorial/quickstart.md | 9 +- rest_framework/fields.py | 107 +++++++++++++++++- rest_framework/renderers.py | 25 ++-- .../static/rest_framework/css/default.css | 7 ++ .../templates/rest_framework/base.html | 4 +- 11 files changed, 244 insertions(+), 25 deletions(-) create mode 100644 djangorestframework.egg-info/PKG-INFO create mode 100644 djangorestframework.egg-info/SOURCES.txt create mode 100644 djangorestframework.egg-info/dependency_links.txt create mode 100644 djangorestframework.egg-info/top_level.txt diff --git a/djangorestframework.egg-info/PKG-INFO b/djangorestframework.egg-info/PKG-INFO new file mode 100644 index 000000000..04eafbde9 --- /dev/null +++ b/djangorestframework.egg-info/PKG-INFO @@ -0,0 +1,19 @@ +Metadata-Version: 1.0 +Name: djangorestframework +Version: 2.0.0 +Summary: A lightweight REST framework for Django. +Home-page: http://django-rest-framework.org +Author: Tom Christie +Author-email: tom@tomchristie.com +License: BSD +Download-URL: http://pypi.python.org/pypi/rest_framework/ +Description: UNKNOWN +Platform: UNKNOWN +Classifier: Development Status :: 4 - Beta +Classifier: Environment :: Web Environment +Classifier: Framework :: Django +Classifier: Intended Audience :: Developers +Classifier: License :: OSI Approved :: BSD License +Classifier: Operating System :: OS Independent +Classifier: Programming Language :: Python +Classifier: Topic :: Internet :: WWW/HTTP diff --git a/djangorestframework.egg-info/SOURCES.txt b/djangorestframework.egg-info/SOURCES.txt new file mode 100644 index 000000000..298d1c333 --- /dev/null +++ b/djangorestframework.egg-info/SOURCES.txt @@ -0,0 +1,86 @@ +MANIFEST.in +setup.py +djangorestframework.egg-info/PKG-INFO +djangorestframework.egg-info/SOURCES.txt +djangorestframework.egg-info/dependency_links.txt +djangorestframework.egg-info/top_level.txt +rest_framework/__init__.py +rest_framework/authentication.py +rest_framework/compat.py +rest_framework/decorators.py +rest_framework/exceptions.py +rest_framework/fields.py +rest_framework/generics.py +rest_framework/mixins.py +rest_framework/models.py +rest_framework/negotiation.py +rest_framework/pagination.py +rest_framework/parsers.py +rest_framework/permissions.py +rest_framework/renderers.py +rest_framework/request.py +rest_framework/response.py +rest_framework/reverse.py +rest_framework/serializers.py +rest_framework/settings.py +rest_framework/status.py +rest_framework/throttling.py +rest_framework/urlpatterns.py +rest_framework/urls.py +rest_framework/views.py +rest_framework/authtoken/__init__.py +rest_framework/authtoken/models.py +rest_framework/authtoken/views.py +rest_framework/authtoken/migrations/0001_initial.py +rest_framework/authtoken/migrations/__init__.py +rest_framework/runtests/__init__.py +rest_framework/runtests/runcoverage.py +rest_framework/runtests/runtests.py +rest_framework/runtests/settings.py +rest_framework/runtests/urls.py +rest_framework/static/rest_framework/css/bootstrap-tweaks.css +rest_framework/static/rest_framework/css/bootstrap.min.css +rest_framework/static/rest_framework/css/default.css +rest_framework/static/rest_framework/css/prettify.css +rest_framework/static/rest_framework/img/glyphicons-halflings-white.png +rest_framework/static/rest_framework/img/glyphicons-halflings.png +rest_framework/static/rest_framework/img/grid.png +rest_framework/static/rest_framework/js/bootstrap.min.js +rest_framework/static/rest_framework/js/default.js +rest_framework/static/rest_framework/js/jquery-1.8.1-min.js +rest_framework/static/rest_framework/js/prettify-min.js +rest_framework/templates/rest_framework/api.html +rest_framework/templates/rest_framework/base.html +rest_framework/templates/rest_framework/login.html +rest_framework/templatetags/__init__.py +rest_framework/templatetags/rest_framework.py +rest_framework/tests/__init__.py +rest_framework/tests/authentication.py +rest_framework/tests/breadcrumbs.py +rest_framework/tests/decorators.py +rest_framework/tests/description.py +rest_framework/tests/files.py +rest_framework/tests/genericrelations.py +rest_framework/tests/generics.py +rest_framework/tests/htmlrenderer.py +rest_framework/tests/hyperlinkedserializers.py +rest_framework/tests/models.py +rest_framework/tests/modelviews.py +rest_framework/tests/negotiation.py +rest_framework/tests/pagination.py +rest_framework/tests/parsers.py +rest_framework/tests/renderers.py +rest_framework/tests/request.py +rest_framework/tests/response.py +rest_framework/tests/reverse.py +rest_framework/tests/serializer.py +rest_framework/tests/status.py +rest_framework/tests/testcases.py +rest_framework/tests/tests.py +rest_framework/tests/throttling.py +rest_framework/tests/validators.py +rest_framework/tests/views.py +rest_framework/utils/__init__.py +rest_framework/utils/breadcrumbs.py +rest_framework/utils/encoders.py +rest_framework/utils/mediatypes.py \ No newline at end of file diff --git a/djangorestframework.egg-info/dependency_links.txt b/djangorestframework.egg-info/dependency_links.txt new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/djangorestframework.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/djangorestframework.egg-info/top_level.txt b/djangorestframework.egg-info/top_level.txt new file mode 100644 index 000000000..7e18534d8 --- /dev/null +++ b/djangorestframework.egg-info/top_level.txt @@ -0,0 +1,7 @@ +rest_framework/authtoken +rest_framework/utils +rest_framework/tests +rest_framework/runtests +rest_framework/templatetags +rest_framework +rest_framework/authtoken/migrations diff --git a/docs/index.md b/docs/index.md index 75a1cf6e6..5e0868724 100644 --- a/docs/index.md +++ b/docs/index.md @@ -66,11 +66,9 @@ If you're intending to use the browseable API you'll want to add REST framework' Note that the URL path can be whatever you want, but you must include `rest_framework.urls` with the `rest_framework` namespace. - ## Tutorial diff --git a/docs/template.html b/docs/template.html index 94fc269f4..c428dff3a 100644 --- a/docs/template.html +++ b/docs/template.html @@ -53,7 +53,7 @@