mirror of
https://github.com/pinry/pinry.git
synced 2025-11-14 09:05:41 +01:00
Allow filtering pins over submitter.username
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
from tastypie import fields
|
from tastypie import fields
|
||||||
from tastypie.authorization import DjangoAuthorization
|
from tastypie.authorization import DjangoAuthorization
|
||||||
|
from tastypie.constants import ALL, ALL_WITH_RELATIONS
|
||||||
from tastypie.exceptions import Unauthorized
|
from tastypie.exceptions import Unauthorized
|
||||||
from tastypie.resources import ModelResource
|
from tastypie.resources import ModelResource
|
||||||
from django_images.models import Thumbnail
|
from django_images.models import Thumbnail
|
||||||
@@ -47,6 +48,9 @@ class UserResource(ModelResource):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
list_allowed_methods = ['get']
|
list_allowed_methods = ['get']
|
||||||
|
filtering = {
|
||||||
|
'username': ALL
|
||||||
|
}
|
||||||
queryset = User.objects.all()
|
queryset = User.objects.all()
|
||||||
resource_name = 'user'
|
resource_name = 'user'
|
||||||
fields = ['username']
|
fields = ['username']
|
||||||
@@ -114,6 +118,9 @@ class PinResource(ModelResource):
|
|||||||
class Meta:
|
class Meta:
|
||||||
fields = ['id', 'url', 'origin', 'description']
|
fields = ['id', 'url', 'origin', 'description']
|
||||||
ordering = ['id']
|
ordering = ['id']
|
||||||
|
filtering = {
|
||||||
|
'submitter': ALL_WITH_RELATIONS
|
||||||
|
}
|
||||||
queryset = Pin.objects.all()
|
queryset = Pin.objects.all()
|
||||||
resource_name = 'pin'
|
resource_name = 'pin'
|
||||||
include_resource_uri = False
|
include_resource_uri = False
|
||||||
|
|||||||
@@ -200,12 +200,17 @@ class PinResourceTest(ResourceTestCase):
|
|||||||
self.assertValidJSONResponse(response)
|
self.assertValidJSONResponse(response)
|
||||||
self.assertEqual(self.deserialize(response)['objects'][0]['id'], pin.id)
|
self.assertEqual(self.deserialize(response)['objects'][0]['id'], pin.id)
|
||||||
|
|
||||||
def test_get_list_json_filtered(self):
|
def test_get_list_json_filtered_by_tags(self):
|
||||||
tag = self.pin_1.tags.all()[0]
|
tag = self.pin_1.tags.all()[0]
|
||||||
response = self.api_client.get('/api/v1/pin/', format='json', data={'tag': tag})
|
response = self.api_client.get('/api/v1/pin/', format='json', data={'tag': tag})
|
||||||
self.assertValidJSONResponse(response)
|
self.assertValidJSONResponse(response)
|
||||||
self.assertEqual(self.deserialize(response)['objects'][0]['id'], self.pin_1.id)
|
self.assertEqual(self.deserialize(response)['objects'][0]['id'], self.pin_1.id)
|
||||||
|
|
||||||
|
def test_get_list_json_filtered_by_submitter(self):
|
||||||
|
response = self.api_client.get('/api/v1/pin/', format='json', data={'submitter__username': self.user.username})
|
||||||
|
self.assertValidJSONResponse(response)
|
||||||
|
self.assertEqual(self.deserialize(response)['objects'][0]['id'], self.pin_1.id)
|
||||||
|
|
||||||
def test_get_list_json(self):
|
def test_get_list_json(self):
|
||||||
user = User.objects.get(pk=1)
|
user = User.objects.get(pk=1)
|
||||||
image = Image.objects.get(pk=1)
|
image = Image.objects.get(pk=1)
|
||||||
|
|||||||
Reference in New Issue
Block a user