Site Scene

Posts Tagged ‘product’

Plone, Dexterity, and Incorrect Widgets

A nice ‘gotcha’ is the distinction between Zope’s schema.Date and schema.Datetime. The difference is obvious and straightforward when the two terms are laid out side-by-side: one is for dates only and the other adds a time component. Where things fell down for me in my usage of these fields with a Dexterity-based content type in Plone is the human component. When these fields are mashed in together within a lot of other text/Python/names, it’s easy to miss those 4 little letters of ‘time’. This lead me trying to use a DatetimeFieldWidget when I really could only use a DateFieldWidget. Wrong widget for the wrong type = unpredictable. (more…)

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

Plone/Zope: Utilising zope.testrecorder for unit testing

Writing unit tests (especial doctests) for your Plone product is reasonably time consuming. For us developers, having tested code is absolutely essential. This is especially true when clients are beating down your door looking for a fully functional product and you need to know what you’ve written works and isn’t going to fall over (just yet, anyway). Web apps are able to be tested using a multitude of frameworks, and whilst not the most fully featured (eg lacking Javascript support), Zope’s doctest machinery is right there within your Plone product. In order to write these, enter zope.testrecorder to more-or-less automate replicating your actions into tests. (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.

Plone: Re-ordering Viewlets

Just responded to a post on the Plone Nabble forums (here) about how to re-order viewlets.  In particular, this one is little different (but not terribly so) because the original poster wanted to put the breadcrumbs above the global sections (global tabs in Plone).  Normally, this is straight forward because you just use a Generic Setup profile (viewlets.xml) and use an order manager to move your viewlet.  This, however, is a teeny bit more complicated because you’ve got one viewlet that’s outside of another viewlet manager. (more…)