Skip to content

Instantly share code, notes, and snippets.

View ojii's full-sized avatar

Jonas Obrist ojii

View GitHub Profile
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
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.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
@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 __future__ import with_statement
from unittest import TestCase
from tempfile import template, mkdtemp, _exists
from sphinx.application import Sphinx
import os
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
def render_page(request, page):
context = RequestContext(request)
context['lang'] = get_language_from_request(request)
context['current_page'] = page
context['has_change_permissions'] = page.has_change_permission(request)
request._current_page_cache = page
render_to_response(page.get_template(), context)
# install virtualenv either using apt-get, yum, pip, easy_install or directly from http://pypi.python.org/pypi/virtualenv/1.5.1
# this tutorial assumes you use a proper operating system (read: no windows)
# you should start this series of commands from your workspace
# If you use another database than mysql you have to replace pip install mysql-python with the appropriate database connector
virtualenv --no-site-packages yourprojectname
cd yourprojectname
. bin/activate
pip install django
pip install PIL
pip install mysql-python
context.update({
'gallery': instance.gallery,
'object': instance,
'placeholder': placeholder,
})
from django.forms.fields import ChoiceField
from django.forms.models import ModelChoiceField, ModelMultipleChoiceField
class CachedModelChoiceIterator(object):
def __init__(self, field):
self.field = field
self.queryset = field.queryset
self.model = field.queryset.model
# -*- coding: utf-8 -*-
from django.db import models
from translateable.models import TranslatedModel
class MyModel(TranslatedModel):
non_translated_field = models.IntegerField()
class Translations(models.Model):
translateable_field = models.IntegerField()