Skip to content

Instantly share code, notes, and snippets.

View simahawk's full-sized avatar

Simone Orsi simahawk

View GitHub Profile
@simahawk
simahawk / gist:1286732
Created October 14, 2011 10:10
lfs template tag example
from django import template
register = template.Library()
import lfs.cart.utils
from lfs.core.models import Shop
from lfs.caching.utils import lfs_get_object_or_404
@register.inclusion_tag("lfs/disclaimer.html")
def disclaimer():
@simahawk
simahawk / gist:2043829
Created March 15, 2012 11:47
zeo conf for buildout
[buildout]
parts +=
zeoserver
client1
client2
cljobs
cldebug
[zeoserver]
recipe = plone.recipe.zeoserver
@simahawk
simahawk / zodb_keyerror_tmp_fix.py
Created April 20, 2012 13:19
temporary fix for ZODB connection KeyError
# temporary hack for fixing ZODB connection error
from ZODB import FileStorage, DB
dbname = 'my_missing_db'
path = 'path/to/missing/storage.fs'
storage = FileStorage.FileStorage(path)
db = DB(storage)
# app is the zope instance in debug mode
app._p_jar._db.databases[dbname] = db
@simahawk
simahawk / killitnow.py
Last active December 23, 2015 15:57
Kill any process by name or part of it, and kill it now!
#!/usr/bin/python2.7
import sys
import os
import psutil
def find_process(tokill):
res = []
for proc in psutil.process_iter():
cmdline = hasattr(proc.cmdline, '__call__') \
@simahawk
simahawk / gist:4707567
Last active December 12, 2015 03:29
register plone user and notify if needed
def _register(self, username, properties):
member = None
try:
# force encoding to utf8
for k,v in properties.items():
properties[k]= v.encode('utf8')
member = self.regtool.addMember(username, properties['fullname'], properties['email'])
member.setMemberProperties(properties)
self.created += 1
msg = "created user '%s' -> %s" % (username,str(properties))
@simahawk
simahawk / collection_utils.py
Created July 12, 2013 07:34
Plone: extracting catalog query from topic and collection seamlessly
from Products.ATContentTypes.interfaces import IATTopic
from plone.app.collection.interfaces import ICollection
from plone.app.querystring import queryparser
def is_collection(obj):
return IATTopic.providedBy(obj) or ICollection.providedBy(obj)
def parse_new_collection_query(context):
@simahawk
simahawk / member-subscribers.zcml
Created October 15, 2013 10:05
Plone Memer events and hooks for subscribers
<subscriber
for="Products.PlonePAS.interfaces.events.IUserInitialLoginInEvent"
handler=".subscribers.user_firsttime_loggedin"
/>
<subscriber
for="Products.PluggableAuthService.interfaces.events.IUserLoggedInEvent"
handler=".subscribers.user_loggedin"
/>
<subscriber
@simahawk
simahawk / advancedpage.py
Last active August 29, 2015 14:00
A dexterity advanced page that renders ZPT markup
#-*- coding: utf-8 -*-
from Acquisition import aq_inner
from Acquisition import aq_base
from five import grok
from zope import schema
from zope.component import getMultiAdapter
# ~/.gitconfig
[branch]
autosetupmerge = true
[push]
default = current
[core]
excludesfile = .gitignore
@simahawk
simahawk / ldap.cfg
Created June 3, 2015 10:57
LDAP setup via buildout
[buildout]
parts +=
openldap
python-ldap
eggs +=
plone.app.ldap
[openldap]
recipe = zc.recipe.cmmi