Skip to content

Instantly share code, notes, and snippets.

@charettes
charettes / generate.py
Created December 20, 2012 20:31
Django ticket #19482 localflavor apps locales
#!/usr/bin/env python
from __future__ import unicode_literals
import os
import re
import shutil
from subprocess import Popen
from django.contrib import localflavor
import polib
from polib import POEntry
@charettes
charettes / qs.py
Created February 5, 2013 21:35
Django #15363
def deprecated_get_query_set(cls):
def get_query_set(self, *args, **kwargs):
self.trace.append("%s.get_query_set" % cls.__name__)
return cls.get_queryset(self, *args, **kwargs)
cls.get_query_set = get_query_set
# Account for already defined __getattribute__
getattribute = getattr(cls, '__getattribute__')
def __getattribute__(self, name):
attribute = getattribute(self, name)
if name == 'get_queryset':
class MyManagerBase(Manager.__class__):
pass
class MyManager(Manager):
__metaclass__ = MyManagerBase
cls = self.__class__
if klass is None:
klass = cls
elif not not issubclass(klass, cls):
klass = type(klass.__name__, (klass, cls), {})
@charettes
charettes / gist:6296424
Created August 21, 2013 16:03
Registering mutant dynamic models to reversion.
from django.dispatch.dispatcher import receiver
from mutant.signals import mutable_class_prepared
import reversion
@receiver(mutable_class_prepared)
def register_reversion(sender, existing_model_class, **kwargs):
reversion.register(sender) # Register the newly created model class
if obsolete_class: # Unregister the obsolete model class
reversion.unregister(existing_model_class)
@charettes
charettes / test.py
Created December 23, 2015 23:12
Python 3.5 OrderedDict bug
import collections
import gc
import weakref
def create_reference():
class A(object):
pass
class B(A):
parents = collections.OrderedDict([
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)
# 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()
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(
#!/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