Skip to content

Instantly share code, notes, and snippets.

View beardedeagle's full-sized avatar
😒
Making the world functional.

Randy Thompson beardedeagle

😒
Making the world functional.
View GitHub Profile
@beardedeagle
beardedeagle / dehydrateMixin.py
Created April 26, 2015 05:12
dehydrate mixin to allow for field selection in Tastypie
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]
@beardedeagle
beardedeagle / full_dehydrateMixin.py
Created April 26, 2015 05:13
full_dehydrate mixin to allow for field selection in Tastypie
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']
@beardedeagle
beardedeagle / fieldSelectMixin
Created April 27, 2015 05:01
Field selection mixins for Tastypie (dehydrate, full_dehydrate and db level filter)
###################################################################
# 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')
@beardedeagle
beardedeagle / dummy-web-server.py
Created December 27, 2018 21:26 — forked from bradmontgomery/dummy-web-server.py
a minimal http server in python. Responds to GET, HEAD, POST requests, but will fail on anything else.
#!/usr/bin/env python
"""
Very simple HTTP server in python.
Usage::
./dummy-web-server.py [<port>]
Send a GET request::
curl http://localhost