Skip to content

Instantly share code, notes, and snippets.

View huxley's full-sized avatar

Patrick Taylor huxley

View GitHub Profile
def get_cache_key(model, pk):
"""
Generates a cache key based on ``WRITE_CACHE_PREFIX``, the cache key prefix
defined in the settings file (if any), the Django app and model name, and
the primary key of the object.
"""
params = {
'prefix': getattr(settings, 'WRITE_CACHE_PREFIX', ''),
'app': model._meta.app_label,
'model': model._meta.object_name,
@huxley
huxley / attribute whitelist and XSS protection .py
Created August 18, 2010 01:52
whitelist + XSS protection example
# http://djangosnippets.org/snippets/1655/
from django import template
from BeautifulSoup import BeautifulSoup, Comment
import re
register = template.Library()
def sanitize(value, allowed_tags):
"""Argument should be in form 'tag2:attr1:attr2 tag2:attr1 tag3', where tags