Skip to content

Instantly share code, notes, and snippets.

View ojii's full-sized avatar

Jonas Obrist ojii

View GitHub Profile
@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>
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
import urllib2
import urllib
class Rest(object):
def __init__(self, base):
self.base = base
self.opener = urllib2.build_opener(urllib2.HTTPHandler)
def get(self, path):
return urllib2.urlopen(self.base + path).read()
from django.template.defaultfilters import slugify
from django.db.models.signals import pre_save
class Slugifier(object):
def __init__(self, model, target, source):
self.model = model
self.target = target
self.source = source
field = self.model._meta.get_field_by_name(self.target)[0]
self.max_length = field.max_length
@ojii
ojii / very_dangerous_script.py
Created February 3, 2011 16:12
DONT USE THIS IF YOU DONT KNOW EXACTLY WHAT IT DOES AND HOW IT DOES IT!
'''
WARNINGS: THIS SCRIPT COMES WITHOUT ANY WARRANTY AND RUNNING IT IS DONE SO AT YOUR OWN RISK!
'''
from cms.models import Page
def setup():
from django.contrib.auth.models import User
from cms.utils.permissions import set_current_user
set_current_user(User.objects.get(id=1))
def check_no_moderator():
##############################################################################
#
# Copyright (c) 2006 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
@ojii
ojii / embedable_plugin.py
Created February 25, 2011 10:06
The bit inside the 'cmsplugin' tag is actually a link plugin!
class LinkPlugin(CMSPluginBase):
def get_embed_content(self, instance, parent_instance):
ctx = Context()
return render_to_string(self.render_template, self.render(ctx, instance, None))
import re
from django.conf import settings
from django.http import HttpResponseRedirect
DEFAULT = 'http://www.getfirefox.com'
class IE6CountdownMiddleware(object):
"""
Do *very* simple user agent scanning and redirect anyone accessing your site
@ojii
ojii / __init__.py
Created March 28, 2011 14:11
__init__.py
# nothing here
@ojii
ojii / wtf.py
Created March 30, 2011 08:15
wtf.py
from django import template
from pprint import pformat
register = template.Library()
@register
def wtf(obj):
return pformat(obj)