From 25bd6d1d4b7a85279047ab8e35f6faee0bc10a1a Mon Sep 17 00:00:00 2001 From: "S. Andrew Sheppard" Date: Mon, 23 Dec 2013 22:27:40 -0600 Subject: [PATCH 1/6] can't save genericrelations via nested serializers in django 1.6 --- rest_framework/tests/test_genericrelations.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/rest_framework/tests/test_genericrelations.py b/rest_framework/tests/test_genericrelations.py index c38bfb9f3..2d3413444 100644 --- a/rest_framework/tests/test_genericrelations.py +++ b/rest_framework/tests/test_genericrelations.py @@ -69,6 +69,35 @@ class TestGenericRelations(TestCase): } self.assertEqual(serializer.data, expected) + def test_generic_nested_relation(self): + """ + Test saving a GenericRelation field via a nested serializer. + """ + + class TagSerializer(serializers.ModelSerializer): + class Meta: + model = Tag + exclude = ('content_type', 'object_id') + + class BookmarkSerializer(serializers.ModelSerializer): + tags = TagSerializer() + + class Meta: + model = Bookmark + exclude = ('id',) + + data = { + 'url': 'https://docs.djangoproject.com/', + 'tags': [ + {'tag': 'contenttypes'}, + {'tag': 'genericrelations'}, + ] + } + serializer = BookmarkSerializer(data=data) + self.assertTrue(serializer.is_valid()) + serializer.save() + self.assertEqual(serializer.object.tags.count(), 2) + def test_generic_fk(self): """ Test a relationship that spans a GenericForeignKey field. From d30ce2575c6b3901f15eb96eeaf66cc65e1d298b Mon Sep 17 00:00:00 2001 From: "S. Andrew Sheppard" Date: Mon, 23 Dec 2013 22:31:31 -0600 Subject: [PATCH 2/6] fix for genericrelation saving --- rest_framework/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index 8351b3df6..c0c810ab9 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -894,7 +894,7 @@ class ModelSerializer(Serializer): m2m_data[field_name] = attrs.pop(field_name) # Forward m2m relations - for field in meta.many_to_many: + for field in meta.many_to_many + meta.virtual_fields: if field.name in attrs: m2m_data[field.name] = attrs.pop(field.name) From 0672d6de6e47ba0269a58ad0da3cc7ff4c82908e Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Thu, 2 Jan 2014 16:46:57 -0500 Subject: [PATCH 3/6] Fix bugfix note This fixes a bugfix note that was added because of #1293, which pointed out that a change in a bugfix [1] broke backwards compatibility. The bugfix did not work as expected because a variable was quoted when it should not have been. This removes the quotes around the variable, which brings back the expected functionality. --- docs/topics/release-notes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/topics/release-notes.md b/docs/topics/release-notes.md index b09bd0bea..ca966d20e 100644 --- a/docs/topics/release-notes.md +++ b/docs/topics/release-notes.md @@ -98,7 +98,7 @@ You can determine your currently installed version using `pip freeze`: class DisablePaginationMixin(object): def get_paginate_by(self, queryset=None): - if self.request.QUERY_PARAMS['self.paginate_by_param'] == '0': + if self.request.QUERY_PARAMS[self.paginate_by_param] == '0': return None return super(DisablePaginationMixin, self).get_paginate_by(queryset) From e032bad1a7c1f9ad2d9c591617ea92b2e802d7e5 Mon Sep 17 00:00:00 2001 From: Paul Melnikow Date: Thu, 2 Jan 2014 16:54:06 -0500 Subject: [PATCH 4/6] FIx link to tox --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e0544a479..a7aa6fc40 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -67,7 +67,7 @@ To run the tests, clone the repository, and then: # Run the tests rest_framework/runtests/runtests.py -You can also use the excellent `[tox][tox]` testing tool to run the tests against all supported versions of Python and Django. Install `tox` globally, and then simply run: +You can also use the excellent [`tox`][tox] testing tool to run the tests against all supported versions of Python and Django. Install `tox` globally, and then simply run: tox From e020c51b44b9acecdb01cc90f2d6da977ba5ea0f Mon Sep 17 00:00:00 2001 From: Steven Cummings Date: Thu, 2 Jan 2014 17:18:08 -0600 Subject: [PATCH 5/6] FIX BaseSerializer.from_native has an altered signature * base classes define it with one parameter * BaseSerializer currently defines a second parameter, which we make optional here for method-dispatch passivity --- rest_framework/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index c0c810ab9..b22ca5783 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -331,7 +331,7 @@ class BaseSerializer(WritableField): return ret - def from_native(self, data, files): + def from_native(self, data, files=None): """ Deserialize primitives -> objects. """ From 442916b9649baaf305ff094fe05f026ad04c7818 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Fri, 3 Jan 2014 13:24:52 +0000 Subject: [PATCH 6/6] Link to BrightAPI, and remove ad except from frontpage --- docs/template.html | 23 ++--------------------- mkdocs.py | 6 ++++++ 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/docs/template.html b/docs/template.html index c065237a5..a397d067b 100644 --- a/docs/template.html +++ b/docs/template.html @@ -170,31 +170,12 @@ + - - diff --git a/mkdocs.py b/mkdocs.py index 09c9dcc67..92679a21e 100755 --- a/mkdocs.py +++ b/mkdocs.py @@ -161,6 +161,12 @@ for (dirpath, dirnames, filenames) in os.walk(docs_dir): output = output.replace('{{ page_id }}', filename[:-3]) output = output.replace('{{ canonical_url }}', canonical_url) + if filename =='index.md': + output = output.replace('{{ ad_block }}', """

The team behind REST framework is launching a new API service.

+

If you want to be first in line when we start issuing invitations, please sign up here.

""") + else: + output = output.replace('{{ ad_block }}', '') + if prev_url: output = output.replace('{{ prev_url }}', prev_url) output = output.replace('{{ prev_url_disabled }}', '')