This file contains 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
#!/usr/bin/env python | |
""" | |
Very simple HTTP server in python. | |
Usage:: | |
./dummy-web-server.py [<port>] | |
Send a GET request:: | |
curl http://localhost |
This file contains 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
################################################################### | |
# mixin that utilizes dehydrate to implement field selection # | |
# Tested with python 2.7.5, django 1.8 and django-tastypie 0.12.1 # | |
################################################################### | |
class fieldSelectMixin(object): | |
""" | |
Mixin to allow field selection, dehydrate method. | |
""" | |
def dehydrate(self, bundle): | |
selectedFields = bundle.request.GET.get('fields') |
This file contains 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 fieldSelectMixin(object): | |
""" | |
Mixin to allow field selection. full_dehydrate method. | |
""" | |
def full_dehydrate(self, bundle, for_list=False): | |
""" | |
Given a bundle with an object instance, extract the information from it | |
to populate the resource. | |
""" | |
use_in = ['all', 'list' if for_list else 'detail'] |
This file contains 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 fieldSelectMixin(object): | |
""" | |
Mixin to allow field selection, dehydrate method. | |
""" | |
def dehydrate(self, bundle): | |
selectedFields = bundle.request.GET.get('fields') | |
if selectedFields: | |
selectedFields = selectedFields.split(',') | |
removedFields = [field for field in bundle.data.keys() if field not in selectedFields] |