Skip to content

Instantly share code, notes, and snippets.

View benzkji's full-sized avatar
eight times a thing

Ben Stähli benzkji

eight times a thing
  • bnzk GmbH
  • Biel/Bienne Switzerland
View GitHub Profile
benzkji / jquery.fileupload backbone form editor
Last active August 29, 2015 14:06
backbone model parse and sync customizations, jquy fileupload with backbone forms
// backbone form editor (form field)
Backbone.Form.editors.SingleFileUpload = Backbone.Form.editors.Base.extend ({
_self: false,
uploader: false,
template_id: "#singleFileUploadTemplate",
additional_fields: [],
events: {
'change': function() {
benzkji /
Last active August 29, 2015 14:23
django-filer no subfolders
import os
from filer.utils.files import get_valid_filename
def no_subfolders(instance, filename):
return get_valid_filename(filename)
benzkji /
Created February 25, 2016 09:14 — forked from gregplaysguitar/
Django-haystack Whoosh backend with character folding
# -*- coding: utf-8 -*-
Whoosh backend for haystack that implements character folding, as per .
Tested with Haystack 2.4.0 and Whooch 2.7.0
To use, put this file on your path and add it to your haystack settings, eg.
benzkji /
Last active April 14, 2016 13:49
Show basics for adding/removing things. Remove language menu, for one-language pages. Remove Wizard button introduced in 3.2
# coding: utf-8
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from cms.toolbar_pool import toolbar_pool
from cms.toolbar_base import CMSToolbar
from cms.toolbar.items import Break
benzkji /
Last active August 19, 2016 14:04
LinkModel Example
from ....
class LinkBase(models.Model):
link_text = models.CharField(verbose_name=_('Link Text'), max_length=255,
blank=True, default='')
link_type = models.CharField(verbose_name=_('Link'), max_length=20, choices=LINK_TYPE_CHOICES,
blank=True, default='')
page = PageField(null=True, blank=True)
file = FilerFileField(null=True, blank=True, related_name='link')
mailto = models.EmailField(null=True, blank=True)
benzkji / django-cms custom page form
Last active March 3, 2017 13:08
django-cms page form customized
from django.contrib import admin
from django import forms
from django.utils.translation import ugettext_lazy as _
from cms.models import Page
from cms.admin.forms import PageForm
from cms.admin.pageadmin import PageAdmin
class CustomPageForm(PageForm):
page_title = forms.CharField(label=_("Title Tag"), widget=forms.TextInput(),
benzkji / is-touch.js
Created July 8, 2017 05:58
document.addEventListener('touchstart', function addtouchclass(e){ // first time user touches the screen
document.documentElement.classList.add('is-touch') // add "can-touch" class to document root using classList API
document.removeEventListener('touchstart', addtouchclass, false) // de-register touchstart event
}, false)
benzkji / back.js
Created July 9, 2017 21:00
back pattern revisited
// check: if we came frome our own site, just use history.back()
// as simple as it gets.
on_back_click: function(e) {
// this check could be further enhanced, but works quite well already.
if (document.referrer.indexOf( !== -1) {
benzkji / gist:cb889e5a54c749452f01
Last active August 24, 2017 07:50
my current fabfile for django deployement on (nginx / gunicorn)
from fabric.api import task, env, run, local, roles, cd, execute, hide, puts,\
import posixpath
import re
env.forward_agent = True
env.project_name = 'parkhotel' # var
env.repository = '{project_name}.git'.format(**env)
env.local_branch = 'master'
env.remote_ref = 'origin/master'
benzkji /
Last active August 24, 2017 18:19
multilanguage haystack search index, with aldryn_search
from __future__ import unicode_literals
from aldryn_search.base import AldrynIndexBase
from django.template.loader import render_to_string
from haystack import indexes
from bodenschatz.models import Product
class ProductIndex(AldrynIndexBase, indexes.Indexable):