Skip to content

Instantly share code, notes, and snippets.

View ojii's full-sized avatar

Jonas Obrist ojii

View GitHub Profile
@chrisglass
chrisglass / inspect_urls.py
Created February 13, 2011 16:42
Creates a flat list of all your url resolvers in Django
from django.core.urlresolvers import get_resolver
from django.core.urlresolvers import RegexURLResolver, RegexURLPattern
def _recurse_resolver(resolver, prefix=[]):
patterns = []
for obj in resolver.url_patterns:
if isinstance(obj, RegexURLPattern):
patterns.append(prefix + [obj.regex.pattern])
elif isinstance(obj, RegexURLResolver):
@evildmp
evildmp / convert_to_placeholders.html
Created January 13, 2011 15:39
Convert to Placeholders is a routine that converts text fields in other applications to Django CMS placeholders.
<h3>Summary</h3>
{% if not execute %}
<p>This is a <strong>dry run</strong>. Nothing has been changed.</p>
<p>Please check the results. If you are satisfied, <a href="/convert_to_placeholders/True/">perform the actions listed below</a>, or <a href="/convert_to_placeholders/">do another dry run</a>.</p>
{% else %}
<p><a href="/convert_to_placeholders/">Perform a dry run instead</a>. It's probably too late though.</p>
{% endif %}
<ul>
@chrisglass
chrisglass / install_django_cms.sh
Created January 12, 2011 18:18
This will install a "naked" version of Django-CMS to use as a demonstration.
#!/bin/bash
# This should be run on a relatvely modern version of Ubuntu (9.10 or later,
# without any sort of confidence)
PROJECT_NAME=$1
if [ x$PROJECT_NAME = "x" ] ; then
# No project name!
echo "Usage: $0 <project name>"
exit 1
@ojii
ojii / example.html
Created January 12, 2011 15:39
example settings.py for the django CMS
{% load cms_tags %}
<!doctype html>
<head>
<title>{{ request.current_page.get_title }}</title>
{% plugins_media %}
</head>
<body>
{% placeholder "main" %}
</body>
@chrisglass
chrisglass / autodiscover_local_memcaches
Created December 21, 2010 08:49
This makes Django settings autodiscover local memcaches! :)
import os
import socket
class IP(object):
def __init__(self):
self.base = None
def get(self, end):
if not self.base:
@stefanfoulis
stefanfoulis / search_indexes.py
Created May 4, 2010 08:08 — forked from beniwohli/search_indexes.py
fork with support for cms placeholders (upcoming cms 2.1 release)
from django.conf import settings
from django.utils.translation import string_concat, ugettext_lazy
from django.utils.html import strip_tags
from haystack import indexes, site
from cms.models.managers import PageManager
from cms.models.pagemodel import Page
from cms.models.pluginmodel import CMSPlugin