fredag den 6. november 2009

Another micro hack

I often write a pagetemplate that needs to be published later. But page templates has no workflow state.

The problem is when the customer needs to test the page on the live page, but others must not be able to see it yet.

I have a small hack to ensure that only managers can see the page.

I call a low overhead method that is protected by the "Manage portal" permission. Like:

<tal:managerCheck tal:define="managerCheck python: here.portal_migration.getInstanceVersion()" />

When the site is to be published I just remove the line.

Well I told you it was a micro hack!

mandag den 26. januar 2009

School of Small Hacks

Being a web developer it bothers me that I cannot have seperate sessions open in Firefox. You can do it in IE. If you open a new browser you get a new session.

So I (mis)use the hosts file to do something similar in Firefox.


127.0.0.1 localhost
127.0.0.1 localtest # insert this.


Then I can go to http://localhost/ in one tab and http://localtest/ in another. That way the browser sees it as different session.

tirsdag den 6. januar 2009

A small trick for socket timouts in Plone

A few times I have had the need for a socket to timout in Plone. Eg when calling an external site that might be down.

You can set the timeout in Plone, but that is not a good idea as you sometime need long running processes to end properly, eg for packing etc.

A workaround is spwaning seperate threads and callback routines. But that is a bother to set up.

Suddenly it stroke me today that it would be possible to change the timout temporarily for a single thread:



import socket
import feedparser

def parseUrl(self, url):
"Fetch the url"
orig_timout = socket.getdefaulttimeout() # get original timeout
# give it a 20 second timout
socket.setdefaulttimeout(20) # set to 20 seconds
try:
result = feedparser.parse(url)['entries']
except:
result = []
socket.setdefaulttimeout(orig_timout) # set back to original
endresult = []
for r in result:
r2 = {}
r2.update(r)
endresult.append(r2)
# sort for latest first
decorated = [(r['updated_parsed'], r) for r in endresult]
decorated.sort()
decorated.reverse()
sorted = [d[-1] for d in decorated]
return sorted


Sweet and simple ...

fredag den 28. november 2008

Put on the Pyjamas and code

Javascript is a nice language, but Python is nicer. So how about writing in Python and having it automatically translated to Javascript. I will have to check that out.

http://pyjs.org/

tirsdag den 2. september 2008

Installing Deliverance

Deliverance is a cool tool, that makes it possible to give web based software a new skin.
Without changing the original software.

It opens a lot of new options to development, migration and integration.

You can have site running that uses Plone, plain html, mailman, blogger etc. And still looks like a single coherent site.

I had few problems installing it using the manual method, so this is the code from how I actually got it to work.



easy_install virtualenv
virtualenv deliverance_env
cd deliverance_env/
source bin/activate
svn co http://codespeak.net/svn/z3/deliverance/buildout/trunk .
python bootstrap/bootstrap.py
./bin/buildout
./bin/deliverance


It started up fine, but the first page I tried to get threw an exception:


Error - exceptions.ImportError: No module named HTML4


Turned out that the default generated deliverance-proxy.ini had a bug:


serializer = deliverance.serializers.HTML4


Changing it to:


serializer = deliverance.serializers:HTML4


works

onsdag den 4. juni 2008

json_migrator Alpha release.

The code for my Plone json migrator has been "sort of functional" for a while now. I will probably not change it before the summer vacation, but that is no reason not to let other look at it.

It is only available in the Collective.

http://svn.plone.org/svn/collective/json_migrator/trunk/

It was successfully used to migrate a 2.0.x site to 3.1.

fredag den 23. maj 2008

Export of member data from Plone as a CSV file

I needed to export member data from Plone for mail merging etc. There was nothing really suitable available so I wrote this small product for it.

The manual is:


Install "portal_memberdata_export" with the quickinstaller.

Export by calling the memberdataExportCSV script, like http://www.example.com/memberdataExportCSV

You need to have the "Manage Portal" permission.



So far it is only available from the collective.

http://svn.plone.org/svn/collective/memberdata_export/trunk/