Skip to content

Instantly share code, notes, and snippets.

View beniwohli's full-sized avatar

Benjamin Wohlwend beniwohli

View GitHub Profile
# -*- coding: utf-8 -*-
from django.core.management.commands import loaddata
from django.db.models import signals
class Command(loaddata.Command):
def handle(self, *fixture_labels, **options):
from cms.signals import update_placeholders
@beniwohli
beniwohli / views.py
Created October 4, 2012 13:10
extension of django.views.generic.ListView for sorted lists
# -*- coding: utf-8 -*-
from django.views.generic import ListView
class SortableListView(ListView):
allowed_sort_fields = ()
sort_default = None
sort_key = 'sort'
sort_field_splitter = '-'
sort_ascending_postfix = 'up'
sort_descending_postfix = 'down'
@beniwohli
beniwohli / gameoflife.c
Created September 17, 2012 11:31
A Game Of Life implementation for Rockbox
#include "plugin.h"
PLUGIN_HEADER
/* variable button definitions */
#if CONFIG_KEYPAD == RECORDER_PAD
#define GOL_QUIT BUTTON_OFF
#define GOL_UP BUTTON_UP
#define GOL_DOWN BUTTON_DOWN
@beniwohli
beniwohli / models.py
Created September 13, 2012 09:11
Combine hvad and mptt
from project.utils import classmaker
class Category(TranslatableModel, MPTTModel):
# https://github.com/ojii/django-nani/issues/39
__metaclass__ = classmaker()
# modified version of http://tomforb.es/using-python-metaclasses-to-make-awesome-django-model-field-choices
# that preserves order of definition
import inspect, itertools
class Option(object):
_counter = itertools.count()
def __init__(self, value, verbose_name=None):
self._count = Option._counter.next()
SELECT "cms_title"."id",
"cms_title"."language",
"cms_title"."title",
"cms_title"."menu_title",
"cms_title"."slug",
"cms_title"."path",
"cms_title"."has_url_overwrite",
"cms_title"."application_urls",
"cms_title"."redirect",
"cms_title"."meta_description",
@beniwohli
beniwohli / gist:3128205
Created July 17, 2012 09:03
turns html entities into unicode characters
@register.filter
def unescape(value):
"""
Removes HTML or XML character references and entities from a text string.
#
@param text The HTML (or XML) source text.
@return The plain text, as a Unicode string, if necessary.
"""
def fixup(m):
text = m.group(0)
@beniwohli
beniwohli / admin.py
Created July 13, 2012 12:02
workaround example for fieldsets in hvad admin
class MyModelAdmin(TranslatableAdmin)
list_display = ('title', 'is_published')
use_fieldsets = (
(_("Common"), {
'fields': (('is_published',)
}),
(_("Language dependent"), {
'fields': ('name', 'slug',),
}),
#!/bin/bash
# For Ubuntu 8.x and 9.x releases.
if [ -d "/usr/share/postgresql-8.3-postgis" ]
then
POSTGIS_SQL_PATH=/usr/share/postgresql-8.3-postgis
POSTGIS_SQL=lwpostgis.sql
GEOGRAPHY=0
fi
@beniwohli
beniwohli / fill_translations.py
Created February 2, 2012 09:03
Django management command to copy translations from one po file into another
# -*- coding: utf-8 -*-
import os
from optparse import make_option
import polib
from django.core.management import CommandError
from django.core.management.base import AppCommand