This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.template.defaultfilters import slugify | |
class AutoSlugMixin(object): | |
""" | |
Automatically set slug to slugified version of the name if left empty. | |
Use this as follows:: | |
class MyModel(AutoSlugMixin, models.Model): | |
def save(self): | |
super(MyModel, self).save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class InlineButtonsAdminMixin(object): | |
""" | |
Mixin which dynamically adds links to inline admins on the top right of | |
the admin form. | |
""" | |
class Media: | |
js = ('js/inlinebuttons.js',) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LimitedAdminInlineMixin(object): | |
""" | |
InlineAdmin mixin limiting the selection of related items according to | |
criteria which can depend on the current parent object being edited. | |
A typical use case would be selecting a subset of related items from | |
other inlines, ie. images, to have some relation to other inlines. | |
Use as follows:: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.urlresolvers import reverse | |
from sorl.thumbnail import get_thumbnail | |
from django.conf.urls.defaults import patterns, url | |
# This nice little snippet makes the life of someone extending the admin | |
# functionality a lot easier. | |
# Find the original at: http://djangosnippets.org/snippets/1804/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
logger = logging.getLogger(__name__) | |
# Note: we need dnspython for this to work | |
# Install with `pip install dnspython` | |
import dns.resolver, dns.exception | |
from django import forms | |
from django.utils.translation import ugettext as _ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys | |
from optparse import OptionParser | |
def main(): | |
parser = OptionParser(usage="usage: %prog [options] <notice_filename> <code_filename>") | |
(options, args) = parser.parse_args() | |
if len(args) != 2: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Listener(object): | |
""" | |
Class-based listeners, based on Django's class-based generic views. Yay! | |
Usage:: | |
class MySillyListener(Listener): | |
def dispatch(self, sender, **kwargs): | |
# DO SOMETHING | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging, re | |
logger = logging.getLogger(__name__) | |
from django.utils.translation import get_language | |
LANGUAGE_CODE_RE = re.compile(r'_(?P<code>[a-z_]{2,5})$') | |
class TranslatableMixin(object): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OrderableFormMixin(object): | |
""" | |
Form mixin class which allows for reordering and hiding fields for normal | |
forms, similar to the way this is possible with ModelForms:: | |
class MyFunkyForm(OrderableFormMixin, Form): | |
class Meta: | |
fields = ('my_field1', 'my_field2') | |
This snippet is based on: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import platform | |
import re | |
import urllib2 | |
import urlparse | |
from django.core.exceptions import ValidationError | |
from django.core.validators import RegexValidator | |
from django.core.urlresolvers import resolve | |
from django.http import Http404 | |
from django.utils.translation import ugettext_lazy as _ |
OlderNewer