Skip to content

Instantly share code, notes, and snippets.

Avatar
🕶️
Available for training, coaching and trouble-shooting (as usual)..

Jens W. Klein jensens

🕶️
Available for training, coaching and trouble-shooting (as usual)..
View GitHub Profile
@jensens
jensens / versionfinder.py
Created February 8, 2011 11:20
parses zopes instance file and returns versions used (for use in buildout)
View versionfinder.py
# versionfinder
import re
regexp = re.compile('.*\/(.*)-(.*)-py')
with open('instance', 'r') as ins:
for line in ins.readlines():
res = regexp.match(line)
if res is None:
continue
print "%s = %s" % res.groups()
@jensens
jensens / actions.py
Created March 2, 2011 16:10
actions to set a Navigation Root
View actions.py
from zope.interface import Interface
from zope.interface import directlyProvides
from zope.interface import noLongerProvides
from Products.Five.browser import BrowserView
from Products.CMFPlone.interfaces import INavigationRoot
from Products.CMFPlone import PloneMessageFactory as _
class IPossibleNavigationRoot(Interface):
pass
View gist:953532
from Products.Five.browser import BrowserView
class LangRedir(BrowserView):
"""language redirect"""
def __call__(self):
target = 'en-ie'
for lang in self.context.portal_languages.getRequestLanguages():
if lang in ('de-at', 'de-ch'):
target = 'de-at'
@jensens
jensens / dcwf2dot.py
Created March 1, 2012 22:57
generates dot file from workflows (zope python script)
View dcwf2dot.py
context.REQUEST.response.setHeader('Content-Type', 'text/plain')
print "digraph %s {" % context.getId()
wf = context
state_to_trans = []
for state in wf.states.values():
roles = state.getAvailableRoles()
roles.sort()
permtable = [ ['<FONT POINT-SIZE="10">%s</FONT>' % _ for _ in ['permission', 'acquired'] + roles ] ]
for perm in state.getManagedPermissions():
pinfo = state.getPermissionInfo(perm)
@jensens
jensens / buildout.cfg
Created March 29, 2012 08:28
python buildout with lxml
View buildout.cfg
[buildout]
parts = py
[py]
recipe = zc.recipe.egg
eggs = lxml
interpreter = py
@jensens
jensens / buildout.cfg
Created April 4, 2012 10:59
Minimla Plone 4.1
View buildout.cfg
[buildout]
find-links +=
http://effbot.org/downloads/
parts =
instance
omelette
extends =
http://dist.plone.org/release/4.1-latest/versions.cfg
@jensens
jensens / buildout.cfg
Created April 4, 2012 13:15
Buildout which just adds setuptools to python
View buildout.cfg
[buildout]
parts = py
[py]
recipe = zc.recipe.egg
eggs =
setuptools
interpreter = py
@jensens
jensens / action.py
Created August 29, 2012 20:10
Plone action menu enable feature by setting marker interface
View action.py
from zope.interface import Interface
from zope.interface import directlyProvides
from zope.interface import noLongerProvides
from Products.Five.browser import BrowserView
from Products.CMFPlone import PloneMessageFactory as _
class ISomeFeatureTarget(Interface):
pass
class IPossibleSomeFeatureTarget(Interface):
View locandy_gae.tests.py
import unittest
import doctest
from pprint import pprint
from interlude import interact
from google.appengine.ext import testbed
optionflags = doctest.NORMALIZE_WHITESPACE | \
doctest.ELLIPSIS | \
doctest.REPORT_ONLY_FIRST_FAILURE
View querystring.py
from plone.app.querystring.queryparser import getPathByUID, getNavigationRoot
def _multi_path(context, row):
values = []
for value in row.values.split():
if not '/' in value:
# It must be a UID
value = '/'.join(getPathByUID(context, value))
# take care of absolute paths without nav_root
nav_root = getNavigationRoot(context)