Skip to content

Instantly share code, notes, and snippets.

Tom Christie tomchristie

Block or report user

Report or block tomchristie

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
View count.py
# http://www.data.parliament.uk/dataset/general-election-2015
import tablib
coalition_parties = ('Lab', 'LD', 'Green')
factor = 1.0
data = tablib.Dataset()
data.csv = open('../Desktop/hocl-ge2015-results-full.csv', 'r').read()
View REST framework roadmap.md
  • Schema & hypermedia support.
  • Better API documentation options.
  • Client libraries for range of languages.
  • Mature authentication defaults.
  • Faster time-to-production.
  • Performance & monitoring.
  • Debugging tools.
  • Realtime API support & documentation.
  • Highlighting & supporting third party packages.
  • Beta release versions & reducing bus factor.
View client.py
response = requests.get('http://api.example.com')
content_type = response.headers.get('content-type')
codec = coreapi.negotiate_decoder(content_type, decoders=decoders)
doc = codec.load(response.content)
.
View server.py
doc = Document(
url='/',
title='Notes',
content={
'notes': [
Document(
url='/123/',
title='Note',
content={
'description': 'Write the talk',
View fields.py
class CountryCodeField(serializers.Field):
codes = {'US': 45, 'AU': 12}
def to_internal_value(self, value):
# make sure it is a string
if type(value) is not str:
raise ValidationError('`value` must be a string, you sent type %s' % type(value))
# check length
if len(value) != 2:
View how-to-communicate.md

How to communicate

Exploring the fundamentals of how we build networked application interfaces.

What problems are we running into building Web APIs today? How can we best take advantage of Django's upcoming channels work to build realtime systems? What are Django's strengths in the changing API landscape, and how can it stay relevant?

  • REST - Taking a look at the pain points.
  • GraphQL - Why it exists, and what it could mean for the future.
  • Realtime - How we can build realtime interfaces in a more structured way.
  • Hypermedia - Why it hasn't yet lived up to its promises, and how it still might.
View serializers.py
class InvoiceList(ManyRelatedField):
def __init__(self):
child = InvoiceSerializer()
super(InvoiceList, self).__init__()
def to_representation(self, iterable):
request = self.parent.context['request']
return [
self.child_relation.to_representation(value)
for value in iterable.filter(user=request.user)
View gist:73a5c3a5eda6325e2f51
* REST framework 0.x - The top branch is the framework. Red branch to the left is docs. Bottom is example projects.
* Big pause - This'd be when my first son was born. Had my hands full.
* You can see when version 2.0 arrives as there's a flurry of activity - the code examples disappear and the docs get loads of work instead.
* During 2.x the tests move out of the package itself, causing another branch off of the center.
* You can tell when version 3.0 arrives, as a whole bunch of blue sponsor images appear in the red docs branch.
* The templated HTML rendering results in three sets of small purple branchs in the main framework, corresponding to vertical, horizontal and inline style templates.
* The big white flower is all the supported languages as we add internationalization to the project.
View github_pagination_style.py
def _get_displayed_page_numbers(current, final):
"""
This utility function determines a list of page numbers to display, based
on the same pagination display style that GitHub use in their issue list pages.
This gives us a nice contextually relevant set of page numbers to display.
For example:
current=14, final=16 -> [1, 2, None, 12, 13, 14, 15, 16]
current=2, final=16 -> [1, 2, 3, 4, 5, None, 15, 16]
View gist:7b552eace0ba5129999c
currency_serializer = CurrencySerializer(Currency.objects.all(), many=True)
service_serializer = ServiceModuleMinSerializer(ServiceModule.objects.all(), many=True)
return Response({
'currencies': currency_serializer.data,
'services': service_serializer.data
})
You can’t perform that action at this time.