Skip to content

Instantly share code, notes, and snippets.

SERVE_MEDIA = DEBUG
LOGGING = {
"version": 1,
"disable_existing_loggers": True,
"handlers": {
"mail_admins": {
"level": "ERROR",
"class": "django.utils.log.AdminEmailHandler"
},
},
"loggers": {
from django.conf import settings
from django.db.models import get_apps, get_app
from django.utils import unittest
from django.test.simple import build_test, build_suite, reorder_suite
from django.test.simple import DjangoTestSuiteRunner
from django.test.testcases import TestCase
class ExclusionTestSuiteRunner(DjangoTestSuiteRunner):
@dstufft
dstufft / reusable.py
Created November 27, 2011 06:33
A Reusable Implementation of Multi Forms
# There are other ways of handling this of course. This could all go into a Formset.
# Another question is should we accept one form being submitted and the other not?
# This is just one possible implementation of a Multi Form Mixin that requires Both forms.
# You could adapt it to work for allowing processing of any forms by modifying the post method
# of MultiProcessFormView.
# In general I don't think a view like this is useful. More than one kind of form shouldn't,
# in my opinion, be submitting to the exact same url. And if you need to include an additional
# form on a page that POST's elsewhere than a simple override of get_context_data would
# be a better option. This keeps your views focuses on their task while still allowing you
from django.conf import settings
from django.db.models.loading import cache
REAL_LOAD_APP = cache.load_app
def _load_app(app, *args, **kwargs):
r = REAL_LOAD_APP(app, *args, **kwargs)
# @@@ This is Really Hacky
// While you can edit this file, it's generally best to put your changes in
// "User/Base File.sublime-settings", which overrides the settings in here.
//
// Settings may also be placed in file type specific options files, for example,
// in Packages/Python/Python.sublime-settings for python files.
{
// Sets the colors used within the text area
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
// Note that the font_face and font_size are overriden in the platform
@dstufft
dstufft / mro.py
Created November 30, 2011 02:14
Python MRO Example
class A(object):
pass
class B(object):
pass
class C(object):
pass
class CandB(C, B):
#
# Taken from http://justcramer.com/2010/12/06/tracking-changes-to-fields-in-django/
#
def track_data(*fields):
"""
Tracks property changes on a model instance.
The changed list of properties is refreshed on model initialization
and save.
@dstufft
dstufft / uuidfield.py
Created November 30, 2011 13:50
PostgreSQL specific implementation of a UUIDField
import uuid
from django.core.exceptions import ImproperlyConfigured
from django.db import models
try:
import psycopg2.extras
psycopg2.extras.register_uuid()
except ImportError:
raise ImproperlyConfigured("UUIDField currently only support PostgreSQL and the psycopg2 interface.")
@dstufft
dstufft / .pylintrc
Created December 1, 2011 20:08
PyLint Messages
# Brain-dead errors regarding standard language features
# W0142 = *args and **kwargs support
# W0403 = Relative imports
# Pointless whinging
# R0201 = Method could be a function
# W0212 = Accessing protected attribute of client class
# W0613 = Unused argument
# W0232 = Class has no __init__ method
# R0901 = Too Many Ancestors