Some Plone tips

To add a tab in the green tab bar, go to portal_actions/object and add an action.

Some useful expressions:

  • string:${context/portal_url}/folder/document
  • python:portal.restrictedTraverse(‘@@plone_context_state’).current_page_url()==”testurl”

Note the python expression portal.restrictedTraverse allows python expressions/scripts to access the new browser views

Comments off

Top 25 Programming Mistakes.

Mitre has published the top 25 programming mistakes that lead to security breaches.

Cross-site scripting is number one, with SQL Injection and buffer overflow following.

Comments off

Plone Main Template Slots

Here is the list of slots that are defined in the master page template for Plone.

  • HEAD slots
    • base
    • head_slot
    • style_slot
    • javascript_head_slot
  • BODY slots
    • content
    • body
    • main (for most cases use this instead of content or body)
    • sub

To use one of these slots (for example, “style_slot”) use the metal:fill-slot macro

<style metal:fill-slot="style_slot" type="text/css">
 table.LesionLocation {border:1px solid blue;border-collapse:collapse;}
 table.LesionLocation td {border:1px solid black;padding: 5px;}

The page template must reference the master template:

<html xmlns="" 
xml:lang="en" lang="en" i18n:domain="plone"

Comments off

Updating XNAT

A quick paste of a newsgroup post that outlines the steps necessary to update the xnat distribution from cvs.

To update from RC1, you should:
 cvs update -d
 bin/ -Ddeploy=true
 psql -f deployments/PROJECT/sql/PROJECT-update.sql
The only thing I added to the schema this round were a few parameters for
configuring access to DICOM server.  Those are used on that settings page,
so it would make since that the save would fail if those columns didn't
exist in the db.
Try running the referenced -update.sql, and restarting Tomcat.

Comments off

[QN] MRI Facts


  • DCE-MRI: Dynamic Contrast Enhanced MRI.
    • T1 Longitudinal Relaxation
    • Parameters
      • Ktrans: Tissue perfusion and Microvascular vessel wall permeability
      • Ve: Extracellular volume fraction
  • DSC-MRI: Dynamic Susceptibility MRI.
    • T2 Transverse Relaxation
    • Parameters
      • Blood flow
      • CBV Blood volume
      • MTT Mean Transit Time

Comments off

[QN] How to convert month name to month number in Python

For a short script I was writing I needed to convert a string representation of the month (“month name”) into a numerical value (“month number”). A quick google led to many solutions to the inverse problem, which to me seems a lot easier. Here is a quick and dirty solution that uses the calendar module.

import calendar

I chose to use the calendar module array month_name because I would rather not have to create a list of month names myself.

Comments (1)

XNAT Cheatsheet

At my workplace I am tasked with getting familiar with and eventually customized XNAT, a Java/Tomcat web-based content management system for the health care industy. As this is the first time I am working with a Jave web application, the learning curve is particularly steep. Here are my running notes as I try to get familiar with Java/JSP/XNAT. I must say though that I think Plone/Zope or even an ASP.Net system would have been a lot easier to understand!

  • Top level directory for xnat
    • Inside the VM (from NRG):
      • /mnt/hgfs/Shared/Workspace/xdat_release
      • Also, /usr/local/NRG/Shared/Workspace/xdat_release
    • Inside the host OS
      • ~/s/prog/xnat_rc1/Virtual-XNAT/Shared/Workspace/xdat_release
  • Directories @ top level
    • bin: Contains maven batch script, and batch scripts to “deploy” XNAT from the top level directory to the tomcat directory (/usr/local/NRG/Applications/tomcat/webapps/xnat)
    • With Eclipse set up properly, there is no need to run the batch scripts.
    • From the website:
      • SUMMARY: The file is located in the root directory of the XNAT package.  The file contains the location of your Tomcat installation and details about your database connections.  The variable will become the name of the generated project.  This will become the name of any generated webapps as well.  The xdat.project.template variable specifies whether or not your new project will use a template.  To create an XNAT project, this variable must be set to ‘xnat’.  Set the db name and connection information to your postgres installation. (This db connection string/name should point to a pre-created empty database of this name).  The initial is set to create an xnat project called ‘xnat’.  You simply need to create an empty database called ‘xnat’ (see step 2) and set the appropriate user name and password.  Also, the maven.appserver.home variable must be set to reference the root directory of your local Tomcat installation (abslolute path).
    • projects: Again from the website: XNAT will generate a folder in this directory for each of your projects. When you make customizations to your XNAT project, you will modify the files in this directory. These modifications will then be processed by the setup or update script.
    • deployments: XNAT will generate a folder in this directory for each of your projects. It stores the settings for your command line tools. It will also be used to generate your web application via the setup or update command.
      • If I need to modify a template, I have copied the template (a Velocity macro, .vm) from the deployments/xnat/src/xnat-templates/screens folder to the projects/xnat/src/templates/screens folder and edited it in Eclipse. On a deploy-templates operation, the web site is updated with the template content. (Note that for .vm file changes a full rebuild is not necessary.)
  • Deploying to Tomcat
    • This can be done in several ways, including using Eclipse, but on the command line running bin/ -Ddeploy=true from the root directory works.
  • Customizing XNAT
    • From the website: Note: The XNAT framework looks for custom code, including additional schemas, in the XNAT_HOME/projects/PROJECT directory.  To make your customizations take effect, run the bin/update process from the XNAT_HOME directory.  This process updates the XNAT_HOME/deployments/PROJECT directory, which will contain your customizations and XNAT-generated code to support these customizations, and deploy it all to your webapp (WAR).
    • I am currently on this step, and will update this when I am successful

Comments off

Allow ssh access to a Fedora 10 machine (VM)

I have been setting up several Virtual Machine’s lately , to test deployment in various linux environments. I must say I have been frustrated with the way linux handles shared libraries. The DLL hell that many people complain about on Windows machines is nothing compared to the interdependencies of shared libraries! (Statically linking everything was not an option, as I was unable to successfully statically compile Python + wxWidgets + wxPython + Numpy)

Once a Fedora 10 VM has been set up, I need to do the following:

  • system-config-firewall   Turn off the firewall
  • chkconfig –list sshd   Confirm whether sshd is running or not
  • Assuming it isnt running in modes 3 & 5,
    • chkconfig sshd on
    • service sshd start

Comments off

wxPython on Linux (GTK) Annoyances

It is very fashionable to gripe about Windows short comings and brag that Linux solutions are always better, more bug-free, etc. I have come to the opposite conclusion in the case of wxPython and Windows/Linux development. Programming on Windows just works. Linux (or more accurately the GTK platform on Linux) is very frustrating because of the quirky behavior in a surprisingly wide variety of cases.

  • the File Browse Button widget (wx.lib.filebrowsebutton) had a bug that appears on GTK (but not Windows). If the value of the associated text control points to a directory or file that does not exist, clicking on the Browse button causes an assertion error. More info (and the fix) is here, summarized below:
    • This is the same error as discussed in for (I am using
      but apparently the fix didn't carry over or fix this particular case.

      "Simple fix is to add a line that blanks out the file part when the
      directory is not found." is what it says but my source for doesn't actually blank out the file part.

      current = ''

      in the else clause around line 161 fixed it.

      directory = self.startDirectory
      current = ''
      dlg = wx.FileDialog(self, self.dialogTitle, directory, current,self.fileMask, self.fileMode)

  • Default fonts are sometimes (but not always!) larger than the encapsulating control. Pull down menus especially suffer from this on GTK, and I have to write special case code to check whether the program is being run under GTK, and size the fonts smaller so they are not clipped by the control. Very annoying!
  • StaticBitmap on GTK does not behave as on Windows, with the latter version being more feature full. There is a work around, by using a wx.lib.statbmp.GenStaticBitmap, but this leads to a performance hit, so I need to special case this as well for GTK.
  • More to come as I struggle with cross-platform programming.

Comments off

Statically Linking Python 2.5, wxPython, Numpy

  • These instructions still do not work (I get a seg fault) so this will be updated until I get a working setup.
  • Follow these instructions, but note the following caveats
    • Instead of –enable-static, use –disable-shared
    • Copy distrib/ to the top level wxPython directory and save its output to Setup.local
    • Copy Setup.local to the Python src/Modules directory
    • On my setup, I had to edit Setup.local and delete all -pthread instances
    • After configuring Python, edit the Makefile so thatlib stdc++ is linked in.
    • If you get a libinstall error when you run make install, use make -i install
    • Copy the wx and wx_addons directories from the wxPython source directory
    • If you have trouble with import wx, edit the Setup file in the Python src/Modules directory and add _random operator, and other modules.

    Comments off