Skip to content

Commit

Permalink
fixed DRF 3.3 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
MattBroach committed Nov 12, 2015
1 parent f40c5c1 commit 4ce5d1c
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 5 deletions.
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,13 @@ MANIFEST.in
*.rst
dist/
django_rest_multiple_models.egg-info/
setup.py

# Environment #
###############
setup.sh
Vagrantfile
.vagrant/
testproj/
manage.py
*swp
db.sqlite3
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ If you want to combine `MultipleModelAPIView`'s `list()` function with other vie

# Version Notes

* 1.2 -- Fixed a bug with the Browsable API when using Django Rest Framework >= 3.3

* 1.1 -- Added `get_queryList()` function to support creation of dynamic queryLists

* 1.0 -- initial release
Expand Down
31 changes: 28 additions & 3 deletions drf_multiple_model/tests.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from django.db import models
from django.test import TestCase
from django.test import TestCase, override_settings
from django.conf.urls import url

from rest_framework import serializers, status
from rest_framework import serializers, status, renderers
from rest_framework.test import APIRequestFactory
from rest_framework.test import APIClient

from drf_multiple_model.views import MultipleModelAPIView

Expand Down Expand Up @@ -51,6 +53,12 @@ class BasicTestView(MultipleModelAPIView):
queryList = ((Play.objects.all(),PlaySerializer),
(Poem.objects.filter(style="Sonnet"),PoemSerializer))

class TestBrowsableAPIView(MultipleModelAPIView):
renderer_classes = (renderers.BrowsableAPIRenderer,)

queryList = ((Play.objects.all(),PlaySerializer),
(Poem.objects.filter(style="Sonnet"),PoemSerializer))

# Testing label functionality
class LabelTestView(MultipleModelAPIView):
queryList = ((Play.objects.all(),PlaySerializer,'The Plays'),
Expand Down Expand Up @@ -109,8 +117,13 @@ def get_queryList(self):

return queryList

# Tests
# Fake URL Patterns for running tests
urlpatterns = [
url(r"^$",TestBrowsableAPIView.as_view()),
]

# Tests
@override_settings(ROOT_URLCONF=__name__)
class TestMMViews(TestCase):
def setUp(self):
Play.objects.bulk_create([
Expand Down Expand Up @@ -396,3 +409,15 @@ def test_dynamic_queryList(self):
]}
]);


def test_url_endpoint(self):
"""
DRF 3.3 broke the MultipleModelAPIView with a get_queryset call
This test is to replicate (and then fix) that problem
"""

client = APIClient()
response = client.get('/',format='api')

self.assertEqual(response.status_code, status.HTTP_200_OK)

5 changes: 4 additions & 1 deletion drf_multiple_model/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
from rest_framework.generics import GenericAPIView

class MultipleModelAPIView(MultipleModelMixin,GenericAPIView):
def get_queryset(self):
return

def get(self, request, *args, **kwargs):
return self.list(request, *args, **kwargs)
return self.list(request, *args, **kwargs)
35 changes: 35 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
from setuptools import setup

with open(os.path.join(os.path.dirname(__file__), 'PYPI_README.rst')) as readme:
README = readme.read()

# allow setup.py to be run from any path
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))

setup(
name='django-rest-multiple-models',
version='1.2',
packages=['drf_multiple_model'],
include_package_data=True,
license='MIT License',
description='Multiple model/queryset view (and mixin) for Django Rest Framework',
long_description=README,
url='https://github.com/Axiologue/DjangoRestMultipleModels',
author='Matt Broach',
author_email='go.for.dover@gmail.com',
classifiers=[
'Environment :: Web Environment',
'Framework :: Django',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
],
)

0 comments on commit 4ce5d1c

Please sign in to comment.