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 gist:c5ed81a03808518d037e
{
"users": [
{
"organisations": [
{
"id": 456,
"role": "OWNER",
"editable": false,
"name": "Acme Org",
"permissions": ["SDFDS::SDFDS", "SDFDFS::SASDA"]
View gist:3fbf761fcbb9fe12a0d0
permissions = [
Permission(permission=permission, user=user, organisation=self)
for permission in ACCOUNT_PERMISSIONS
]
View gist:e191d680f357f104b561
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
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
})
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 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)
@tomchristie
tomchristie / unicode_json_renderer.py
Created Sep 20, 2011
JSONRenderer that doesn't force ascii
View unicode_json_renderer.py
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 Sep 21, 2011
Better API on DocumentingTemplateRenderer for escaping content.
View renderers.py
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 Nov 17, 2011
Don't attempt to connect to the Selenium server at import; Wait until the first test is run.
View gist:1372740
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.
"""
You can’t perform that action at this time.