This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% load cms_tags %} | |
<!doctype html> | |
<head> | |
<title>{{ request.current_page.get_title }}</title> | |
{% plugins_media %} | |
</head> | |
<body> | |
{% placeholder "main" %} | |
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
context.update({ | |
'gallery': instance.gallery, | |
'object': instance, | |
'placeholder': placeholder, | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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() |