This file contains hidden or 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
** content_gfk ** | |
E..E | |
====================================================================== | |
ERROR: test_build_related_resource (content_gfk.tests.fields.ContentTypeFieldTestCase) | |
---------------------------------------------------------------------- | |
Traceback (most recent call last): | |
File "/home/joshbohde/code/django-tastypie/tests/content_gfk/tests/fields.py", line 79, in test_build_related_resource | |
'/api/v1/quotes/%s/' % quote_1.pk | |
File "/home/joshbohde/code/django-tastypie/tastypie/contrib/contenttypes/fields.py", line 47, in build_related_resource | |
return super(GenericForeignKeyField, self).build_related_resource(*args, **kwargs) |
This file contains hidden or 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
class MyResource(ModelResource): | |
def full_dehydrate(self, bundle): | |
""" | |
Given a bundle with an object instance, extract the information from it | |
to populate the resource. | |
""" | |
requested = bundle.request.GET.get('fields', '') | |
if requested: | |
requested = set(requested_fields.split(',')) | set(self.fields.keys()) |
This file contains hidden or 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
from tastypie.fields import ToManyField | |
class ConditionalRelatedField(ToManyField): | |
truthy = set('1', 'true', 'yes') | |
def dehydrate_related(self, bundle, related_resource): | |
full = bundle.request.GET.get('include_entitites', '').lower() | |
if full not in self.truthy: | |
return related_resource.get_resource_uri(bundle) | |
else: |
This file contains hidden or 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
from tastypie import fields | |
from tastypie.resources import ModelResource | |
class LeagueResource(ModelResource): | |
registrations = fields.ToMany(LeagueRegistrationResource, attribute="leagueregistrations_set") | |
class Meta: | |
queryset = League.objects.all() | |
resource_name = 'league' |
This file contains hidden or 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
web: gunicorn -k gevent -b 0.0.0.0:$PORT app:app |
This file contains hidden or 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
# Using my `sometimes_return_data` branch | |
class MyResource(Resource): | |
def return_full_data(self, request): | |
truthy = ('true', '1') | |
return_data = request.META.get('RETURN_DATA', None) | |
return_data = return_datat or request.GET.get('return_data', None) | |
return return_data and (return_data.lower() in truthy) |
This file contains hidden or 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
.F...[29/Mar/2012 22:52:48] "GET /api/v1/geonotes/?polys__contains=%7B%22coordinates%22%3A%20%5B%5B-122.475233%2C%2037.768616999999999%5D%2C%20%5B-122.470416%2C%2037.767381999999998%5D%5D%2C%20%22type%22%3A%20%22MultiPoint%22%7D HTTP/1.1" 400 56 | |
F[29/Mar/2012 22:52:52] "GET /api/v1/geonotes/?points__within=%7B%22type%22%3A%20%22MultiPolygon%22%2C%20%22coordinates%22%3A%20%5B%5B%5B%5B-122.511067%2C%2037.771276%5D%2C%20%5B-122.510037%2C%2037.766391%5D%2C%20%5B-122.510037%2C%2037.763813%5D%2C%20%5B-122.456822%2C%2037.765848%5D%2C%20%5B-122.452960%2C%2037.766459%5D%2C%20%5B-122.454848%2C%2037.773990%5D%2C%20%5B-122.475362%2C%2037.773040%5D%2C%20%5B-122.511067%2C%2037.771276%5D%5D%5D%5D%7D HTTP/1.1" 400 56 | |
F[29/Mar/2012 22:52:55] "GET /api/v1/ HTTP/1.1" 200 171 | |
.[29/Mar/2012 22:52:59] "GET /api/v1/ HTTP/1.1" 200 292 | |
.[29/Mar/2012 22:53:02] "GET /api/v1/geonotes/ HTTP/1.1" 500 88 | |
FF[29/Mar/2012 22:53:03] "POST /api/v1/geonotes/ HTTP/1.1" 500 88 | |
[29/Mar/2012 22:53:03] "POST /api/v1/geonotes/ HTTP/1.1" 201 0 | |
[29/Mar/ |
This file contains hidden or 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
class UserResource(ModelResource): | |
api_key = fields.CharField('api_key__key', readonly=True) | |
class Meta: | |
queryset = User.objects.all() | |
authorization = Authorization() | |
resource_name = 'user' | |
# excludes = ['uuid','id','timestamp'] |
This file contains hidden or 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
class DefaultFilterResource(ModelResource): | |
def build_filters(self, filters=None): | |
base = super(DefaultFilterResource, self).build_filters(filters=filters) | |
if base: | |
return base | |
return { | |
'date__gt': datetime.now() - timedelta(days=1) | |
} | |
This file contains hidden or 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
class CinemaInfoResource(ModelResource): | |
class Meta: | |
object_class = CinemaInfo | |
def get_object_list(self): | |
return CinemaInfo.objects.all() |