Personal tools

You are reading the articles stored in English

Oct 16, 2009

Fast content import

Filed Under:

For one of our customers we have implemented a prototype for fast importing data to Plone. Instead of creating thousands of Archetype-based objects - we are creating only brains. Real objects will be created manually by users. The difference is huge.

The task was simple - import to Plone 36.000 documents (with all children it gives the total of 120.000 objects). Simply creating it using invokeFactory will take too much time (aprox. 14 hours). Why not create just brains and let users decide which document fully migrate? This is what we did.

We started with import script which creates brains in portal_catalog using directly catalog_object method:

pc = getToolByName(self.context, 'portal_catalog')
pc.catalog_object(dummy_object, dummy_object.path)

 

dummy_object is a simple python object with all metadata that we need later for portal_catalog query:

>>> pp dummy_object.__dict__
{'title': u'dummy title',
'id': u'simple_id',
'review_state': 'private',
'path': '/plone/importfolder/ToBeMigrated_simple_id'}

 

After lunching the script (it took 19 minutes) we had all the brains (36.000) in portal_catalog with proper metadata/index updated. Now we need to allow users to see them. So we created traverser for our importfolder:

def __bobo_traverse__(self, REQUEST, name):
    if name.startswith('ToBeMigrated'):
       view = getMultiAdapter((self, self.REQUEST), name='to_be_migrated')
       view.setBrainId(name)
       return view
    return super(ImportFolder, self).__bobo_traverse__(REQUEST, name)
 

which returns a simple BrowserView with the brain.id. The view has a template which informs end-user that this document need to be migrated. If he decided to import it - system will start import process for selected brain.id.
The rest is pure Plone folder_contents view which lists my 'dummy' brains in import_folder (cause the path in the brain is correct). Simple and much faster ;-)

 

 

Oct 14, 2009

New version of redturtle.video

Filed Under:

Released version 0.2.0beta of redturtle.video

A new version of redturtle.video was released on pypi:

http://pypi.python.org/pypi/redturtle.video/0.2.0beta

The package redturtle.video is a video support for Plone, based on collective.flowplayer.
In the new version of redturle.video two new fields are added to content types Video files and Video link. These new fields are "Year" and "Duration".

The information on the lenght of video is achieved through the use of packages: 'hachoir_core', 'hachoir_metadata' and 'hachoir_parser'.

The "Video Gallery" portlet shows content image fields taken from videos. In the new version "Video Gallery" portlet shows also the new informations on the year and duration of the video and also the title of the video.

Oct 06, 2009

Improve the compatibility of collective.plonetruegallery

Filed Under:

I created a branch of the product collective.plonetruegallery, extendible.gallery, which allows to use the features of the package for new types of content and not only for the type "Gallery".

I tried to use the functionality provided by the product collective.plonetruegallery, such as the view "gallery", for my content type, and I had a problem: these features are applicable only to the content type "Gallery". This is because in the code of the package conditions are evaluated on the value portal_type of the content type, eg. if(object.portal_type == 'Gallery').

So I changed some parts of the original product by ensuring that the controls are no longer performed on the value portal_type of the type of content, but on the interfaces implemented by the type of content. In this way the functionalities of collective.plonetruegallery can be applied to any type of content, different from "Gallery", if it implements the interface "IGallery", eg.: IGallery.providedBy (object).

I take advantage using my content type "Cartridge" that extends ATBTreeFolder, which functions as a folder can hold a large number of elements, rather than the type of content "Gallery" which is not a large folder, and then was not suitable for my purposes. But the point is that I could still use the view "gallery" of collective.plonetruegallery to view images from the cartridge, because my type of content implements the interface "IGallery".

I have proposed these changes to the developers of the product and now see if they are interested in applying this modern approach!

Oct 04, 2009

Hidden Javascript Jewels inside Plone!

Filed Under:

The basic Plone installation rely on some little javascript sources that can be very useful.

Right now Plone is filled with a lot of jQuery javascript script for obtain UI effects. Every time you need an effect that Plone has, you must before ask to you: I'm sure that I only need to write down some good HTML, and nothing more?

Please not that even if this page try to integrate the same examples reported, you can't really see them working due to CSS issue. Use Firebug "Inspect element" feature to see how the javascript is changing the DOM.

Expand/collapse like "history" does

The javascript jem responsible of this is collapsiblesections.js.

It's javascript docstring says:

/* - collapsiblesections.js - */
/*
 * This is the code for the collapsibles. It uses the following markup:
 *
 * <dl class="collapsible">
 *   <dt class="collapsibleHeader">
 *     A Title
 *   </dt>
 *   <dd class="collapsibleContent">
 *     <!-- Here can be any content you want -->
 *   </dd>
 * </dl>
 *
 * When the collapsible is toggled, then the dl will get an additional class
 * which switches between 'collapsedBlockCollapsible' and
 * 'expandedBlockCollapsible'. You can use this to style it accordingly, for
 * example:
 *
 * .expandedBlockCollapsible .collapsibleContent {
 *   display: block;
 * }
 *
 * .collapsedBlockCollapsible .collapsibleContent {
 *   display: none;
 * }
 *
 * If you add the 'collapsedOnLoad' class to the dl, then it will get
 * collapsed on page load, this is done, so the content is accessible even when
 * javascript is disabled.
 *
 * If you add the 'inline' class to the dl, then it will toggle between
 * 'collapsedInlineCollapsible' and 'expandedInlineCollapsible' instead of
 * 'collapsedBlockCollapsible' and 'expandedBlockCollapsible'.
 *
 */


This piece fo code can be great for obtain the same sexy expand/collapse feature that you see all around Plone UI.

For example, I can use here this code:

<dl class="collapsible collapsedOnLoad">
    <dt class="collapsibleHeader">
      See the RedTurtle Hidden logo
    </dt>
    <dd class="collapsibleContent">
      <img alt="The RedTurtle Logo" src="http://www.redturtle.net/logo.jpg" />
    </dd>
 </dl>


And what is the results?

See the RedTurtle Hidden logo
The RedTurtle Logo

Dropdown menus

Wow! Can you believe that the dropdown menus you see in the working area of Plone (like "View", "Add portal content", ...) are only a piece of simple HTML and a magic javascipt does all the work?
The script this time is dropdown.js.

It says:

/* - dropdown.js - */
/*
 * This is the code for the dropdown menus. It uses the following markup:
 *
 * <dl class="actionMenu" id="uniqueIdForThisMenu">
 *   <dt class="actionMenuHeader">
 *     <!-- The following a-tag needs to be clicked to dropdown the menu -->
 *     <a href="some_destination">A Title</a>
 *   </dt>
 *   <dd class="actionMenuContent">
 *     <!-- Here can be any content you want -->
 *   </dd>
 * </dl>
 *
 * When the menu is toggled, then the dl with the class actionMenu will get an
 * additional class which switches between 'activated' and 'deactivated'.
 * You can use this to style it accordingly, for example:
 *
 * .actionMenu.activated {
 *   display: block;
 * }
 *
 * .actionMenu.deactivated {
 *   display: none;
 * }
 *
 * When you click somewhere else than the menu, then all open menus will be
 * deactivated. When you move your mouse over the a-tag of another menu, then
 * that one will be activated and all others deactivated. When you click on a
 * link inside the actionMenuContent element, then the menu will be closed and
 * the link followed.
 *
 */


So you only need to design an HTML dl structure like this:

 <dl class="actionMenu" id="myDummyMenuId">
   <dt class="actionMenuHeader">
     <a href="some_destination">Open the magic dropdown</a>
   </dt>
   <dd class="actionMenuContent">  
       <img alt="The RedTurtle Logo" src="http://www.redturtle.net/logo.jpg" />
   </dd>
 </dl>


Here follow the example usage

Open the magic dropdown
The RedTurtle Logo

Conclusion

There is a lot of Magic behind Plone, but thanks to jQuery and a smart infrastructure you can use this Magic for your needs!

Sep 24, 2009

How to revive an unstartable Plone 3.2.2 under windows XP Pro SP3

Filed Under:

You may have experienced erratic behaviour from installations of Plone under Windows XP. This contribution, based on my personal experience and on what I found searching the web, will hopefully let you fix a Zope service that become unstartable without any apparent reason, or at least find a workaround by running runzope.bat from the command line.

In mid-september 2009 I downloaded and installed successfully the Plone 3.2.2 bundle for windows, including Python and Zope 2.something (you already understood that I am not an expert in the field).

Plone worked fine, I customized my local installation (to be used for demo purposes) without any problem.

After two days without using Plone (that I usually started from the "Plone Controller" application) I found that the "Plone Controller" could not start anymore the Zope instance. The Zope instance service - even though marked for automatic start - could not be started, the windows system log messages were useless (error 01x, no explanation).

In similar situations, usually Zope may be started by runzope.bat from the command line: I tried that workaround that proved effective, even though I did not engage in a full set of site update and configuration: some posts in technical fora suggest that this solution does not necessarily provide a fully working Zope / Plone instance.

Not fully satisfied with the workaround, I explored the Web for solutions, and here is what I found and applied successfully (ZI = Zope instance, PC = Plone Controller, RZ = Runzope.bat). All the paths are the default paths resulting from a default run of the Plone Win 32 bit installer. Here is a sequence of all the steps, problem and solution.

  • ZI could not be started by PC - issues error message in endless cascading pop-ups
  • Plone local site (in my case, http://localhost:8080/PloneCesare) is obviously inaccessible
  • At this stage, ZI *could* be manually started by RZ, issuing from the command line: 
C:\Programmi\Plone\parts\instance\bin\runzope.bat
  • Plone local site http://localhost:8080/PloneCesare now is accessible, but PC is not aware that ZI is started, as long as PC "sees" only the Zope service, not the manually started instance
  • Zope Instance service (default name:"Zope instance at C:\Programmi\Plone\parts\instance") remains unstartable. Furthermore, it does not seem to retain the parameters set from the Windows "Services" interface.
  • To solve the issue, I reset the service options, by issuing from the command line:

 C:\Programmi\Plone\python\python.exe C:\Programmi\Plone\parts\instance\bin\zopeservice.py --startup auto install


The execution returns the following lines:

Installing service Zope_78966557
Changing service configuration
Service updated

 

  • Then, still not entirely trusting the Windows Service interface, I try to start the service manually:
  •  C:\Programmi\Plone\python\python.exe C:\Programmi\Plone\parts\instance\bin\zopeservice.py start
  • Execution returns the following line:
  • Starting service Zope_78966557
  • Now the plone controller sees that the instance is running and enables all its functions, including the ZMI
  • Under "Services", the service is up and running
  • Service may be freely started and stopped both from the PC and from the window's "Services" panel. 
  • Plone works fine
  • Please note that most of the information available on the Web about similar issues refers to older Plone versions, and may not apply to the newest releases. Please note also that Win XP Home may behave in a different way.