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) { |
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
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
""" | |
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
# 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
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
{% 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
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
from itertools import count | |
def chunked_iterator(iterable, chunk_size): | |
"""Given a slice-able yield individual items but consume them in chunk_size | |
batches so we can e.g. retrieve records from Solr in 50-100 batches | |
rather than the default 10 | |
Note that unlike the itertools grouper example we must use slice notation | |
to trigger things like Haystack's sliced __getitem__ to set our own batch | |
size |
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
""" | |
An alternative Django ``TEST_RUNNER`` which uses unittest2 test discovery from | |
a base path specified in settings, rather than requiring all tests to be in | |
``tests`` module of an app. | |
If you just run ``./manage.py test``, it'll discover and run all tests | |
underneath the ``TEST_DISCOVERY_ROOT`` setting (a path). If you run | |
``./manage.py test full.dotted.path.to.test_module``, it'll run the tests in | |
that module (you can also pass multiple modules). |
OlderNewer