Skip to content

Instantly share code, notes, and snippets.

@gsakkis
gsakkis / gist:866301
Created March 11, 2011 18:10
Dumbo remote debugging
import os, sys
class Winpdb(object):
'''Embed a Winpdb server.
If you have to tunnel to connect remotely from the Winpdb client, run:
ssh -C -N -f -L 51000:localhost:51000 $SERVER_HOST
@gsakkis
gsakkis / gist:631306
Created October 17, 2010 21:17
Replace classmethod with descriptor
diff --git a/django/views/generic/base.py b/django/views/generic/base.py
--- a/django/views/generic/base.py
+++ b/django/views/generic/base.py
@@ -9,6 +9,39 @@
logger = getLogger('django.request')
+class AsViewDescriptor(object):
+ def __get__(self, instance, cls):
+ if instance is not None:
'''Manager-based polymorphic model inheritance.
This module provides a non-intrusive approach for accessing polymorphically
instances of a model hierarchy. Non-intrusive means:
- It does not require extending a custom ``Model`` base class or metaclass.
- It does not require a ``ForeignKey`` to ``ContentType`` or the ``contenttypes``
app in general. Instead the real class of an instance is determined based on
the value (**polymorphic identity**) of a user-specified discriminating field
(**polymorphic on**).
- It does not override the default (or any other) model ``Manager`` (unless
from collections import Mapping, namedtuple
def choices(fields):
'''Create a tuple-like instance appropriate for Django's ``Field.choices``.
Additionally the returned instance also supports attribute access by field name.
Example usage::
>>> t = choices(enumerate(['abc', 'pqr', 'xyz']))