Skip to content

Instantly share code, notes, and snippets.

View mjtamlyn's full-sized avatar

Marc Tamlyn mjtamlyn

  • Photocrowd
  • Oxford
View GitHub Profile
@mjtamlyn
mjtamlyn / cursor.py
Last active December 2, 2021 08:42
Graphene pagination
import functools
from django.db.models import Prefetch, QuerySet
import attr
import graphene
from cursor_pagination import CursorPaginator
from graphene.utils.str_converters import to_snake_case
from graphql_relay import connection_from_list
@mjtamlyn
mjtamlyn / gcbv2.md
Last active April 12, 2019 18:55
Django generic class based views - version 2?

Django generic class based views - version 2?

Firstly, lets start with some full disclosure. I'm a big fan of class based views. Since they first came out, I've pretty much not written a functional view at all. I use the generic ones almost all the time, when they don't fit I build my own. I've written some websites with wonderfully complex heirarchy of composed features, using almost every individual mixin from Django and a few of my own. When I want to do some work on Django, my first port of call is normally the list of issues tagged as "generic views". I envisaged CCBV and then helped rewrite the official documentation. In

@mjtamlyn
mjtamlyn / settings.py
Created January 10, 2018 09:25
Logging config
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
'simple': {
'format': '%(levelname)s %(message)s'
},
# Extra imports
from rest_framework.authtoken.models import Token
from rest_framework.response import Response
from rest_framework import status
class Login(ObtainAuthToken):
serializer_class = MyAuthTokenSerializerWithExtraChecks
def post(self, request):
"""Override the post method to use custom serializer class."""
### Keybase proof
I hereby claim:
* I am mjtamlyn on github.
* I am mjtamlyn (https://keybase.io/mjtamlyn) on keybase.
* I have a public key whose fingerprint is 43B2 D38F 7D86 E0FD B442 D407 2D52 B74A 095C B09A
To claim this, I am signing this object:
@mjtamlyn
mjtamlyn / README.md
Last active May 25, 2016 15:15
Utilities for testing graphene APIs

Some prototype utilities for testing projects built with graphene.

Context

Simple utility class for creating context objects (e.g. context=Context(user=user))

Fragment

A wrapper class for strings to say "don't touch me". Can be used for arguments and as keys of the object passed to build_query.

GrapheneTestCase

A unittest.TestCase mixin with utility functions

diff --git a/django/core/mail/__init__.py b/django/core/mail/__init__.py
index 5a01adc..db88c94 100644
--- a/django/core/mail/__init__.py
+++ b/django/core/mail/__init__.py
@@ -3,6 +3,8 @@ Tools for sending email.
"""
from __future__ import unicode_literals
+from contextlib import contextmanager
+
diff --git a/django/forms/forms.py b/django/forms/forms.py
index bcc0d6d..46192ad 100644
--- a/django/forms/forms.py
+++ b/django/forms/forms.py
@@ -15,7 +15,7 @@ from django.forms.widgets import Media, MediaDefiningClass, TextInput, Textarea
from django.utils.html import conditional_escape, format_html
from django.utils.encoding import smart_text, force_text, python_2_unicode_compatible
from django.utils.safestring import mark_safe
-from django.utils.translation import ugettext as _
+from django.utils.translation import ugettext as _, ugettext_lazy
@mjtamlyn
mjtamlyn / gist:8304266
Created January 7, 2014 18:38
Django 1.7 on python 2.7 with the saferef patch
PYTHONPATH=.. ./runtests.py dispatch
Testing against Django installed in '/Users/marc/code/django/django'
Creating test database for alias 'default'...
Creating test database for alias 'other'...
.FFFFFFF...E
======================================================================
ERROR: dispatch.tests.test_saferef (unittest.loader.ModuleImportFailure)
----------------------------------------------------------------------
ImportError: Failed to import test module: dispatch.tests.test_saferef
Traceback (most recent call last):
@mjtamlyn
mjtamlyn / apps.py
Created January 1, 2014 17:15
THIS MAKES ME SO HAPPY
from django import apps
from django.contrib import admin
class AdminConfig(apps.AppConfig):
name = 'django.contrib.admin'
def ready(self):
admin.autodiscover()