Posts tagged 'python' – Page 2

Plone and Dexterity: Working with computed fields

Today, we’re looking at how to utilise computed fields within a Dexterity-based content type. The specific use-case is that of having two separate fields (first name and surname, for a Person type, for example) generate the complete object title. The first part of this — having the title of the content displayed correctly — is pretty straight forward once you know what documentation to read and understand how things happen. The second part — having the ID of the content correctly generated to be first name/surname is slightly more complicated.

Title computation and display

Let’s look at the first part …

Plone/Zope, Python and collective.autoreload / plone.reload

Here’s an interesting error message I got stumped with for a good set of hours.  The issue started with me using collective.autoreload with Plone and it does the trick, mostly.  With any such ‘operation’ and live reloading of code for Python, you’ve got to expect that not everything will go according to plan.  Most things do, but one issue I found presented with this error message:

< ... huge traceback ...>
TypeError: super(type, obj): obj must be an instance or subtype of type

The issue arises for me (and you’ll probably see it elsewhere) when I go ahead …

Ubuntu 9.10 install hiccough

Yay, the new version of Ubuntu is out.  With it comes plenty of cool new features (how awesome does the start up and login screen look now?) and also plenty of opportunities for things to break when I’ve become so accustomed to having them working.  At least it’s not Windows though — I think I may just gnaw my own limbs off before I have to get forced to upgrade to Windows 7 for gaming reasons.

But I digress, there was one reasonably small problem with the upgrade that I saw on both of my Ubuntu machines (laptop and …

PloneFormGen (Plone) & Google Calendar Integration

It’s a little bit of a different mash-up, but it’s still nonetheless useful to have, given types of booking forms and so forth that could utilise it.  The easiest way I found (to avoid security issues with Python scripts in Plone) was to create an external method and just import it within a PFG Custom Adapter.

Parts

  • My GoogleCalendar.py external method.  I’ve had to add this into a policy product I have.  The function should be generalised enough to work with any Google account, hosted or not.  In short:

    • It takes in a variety of arguments …

Creating & distributing a new Plone/PyPI product

It’s amazing to see how technologies can be so smoothly integrated these days.  I’m talking, at least in this instance, about how setuptools works with PyPI (and then Plone.org’s Products section) and allows you to distribute your product(s) to the world.  So far, I’ve just got the one — collective.portlet.googleapps — but I’m sure time will pass and I’ll have some more useful things to contribute. Here’s a summary of what I did:

  1. Create the product.  ZopeSkel is a wonderful help here for Plone products. [I lie a little bit in …

Virtualenv, Plone, and Centos 5.x

EDIT: Watch out for python-ldap 2.3.10, the latest version at time of writing. Seems like there’s an issue with it and Centos 5.4. Forcing python-ldap to be version 2.3.8 works, though. (easy_install python-ldap==2.3.8)

Previously, you might have read about setting up a Virtualenv on Ubuntu Jaunty. Now, that was reasonably painless since python-virtualenv and python-setuptools is in the Ubuntu repo. Whether it’s my Centos servers and their misguided repos or me just not being able to find such a related rpm packages, Centos just needs little more love to get …

DateTime in Python/Zope/Plone is painful

Alright, now for today’s problem:  why do two dates that look different when outputted actually end up being the same date?

Answer: I’m not sure, but I’m pretty sure it’s got something to do with the wacky support the above-mentioned 3 products have for timezones.

The background: Plone stores a DateTime object to record a user’s last login time.  It doesn’t really matter what’s purpose is, because Plone (this time) isn’t at fault.  The DateTime gets stored, no worries.  The problem arises when you try to put that value back into a …

Virtualenv, Plone, and Ubuntu 9.04 Jaunty

What a complicated situation it is trying to use all of the above-mentioned pieces of software together. In all seriousness, Virtualenv is now appearing to be the best thing since sliced bread for me to help out with making Plone/Zope usable under Jaunty.

By default, as everyone should know by now, a whole bunch of old Python 2.4 packages got removed from Jaunty, throwing us Plone developers into peril.  Well, those of us who hadn’t discovered the joys of virtualenv yet, that is.

Here’s how to convert an existing buildout folder over to Virtualenv without too …

Plone: URL Encoding In A Script

So, for today’s problem, how can we get a URL (specifically the GET request arguments) suitably encoded? Easy, if we’re talking about a Python script that lives on the file system and can be used within Zope/Plone that way. But what about some sort of Python script that has to exist on the Plone site (specifically, creating a PloneFormGen (PFG) Custom Adapter)?

First thing I jumped to is urllib and urlecode: but no luck because you’re unauthorised to import the library in your script. Boo!

After much poking, and Googling for something that I thought should …

Plone: Correcting Page Template Errors Easily

Here’s how to correct pesky problems in your code/XHTML since the line number and column references are slightly useless in the ZMI.

Paste contents from a page or page template from the ZMI into a program like gedit and then the line and column reference numbers will be correct (once you remove the comment about the error from the top of the page).

Editing in the ZMI is a bit painful, but we persevere.