Skip to content

Instantly share code, notes, and snippets.

😒
Making the world functional

Randy Thompson beardedeagle

😒
Making the world functional
Block or report user

Report or block beardedeagle

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@beardedeagle
beardedeagle / dummy-web-server.py
Created Dec 27, 2018 — 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.
View dummy-web-server.py
#!/usr/bin/env python
"""
Very simple HTTP server in python.
Usage::
./dummy-web-server.py [<port>]
Send a GET request::
curl http://localhost
@beardedeagle
beardedeagle / fieldSelectMixin
Created Apr 27, 2015
Field selection mixins for Tastypie (dehydrate, full_dehydrate and db level filter)
View fieldSelectMixin
###################################################################
# 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 / full_dehydrateMixin.py
Created Apr 26, 2015
full_dehydrate mixin to allow for field selection in Tastypie
View full_dehydrateMixin.py
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 / dehydrateMixin.py
Created Apr 26, 2015
dehydrate mixin to allow for field selection in Tastypie
View dehydrateMixin.py
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]
You can’t perform that action at this time.