Skip to content

Instantly share code, notes, and snippets.

View kezabelle's full-sized avatar

Keryn Knight kezabelle

View GitHub Profile
@kezabelle
kezabelle / admin.py
Created June 8, 2011 20:08
Terrible attempt at a test case for django-cms
# the method itself, bundled onto AdminTests
def test_changelist_tree_ordering(self):
# make sure we're only getting the pages we care about.
with SettingsOverride(CMS_MODERATOR=False, CMS_PERMISSION=False):
# create some pages, deleting one that pops up in setUp()
kwargs = { 'published': True, 'in_navigation': True, 'language': 'en',
'template': 'nav_playground.html'}
Page.objects.get(pk=1).delete()
page1 = create_page(title="page 1", parent=None, soft_root=True, **kwargs)
page2 = create_page(title="page 2", **kwargs)
@kezabelle
kezabelle / cms_plugins.py
Created September 18, 2011 16:23
test piece for django-cms issue #992
# tests/project/pluginapp/plugins/db_table/cms_plugins.py
from django.db import models
from cms.models import CMSPlugin
class NewPluginTestNoDefaults(CMSPlugin):
pass
class NewPluginTestAsPerDefaults(CMSPlugin):
class Meta:
@kezabelle
kezabelle / perms.py
Created December 9, 2011 15:19
Standalone demonstration of view restrictions issue.
from django.contrib.auth.models import User, Group
from cms.api import create_page
from cms.models.permissionmodels import PagePermission
from cms.models import ACCESS_PAGE, ACCESS_DESCENDANTS, ACCESS_CHILDREN, ACCESS_PAGE_AND_CHILDREN, ACCESS_PAGE_AND_DESCENDANTS
template = "cms/default.html"
language = 'en-gb'
groups = []
users = []
@kezabelle
kezabelle / gist:3142835
Created July 19, 2012 10:06
Runserver with Werkzeug, and fallback.
  • pip install django-extensions Werkzeug
  • add django_extensions to INSTALLED_APPS
  • add Makefile for:
run:
    python manage.py runserver_plus || python manage.py runserver
  • Usage:
@kezabelle
kezabelle / .vimrc
Created September 6, 2012 20:10
Continuous preview of Sphinx docs. A reminder to me, when my .bash_history forgets.
" To get vim to work with Watchdog http://pypi.python.org/pypi/watchdog
" we have to set these; see https://github.com/gorakhargosh/watchdog/issues/56
set noswapfile
set nobackup
set nowritebackup
@kezabelle
kezabelle / gist:3766607
Created September 22, 2012 15:58
WTF Haystack
>>> # Why does applying a list of models increase the number of results
>>> # when that list of models accounts for all search indexes?
>>> from haystack.query import SearchQuerySet
>>> from haystack.forms import model_choices
>>> from django.db.models import get_model
>>> models = [get_model(*x[0].split('.')) for x in model_choices()]
>>> len(models)
6
>>> sqs = SearchQuerySet()
@kezabelle
kezabelle / 001_explanation.rst
Last active December 10, 2015 18:18
Figuring out closure tables.Using a billion blogs, slideshares and implementations that are half complete, or in languages I don't understand.

Closure tables, how the hell do they work?

Attempting to combine piece-meal examples of closure tables into a concrete demonstration.

Bits taken from Rendering Trees with Closure Tables, Closure Table part deux – Nodes and Adjacencies – A tree in MySQL, The simplest(?) way to do tree-based queries in SQL, Moving Subtrees in Closure Table Hierarchies, What is the most efficient/elegant way to parse a flat table into a tree? and Models for hierarchical data and a bunch of others I'll document as I re-find them.

@kezabelle
kezabelle / rebinding_jquery.coffee
Last active December 12, 2015 04:49
Attempting to put django's silly namespaced jQuery back into the global namespace, yay pollution. Now with a CoffeeScript generated version! Is that better? I don't even know!
(() ->
if django?.jQuery?
# standard access via $
window.$ = django.jQuery if not window.$
# in case something is explicitly asking for jQuery.
window.jQuery = django.jQuery if not window.jQuery
# can we log the information?
if console?.log?
console.log "version #{ django.jQuery.fn.jquery.toString() } of jQuery applied to window[$|jQuery]"
@kezabelle
kezabelle / gist:4959657
Created February 15, 2013 10:49
Quick and dirty nested accordian in jQuery, a reminder for myself.
/*
* Taken from http://sower.com.au/2011/06/jquery-multilevel-accordion-in-10-lines-of-code/
*/
$(document).ready(function() {
$('.menu li ul').hide();
$('.menu li a').click(
function(evt) {
evt.preventDefault();
evt.stopPropagation();
var openMe = $(this).next();
@kezabelle
kezabelle / gist:4984836
Created February 19, 2013 10:48
Quick and dirty list item rotation (eg: for carousels), a reminder to myself. Can't remember where I found this :(
var rotate = function() {
$('.carousel ol').each(function(){
var $cur = $(this).find('.current').removeClass('current');
var $next = $cur.next().length?$cur.next():$(this).children().eq(0);
$next.addClass('current').trigger('change');
});
}
var interval = setInterval(rotate, 4000);