Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| from django.db.models.signals import post_init | |
| def track_data(*fields): | |
| """ | |
| Tracks property changes on a model instance. | |
| The changed list of properties is refreshed on model initialization | |
| and save. | |
| >>> @track_data('name') |
| from django.db.models.signals import post_syncdb | |
| from django.contrib.contenttypes.models import ContentType | |
| from django.contrib.auth.models import Permission | |
| def add_view_permissions(sender, **kwargs): | |
| """ | |
| This syncdb hooks takes care of adding a view permission too all our | |
| content types. | |
| """ | |
| # for each of our content types |
| import os | |
| from django.conf import settings | |
| from django.contrib.staticfiles.finders import BaseFinder, AppDirectoriesFinder | |
| from django.contrib.staticfiles.storage import AppStaticStorage | |
| from django.core.files.storage import FileSystemStorage | |
| from django.utils._os import safe_join | |
| class AppMediaStorage(AppStaticStorage): |
| ''' | |
| Author: Stephen J. Zabel | |
| License: BSD | |
| This module exposed a helper function for | |
| wrapping views at the urls.py/resolver level | |
| My personal little itch as an example... | |
| urlpatterns += required( |
| import os | |
| from django.conf import settings | |
| from django.contrib.staticfiles.finders import BaseFinder, AppDirectoriesFinder | |
| from django.contrib.staticfiles.storage import AppStaticStorage | |
| from django.core.files.storage import FileSystemStorage | |
| from django.utils._os import safe_join | |
| class AppMediaStorage(AppStaticStorage): |
| # --*-- coding: utf-8 --*-- | |
| from django.db import models | |
| # Create your models here. | |
| class TipoLicencaDeUso(models.Model): | |
| nome = models.CharField(max_length=255) | |
| descricao = models.TextField(verbose_name=u"Descrição") | |
| sigla = models.CharField(max_length=20) |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| // Create a jquery plugin that prints the given element. | |
| jQuery.fn.print = function(){ | |
| // NOTE: We are trimming the jQuery collection down to the | |
| // first element in the collection. | |
| if (this.size() > 1){ | |
| this.eq( 0 ).print(); | |
| return; | |
| } else if (!this.size()){ | |
| return; | |
| } |
| from django.utils.decorators import method_decorator | |
| def class_decorator(decorator): | |
| def inner(cls): | |
| orig_dispatch = cls.dispatch | |
| @method_decorator(decorator) | |
| def new_dispatch(self, request, *args, **kwargs): | |
| return orig_dispatch(self, request, *args, **kwargs) | |
| cls.dispatch = new_dispatch | |
| return cls |