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 / 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 / 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 / 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 /
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 /
Created December 8, 2015 07:15
haystack index for django-filer PDFs
# coding: utf-8
from __future__ import unicode_literals
import os
from pdfminer.pdfdocument import PDFEncryptionError
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
from pdfminer.converter import TextConverter
from pdfminer.layout import LAParams
from pdfminer.pdfpage import PDFPage
from cStringIO import StringIO
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 May 11, 2018 11:22
remove top right "create" button from django cms toolbar
from cms.toolbar_pool import toolbar_pool
from cms.cms_toolbars import PlaceholderToolbar
class PlaceholderToolbarNoWizard(PlaceholderToolbar):
def add_wizard_button(self):
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 / index.html
Last active March 25, 2021 16:41
simple invisible recaptcha example, works with multiple forms
<script src=''></script>