- 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:
| # 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) |
| # 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: |
| 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 = [] |
run:
python manage.py runserver_plus || python manage.py runserver
| " 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 |
| >>> # 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() |
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.
| (() -> | |
| 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]" |
| /* | |
| * 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(); |
| 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); |