This file contains hidden or 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
# usage: python <thisfile.py> help -- downloads the files to the current directory | |
# requires libmpq | |
# Attempts to brute force and download specific patches | |
# e.g. python sc2patch.py --current=0.10.0.14803 --next=0.11.0.15097 | |
# This would find and download any patches relevant, the next argument is optional, | |
# but allows you to provide a starting point. This stops at the first patch it finds, | |
# so you would need to continue with a new starting point if you wanted a different patch. | |
# e.g. if you didnt specify next in this example, it would stop at the initial 0.11 build, | |
# which wasnt publicly released |
This file contains hidden or 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
<html> | |
<head> | |
<title>Comments count code example</title> | |
</head> | |
<body> | |
<!-- For this link, we will try to fetch comments count by URL: http://example.com/article.html --> | |
<a href="http://example.com/article.html#disqus_thread">First article</a> | |
<!-- For this link, we will try to fetch comments count by identifier: article2identifier --> |
This file contains hidden or 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 queryset_to_dict(qs, key='pk'): | |
""" | |
Given a queryset will transform it into a dictionary based on ``key``. | |
""" | |
return dict((getattr(u, key), u) for u in qs) | |
def distinct(l): | |
""" | |
Given an iterable will return a list of all distinct values. | |
""" |
This file contains hidden or 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
diff --git a/django_root/django/db/models/base.py b/django_root/django/db/models/base.py | |
index 37331b3..4da2802 100644 | |
--- a/django_root/django/db/models/base.py | |
+++ b/django_root/django/db/models/base.py | |
@@ -5,6 +5,7 @@ from itertools import izip | |
import django.db.models.manager # Imported to register signal handler. | |
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned, FieldError, ValidationError, NON_FIELD_ERRORS | |
from django.core import validators | |
+from django.db.models.expressions import ExpressionNode | |
from django.db.models.fields import AutoField, FieldDoesNotExist |
This file contains hidden or 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 QuerySetDoubleIteration(Exception): | |
"A QuerySet was iterated over twice, you probably want to list() it." | |
pass | |
# "Skinny" here means we use iterator by default, rather than | |
# ballooning in memory. | |
class SkinnyManager(Manager): | |
def get_query_set(self): | |
return SkinnyQuerySet(self.model, using=self._db) |
This file contains hidden or 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 attach_foreignkey(objects, field, select_related=None): | |
""" | |
Shortcut method which handles a pythonic LEFT OUTER JOIN. | |
``attach_foreignkey(posts, Post.thread)`` | |
""" | |
field = field.field | |
qs = field.rel.to.objects.filter(pk__in=distinct(getattr(o, field.column) for o in objects)) | |
if select_related: | |
qs = qs.select_related(*select_related) |
This file contains hidden or 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 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') |
This file contains hidden or 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 threading import local | |
_blah = local() | |
class StopThatShit(Exception): | |
pass | |
def patch(): | |
from django.db.backends import util | |
from django import template |
This file contains hidden or 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 django.conf import settings | |
from django.conf.urls.defaults import include, patterns | |
from django.http import HttpResponse | |
from django.utils.encoding import smart_unicode | |
if 'debug_toolbar' not in settings.INSTALLED_APPS: | |
class DebugMiddleware(object): | |
pass | |
else: | |
import debug_toolbar.urls |
OlderNewer