Skip to content

Instantly share code, notes, and snippets.

@charettes
charettes / alias_module.py
Created Feb 12, 2020
Allow module aliasing
View alias_module.py
from __future__ import unicode_literals
import re
import sys
from importlib import import_module
class _AliasLoader(object):
def __init__(self, alias, aliased):
self.alias = alias
@charettes
charettes / operation.py
Created Mar 28, 2019
import_model_operation.py
View operation.py
class ImportForeignModel(Operation):
"""Import a model from a foreign app to this one."""
def __init__(self, app_label, model_name):
self.app_label = app_label
self.model_name = model_name.lower()
def state_forwards(self, app_label, state):
imported_model_state = state.models[self.app_label, self.model_name].clone()
# Change the app label.
View addtrailingcommas.py
#!/usr/bin/env python
"""
This script assumes you have both flake8 and flake8-commas packages
installed in the Python environment you use to run this script.
"""
import subprocess
import sys
from collections import defaultdict
View tests-test_client_regress-tests.py.diff
diff --git a/tests/test_client_regress/tests.py b/tests/test_client_regress/tests.py
index b8d7c99..8c67a18 100644
--- a/tests/test_client_regress/tests.py
+++ b/tests/test_client_regress/tests.py
@@ -467,6 +467,10 @@ class AssertRedirectsTests(SimpleTestCase):
self.assertEqual(response.request.get('wsgi.url_scheme'), 'https')
self.assertEqual(response.request.get('SERVER_NAME'), 'otherserver')
self.assertEqual(response.request.get('SERVER_PORT'), '8443')
+ response = self.client.get('/redirect_other_host/', follow=False)
+ self.assertRedirects(
View test_models.py
# Add the common tests module as an application to allow its models
# table to be created even if they are not part of the common migations.
app_config = AppConfig.create(__package__)
app_config.label = 'common_tests'
app_config.import_models(apps.all_models[app_config.label])
apps.app_configs[app_config.label] = app_config
apps.clear_cache()
View allow_migrate_cascade.py
from django.db import router
from django.db.models import deletion
def ALLOW_MIGRATE_CASCADE(collector, field, sub_objs, using):
opts = sub_objs[0]._meta
if router.allow_migrate(using, opts.app_label, opts.model_name):
deletion.CASCADE(collector, field, sub_objs, using)
@charettes
charettes / test.py
Created Dec 23, 2015
Python 3.5 OrderedDict bug
View test.py
import collections
import gc
import weakref
def create_reference():
class A(object):
pass
class B(A):
parents = collections.OrderedDict([
View detect.patch
diff --git a/django/test/runner.py b/django/test/runner.py
index 1106c52..e053bd3 100644
--- a/django/test/runner.py
+++ b/django/test/runner.py
@@ -211,6 +211,27 @@ class DiscoverRunner(object):
result = self.run_suite(suite)
self.teardown_databases(old_config)
self.teardown_test_environment()
+ from itertools import groupby
+ def keyfunc(test):
View gist:abdad035dda9574f11d6
(django-sundial)simon@simon-laptop:~/workspace/django-sundial$ python setup.py bdist_wheel --universal
running bdist_wheel
running build
installing to build/bdist.linux-x86_64/wheel
running install
running install_egg_info
running egg_info
creating django_sundial.egg-info
writing requirements to django_sundial.egg-info/requires.txt
writing django_sundial.egg-info/PKG-INFO
View keybase.md

Keybase proof

I hereby claim:

  • I am charettes on github.
  • I am charettes (https://keybase.io/charettes) on keybase.
  • I have a public key whose fingerprint is 8557 62CE 0C47 C935 9480 44AA 72AF 89A0 B1B4 EDB3

To claim this, I am signing this object: