Skip to content

Instantly share code, notes, and snippets.

@diox
diox / gist:c7a4667abc9a3df1ddff
Created February 4, 2015 14:34
How to upload langpacks on Marketplace
import os
import re
import requests
import feedgenerator
from dateutil.parser import parse
from raven import Client
REPO = 'django/django'
@diox
diox / gist:2184204
Created March 24, 2012 15:20
clamp_pagination() for django-pagination app
@register.simple_tag(takes_context=True)
def clamp_pagination(context, key):
"""
Force number of pages to be never be more than PAGINATION_FIXED_NB_PAGES
"""
paginator = context.get('paginator')
page_obj = context.get('page_obj')
if paginator and page_obj:
max_num_pages = getattr(settings, 'PAGINATION_FIXED_NB_PAGES', 10)
@diox
diox / gist:1067644
Created July 6, 2011 16:17
Custom memcached backends for django, enabling binary protocol and hiding errors
from django.core.cache.backends import memcached
import pylibmc
import logging
log = logging.getLogger('django.core.cache.backends.memcached')
class BinaryPyLibMCCache(memcached.PyLibMCCache):
"""
Custom cache backend using pylibmc that enables binary protocol
@diox
diox / clear_johnny_cache.py
Created July 5, 2011 16:30
Django management command to clear johnny-cache cache :-)
import sys
import logging
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
help = ("Invalidates portions of the queryset cache based on the app names"
" or models provided as arguments to the command. If no arguments "
"are provided, nothing is done. To clear the entire queryset "
from django.db import models
class Foo(models.Model):
bar = models.PositiveSmallIntegerField(default=1)
class Meta:
ordering = ['bar']
class Child(Foo):
barchild = models.PositiveSmallIntegerField(default=1)
@diox
diox / gist:909599
Created April 8, 2011 10:15
How django_compressor {% compress %} works behind the scenes

How django_compressor {% compress %} works behind the scenes

This document assumes you already have an up and running instance of django_compressor, and that you understand how to use it in your templates. The goal is to explain what the main template tag, {% compress %}, does behind the scenes, to help you debug performance problems for instance.

First step: Offline cache

@diox
diox / gist:896618
Created March 31, 2011 15:47
Patch against rhythmbox-random-album-player to make it use library filters instead of play queue
Index: __init__.py
===================================================================
--- __init__.py (revision 4)
+++ __init__.py (working copy)
@@ -39,17 +39,24 @@
def __init__(self):
rb.Plugin.__init__(self)
- def queue_random_album(self):
+ def get_random_album_first_song(self):