Site Scene

Posts Tagged ‘python’

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: (more…)

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. (more…)

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 (email, password, calendar_url, start_time, end_time, title, location, content).
      • Email/password are your auth details
      • calendar_url is where you’re putting the event,
      • and the rest of the args are related to the event itself.
    • It builds the XML-based request to create the event.  I tried going for the gdata API, but it’s just over the top for a simple exercise like this.
    • Send the request to Google (twice, as required), and create the event in the process.
  • A custom PFG script adapter like this:

    from DateTime import DateTime
    from my.theme.Extensions.GoogleCalendar import createGoogleCalendarEvent
    calendar_url = ‘http://www.google.com/…’
    email = ‘myu...@google.com
    password = ’shhhhhsecret’
    startDateTime = (DateTime(str(fields['start-date-time']))).HTML4()
    endDateTime = (DateTime(str(fields['end-date-time']))).HTML4()
    eventTitle = str(fields['purpose'])
    eventLocation = str(fields['rooms-to-book'])
    eventContent = ‘Booked for: ‘+ str(fields['booking-name'])
    createGoogleCalendarEvent(context, email, password, calendar_url, startDateTime, endDateTime, eventTitle, eventLocation, eventContent)

And that should be that.  As long as all your URLs, emails, passwords, and fields in your form are suitable, this should work a treat.  Note that the start-date-time and end-date-time fields are date/time fields in your Form Folder and converting to HTML4() makes them into Google’s format.  Additional info can be added in the eventContent variable, and that’ll turn up in the Description in Google Calendar.

For added spice…

Just add a web interface to your Google Calendar to your Plone site (eg in a normal Plone page; watch out for iframe filtering) and let people book themselves into things.  Would be great to see PFG know when a Google Calendar event was on (and stop people submitting) but it’s a bit much just for now.

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. (more…)

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 it to the same setup. (Note: actually, there was a setuptools RPM that I installed, but nfi why it didn’t give me easy_install…) (more…)