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 izip | |
def chunkify(iterable, chunk_size): | |
r""" | |
>>> chunkify(range(1, 11), 2) | |
[(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)] | |
""" | |
_iterable = iter(iterable) | |
return izip(*[_iterable] * chunk_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
class FormsetWidget(forms.Widget): | |
def render(self, name, value, attrs): | |
if isinstance(value, self.formset): | |
formset = value | |
else: | |
formset = self.formset(initial=value, prefix=name) | |
return render_to_string(self.template, {'formset': formset}) | |
def value_from_datadict(self, data, files, name): |
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
# Django tests with multiprocessing (via Brian Rosner) | |
def run_tests_faster(test_labels, verbosity=1, interactive=True, extra_tests=[]): | |
from Queue import Empty | |
from processing import Queue, cpuCount, enableLogging | |
from processing import currentProcess, Process, freezeSupport | |
#enableLogging() | |
# the number of processes to run in parallel. |
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
# Simple way to see which version of django apps you have | |
# Author: Alexander Artemenko | |
import pkg_resources | |
from django.conf import settings | |
def get_version(app): | |
try: | |
d = pkg_resources.get_distribution(app) | |
return d.project_name, d.version |