Skip to content

Instantly share code, notes, and snippets.

View tomchristie's full-sized avatar
🌿

Tom Christie tomchristie

🌿
View GitHub Profile
{
"users": [
{
"organisations": [
{
"id": 456,
"role": "OWNER",
"editable": false,
"name": "Acme Org",
"permissions": ["SDFDS::SDFDS", "SDFDFS::SASDA"]
permissions = [
Permission(permission=permission, user=user, organisation=self)
for permission in ACCOUNT_PERMISSIONS
]

This is a test of stuff.

https://github.com/tomchristie/django-rest-framework/issues/1936
https://github.com/tomchristie/django-rest-framework/issues/1891
https://github.com/tomchristie/django-rest-framework/issues/1860
https://github.com/tomchristie/django-rest-framework/issues/1767
https://github.com/tomchristie/django-rest-framework/issues/1649
https://github.com/tomchristie/django-rest-framework/issues/1338
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
})
* 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.
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)
@tomchristie
tomchristie / unicode_json_renderer.py
Created September 20, 2011 16:58
JSONRenderer that doesn't force ascii
class UnicodeJSONRenderer(BaseRenderer):
"""
Renderer which serializes to JSON
"""
media_type = 'application/json'
format = 'json'
def render(self, obj=None, media_type=None):
"""
@tomchristie
tomchristie / renderers.py
Created September 21, 2011 07:52
Better API on DocumentingTemplateRenderer for escaping content.
class DocumentingTemplateRenderer(BaseRenderer):
...
escape_binary = True
def _escape_binary(content):
if self.escape_binary and not all(char in string.printable for char in content):
return '[%d bytes of binary content]' % len(content)
return content
...
@tomchristie
tomchristie / gist:1372740
Created November 17, 2011 08:59
Don't attempt to connect to the Selenium server at import; Wait until the first test is run.
class SeleniumTestCase(LiveServerTestCase):
_selenium_server_running = None
@property
def selenium_server_running(self):
"""
Determine if we can connect to the Selenium RC server.
Only evaluated once for performance reasons.
"""