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
def expire_view_cache(view_name, args=[], namespace=None, key_prefix=None, method="GET"): | |
""" | |
This function allows you to invalidate any view-level cache. | |
view_name: view function you wish to invalidate or it's named url pattern | |
args: any arguments passed to the view function | |
namepace: optioal, if an application namespace is needed | |
key prefix: for the @cache_page decorator for the function (if any) | |
from: http://stackoverflow.com/questions/2268417/expire-a-view-cache-in-django | |
added: method to request to get the key generating properly |
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
{% extends "admin/object_history.html" %} | |
{% load adminmedia %} | |
{% block extrahead %} | |
{{ block.super }} | |
<script src="{% admin_media_prefix %}js/jquery.min.js" type="text/javascript" charset="utf-8"></script> | |
{% endblock %} | |
{% block content %} |
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 MyIndex(SearchIndex): | |
text = fields.CharField(document=True, use_template=False) | |
def prepare(self, obj): | |
data = super(MyIndex, self).prepare(obj) | |
extracted_data = self.backend.extract(open(obj.file_field.path, "rb")) | |
if extracted_data is not None: | |
for k, v in extracted_data['metadata'].items(): |
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
# encoding: utf-8 | |
import logging | |
from poster.encode import multipart_encode | |
from pysolr import SolrError, safe_urlencode | |
from haystack.backends.solr_backend import * | |
# For sanity: | |
from haystack.backends.solr_backend import SearchBackend as StandardSolrBackend |
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
""" | |
Apply a decorator to a whole urlconf instead of a single view function. | |
Usage:: | |
>>> from urlconf_decorator import decorate | |
>>> | |
>>> def dec(f): | |
... def wrapper(*args, **kw): | |
... print 'inside the decorator' |
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 functools | |
import sys | |
import re | |
from django.conf import settings | |
from django.db import connection | |
def shrink_select(sql): | |
return re.sub("^SELECT(.+)FROM", "SELECT .. FROM", sql) | |
def shrink_update(sql): |
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
/** | |
* Add this script to the end of your document that use <input autofocus type="text" /> | |
* or <input type="text" placeholder="username" /> and it'll plug support for browser | |
* without these attributes | |
* Minified version at the bottom | |
*/ | |
(function () { | |
function each(list, fn) { | |
var l = list.length; |
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
/* | |
To avoid polluting the global namespace this uses an anonymous | |
function which is called with either the URL for an external | |
JavaScript file or a function. In either case jQuery will be loaded | |
from the Google CDN before your code is executed so it's free to | |
depend on jQuery without checking for it and can do things like | |
jQuery.getScript() to load other components (e.g. jQuery UI), | |
stylesheets, etc. | |
*/ | |
(function (target, msg) { |
NewerOlder