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
benzkji / gist:cb889e5a54c749452f01
Last active August 24, 2017 07:50
my current fabfile for django deployement on djangoeurope.com (nginx / gunicorn)
from fabric.api import task, env, run, local, roles, cd, execute, hide, puts,\
sudo
import posixpath
import re
env.forward_agent = True
env.project_name = 'parkhotel' # var
env.repository = 'git@bitbucket.org:benzkji/bnzk_{project_name}.git'.format(**env)
env.local_branch = 'master'
env.remote_ref = 'origin/master'
@benzkji
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 ({
//tagName:"input",
_self: false,
uploader: false,
template:false,
template_id: "#singleFileUploadTemplate",
additional_fields: [],
events: {
'change': function() {
@benzkji
benzkji / utils.no_subfolders.py
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
benzkji / django-cms custom page form admin.py
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
benzkji / cms_toolbar.py
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.cms_toolbar import ADMIN_MENU_IDENTIFIER, LANGUAGE_MENU_IDENTIFIER
from cms.toolbar_base import CMSToolbar
from cms.toolbar.items import Break
@toolbar_pool.register
@benzkji
benzkji / search_indexes.py
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
benzkji / search_backends.py
Created February 25, 2016 09:14 — forked from gregplaysguitar/folding_whoosh_backend.py
Django-haystack Whoosh backend with character folding
# -*- coding: utf-8 -*-
"""
Whoosh backend for haystack that implements character folding, as per
http://packages.python.org/Whoosh/stemming.html#character-folding .
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
benzkji / cms_toolbars.py
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
toolbar_pool.unregister(PlaceholderToolbar)
@toolbar_pool.register
class PlaceholderToolbarNoWizard(PlaceholderToolbar):
def add_wizard_button(self):
pass
@benzkji
benzkji / models.py
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
benzkji / index.html
Last active March 25, 2021 16:41
simple invisible recaptcha example, works with multiple forms
<script src='https://www.google.com/recaptcha/api.js?hl=de'></script>
check https://developers.google.com/recaptcha/docs/invisible
<div
id="header_recaptcha"
class="g-recaptcha"
data-sitekey="6LctdiQUAAAAAOTUOX92-PkGJXpZgGUp5hrq4l65"
data-size="invisible"
data-callback="recaptcha_submit"