Plone: Under the Hood

Posted by Peter Burkholder Mon, 17 Apr 2006 07:00:00 GMT

My presentation notes from April, 2006. A comparison of TTW (through-the-web) to filesystem-based development with Plone. What's new here is how to modify portal_actions and portal_tabs in an install script.

Prerequisites

Have the following downloads in ~/Projects/plone/Downloads

  • DIYPlone

Immediately prior to presentation

  • Fresh reboot and all apps off
  • Delete test svn directory
  • Rm -rf ~/Projects/plone/Zope
  • Set display not to sleep
  • Start Snapz X pro
  • Start with Plone 2.1.2 already downloaded and Admin password already set
  • Start Apps. Safari will be used for anonymous view, Camino for admin, Firefox for PeterB, Mozilla for talk (or paper), TextMate for Editing

Goals for today

  • Understand the difference between Zope and Plone, and how to install Plone in Zope
  • Understand how to create a Plone site in Zope, and preform basic content customization
  • Understand why skin development is importance for scaling and maintenance

Getting started

We have a Mac OS 10.4.5 with Python 2.3.5 as part of the OS, Zope 2.8.6 built from source in to /usr/local/bin (note that the Plone packaged install uses Zope 2.7.X, and Zope builds well in MacOS)

  • Make a local zope instance:

    cd ~/Projects/plone
    /usr/local/bin/mkzopeinstance.py # Enter "Zope" for dir, and peterb for user
  • Enter admin info, then:

    cd Zope
    tar -zxf ~/src/Plone-2.1.2.tar.gz
    mv Plone-2.1.2/* Products/
  • Set debug mode on by setting "debug-mode on":

    mate etc/zope.conf
    bin/zopectl start
  • Create our site (in Camino)

    • Open ZMI at http://localhost:8080/manage
    • Create wag site: "Plone Site" [Add] (make sure Id is lowercase)
    • Open wag in ZMI and note all the objects available for customization
    • Login and update page: Welcome to Web Advisory Group

Creating a distinctive WAG site

Let's compare the default plone site at localhost://8080/wag to the WAG 2.1 site at http://tremor.dpc.ucar.edu:9508/wag (soon to be at www.ucar.edu/wag). The WAG site is to have a cleaner design (configuration, and some configuration) and a distinctive style (skin) and navigation and text (content) appropriate to our needs.

Content customization

This is easy, and done through Plone

  • Hide unneeded folders: Make "Members" "News" "Events" private (only allowed for Owner/Manager)
  • Create "Projects" and "Meetings" folder and "Publish"

Configuration changes

Now we need to jump into the ZMI, and do some "Configuration" changes to clean up the site

  • Show blocks in Firefox

  • Each block is governed by
    • whether the configuration has it on or off
    • whether it is rendered in the template (a dynamic page description in DTML, TAL, MeTAL)
    • whether the CSS is displaying it (e.g. .display: None will turn off an item)
  • Various aggregates of these are called Skins, each which has a structure determined by templates (in DTML, similar in form to JSP or PHP markup) and the CSS for that object -- fewer changes to templates make site more portable

  • Point everyone to the "Where is What page":http://plone.org/documentation/tutorial/where-is-what/whereiswhat of the Plone site. This is 15 pages so I've not printed it for you.

Anyhow, using that as a guide I can make the following changes

  • ZMI -- wag (properties)
    • get rid of all portlets in site
  • ZMI -- wag -- portal_membership (actions)
    • look for "Log In" and change to ">Administrator Login<"
  • ZMI -- wag -- portal_actions (actions)
    • disable: accessibility, site maps, site setup, contact
  • ZMI -- wag -- portal_registration (actions)
    • get rid of "join" link

This is an awful lot of configuration to commit to the ZODB, where we can't easily manage changes, or scale them across multiple sites.

When I first did this, to make the UCAR tab on the right side, I needed to use the ZMI to make another 'portal_action' called UCAR in the 'portal_tabs' category, then use the awful ZMI interface multiple times to move it above the default portal_tab, 'index_html'.

There's rumour on the Plone site that these configuration changes can be tracked by making the changes in the ZMI, then exporting the changes as XML on the filesystem, and having that be portable, but I don't see that in production. I think it'll be in Plone 2.5 and Zope 3.

As we'll see below, one can write an Install.py script with a product, and use the programmitic API to make the UCAR tab.

Now compare the Default Site and the WAG site (we may have to make a "Plone" site for comparison)

Skin/Style Customizations

Key point: code and customizations on the filesystems, content and configuration in to ZODB

Key point: presentation of content is called a skin. We're looking at the default skin. The skin can be customized either TTW (through-the web) or by building a skin product. First we will do it TTW (and show the drawbacks to that)

  • ZMI -- wag -- portal_skins -- plone_styles -- base_properties -- customize (note that this has been deprecated, but there's no info on what it's been replaced by)

  • Customizing will create base_properties in portal_styles -- custom -- base_properties

    change Text and Line Width (be sure to tick checkboxes)

  • view it

  • undo it: The entire zope site is kept with one potentially very large database called the ZODB that's kept in the fileystem in var/Data.fs. We'll say more about that later....

Reasons for using Filesystem devel instead of TTW

  • TTW makes for a very messy undo list in your ZODB
  • TTW makes it hard to know happened where, when
  • Filesystem lets you find bits of code with grep, find
  • Filesystem lets you use a real version control system
  • Filesystem lets you save skin variants for management to review
  • Filesystem lets you use your favorite editor!

Create WAGSkin product for on-the-filesystem development

Download DIYPloneStyles, generate "fresh" WAGSkin, and open in TextMate:

cd ~/Projects/plone/Zope/
wget http://plone.org/products/diyplonestyle/releases/1.0.5/diyplonestyle-1.0.5.tar.gz
cd Products && tar -zxf ../diyplonestyle-1.0.5.tar.gz
DIYPloneStyle/bin/generator.py --productname WAGSkin # Note: this must be using python 2.3.5
cd WAGSkin
mate .

(Note that we're using diyplonestyle 1.0.5 The recently released 2.1.X series doesn't automatically include the base styles, so you have to turn that on yourself, which I've not yet figured out, or build all styles from scratch)

Commit fresh WAGSkin to Subversion:

svn mkdir -m "committing fresh WAGSkin"  http://svn.dpc.ucar.edu/test/plone
svn mkdir -m "committing fresh WAGSkin" http://svn.dpc.ucar.edu/test/plone/Products
svn mkdir -m "committing fresh WAGSkin" http://svn.dpc.ucar.edu/test/plone/Products/WAGSkin
cd ~peterb/Projects/plone/Zope/Products/WAGSkin
svn co http://svn.dpc.ucar.edu/test/plone/Products/WAGSkin/. .
svn status
svn add skins Extensions
svn commit -m "committing fresh WAGSkin"

Add product to site (this may not be absolutely necessary with debug-mode on):

~/Projects/plone/Zope/bin/zopectl restart

Browse to "Plone control panel":http://localhost:8080/wag/ -- Site Setup -- Add/Remove Products

Make sure to refresh browser (Firefox: Command-Shift-R or CTRL-Shift-R)-- and if this isn't working for you, remember to have debug-mode on in your zope.conf

Customize WAGSkin

Now lets tune up this site

  • open skins/wagskin_styles/base_properties.props

  • change backgroundColor to Yellow, reload

  • now replace the banner with Sylvia's work (and change reference in base props):

    svn cat http://svn.dpc.ucar.edu/test//plone-works/Products/WAGSkin/skins/wagskin_styles/wag_banner.png > wag_banner.png
    svn cat http://svn.dpc.ucar.edu/test//plone-works/Products/WAGSkin/skins/wagskin_styles/listspacer.gif > listspacer.gif
    svn add listspacer.gif wag_banner.png
    svn commit -m "Graphics"
  • now replace whole base props document with what we have that works in Subversion:

    svn cat http://svn.dpc.ucar.edu/test//plone-works/Products/WAGSkin/skins/wagskin_styles/base_properties.props
  • and view the changes with svn diff. Commit to Subversion

  • now change the CSS, but checking out what I already have in subversion:

    http://svn.dpc.ucar.edu/test/plone-works/Products/WAGSkin/skins/wagskin_styles/wagskin.css.dtml
  • commit to Subversion

Next, we'll modify Extension/Install.py and Extensions/util.py to insert a custom UCAR tab on the right side. This use of the API could be used to do all of the ZMI changes we did above to remove unnecessary links.

  • For the sake of preserving indentation, we'll do this, then describe what's happened:

    # remove product from wag site
    zope stop
    cd ~//Projects/plone/Zope/Products/WAGSkin/Extensions
    svn cat http://svn.dpc.ucar.edu/test/plone-works/Products/WAGSkin/Extensions/utils.py > utils.py
    svn cat http://svn.dpc.ucar.edu/test/plone-works/Products/WAGSkin/Extensions/Install.py > Install.py
    zope start
  • Show diffs in TextMate

  • All of this accomplishes editing Extensions/utils.py and adding near the top:

    from Products.CMFCore.permissions import View

    def setupUCARTab(self, out):
    at=getToolByName(self, 'portal_actions')

    at.addAction('ucar_tab',
    name='UCAR',
    action='string:http://www.ucar.edu',
    condition='',
    permission=View,
    category='portal_tabs',
    visible=1)

    print >> out, "Added UCAR Tab"

    # Move index_html to the bottom
    # (cribbed from ConfigurationMethods.py in CMFPlone)
    cloned_actions = at._cloneActions()
    num_actions = len(cloned_actions)
    state_index = 0
    for action in cloned_actions:
    if action.id == 'index_html' and action.category == 'portal_tabs':
    break
    state_index = state_index + 1
    state_action = cloned_actions.pop(state_index)
    cloned_actions.append(state_action)
    at._actions = cloned_actions

    print >> out, "Moved Home Tab"
  • and editing Extensions/Install.py and adding the following to the install(self) function:

    setupUCARTab(self,out)

What have we accomplished?

After doing some ZMI stuff, we've moved our development for graphics to the filesystem and into Subversion Demonstrated how to move at least one ZMI action, adding a portal_tab, into an Install script We can switch between multiple skins, which is great for prototyping graphics for various audiences.

Extending Plone with an Archetype-based custom Content Type

I've been wanting to make a site where I can keep a public record of the rare outages at DLESE.org, and I decided to try Plone's Archetypes product to create a custom "Outage" content-type. Let's see what it looks like, then how it's made

  • Checkout and restart:

    cd ~/Projects/plone/Zope/Products
    svn co http://svn.dpc.ucar.edu/sysadmin/trunk/plone/Outage
    zope restart
  • Install in Plone Add/Remove products, then go to home page and add new "Outage"

  • Enter sample data for Title, Description, Start Time, Duration, etc. Enter a bad email and see how it fails nicely

  • Enter again, but see that if fails badly with an alpha in an Integer field -- but there's not a corrups "Outage" in the folder

  • So change all the integer lines to something like:

    IntegerField('expected_hours', validators=("isInt")),
  • Restart Zope, and test if there's time

  • The next steps would be to create a custom folderish type, OutagesFolder, that organized multiple outages by date, and edit .pt files to display nicely. Also, add logic to send email updates to indicated groups.

Hosting Plone

The ZODB

Everything in Zope on kept in the Zope Object Database, or ZODB, which is the flat file var/Data.fs. It's transactional, and each new transaction is appended to the end so you can undo all the way back until the last time it was packed. You'll need to regularly pack it and back it up. See "Maintaining Zope":http://www.zope.org/Documentation/Books/ZopeBook/2_6Edition/MaintainingZope.stx

Apache Integration

You'll probably use Apache as a front-end. You'll have parts of your site that aren't zope, you may host multiple Plones, you'll want to use mod-cache, you want a more robust HTTP server.

Here we show how to host the wag site using Zope's virtual hosting tool in several of the hosts wag.ucar.edu (at the top level), itc.ucar.edu (as a site at /wag), and plone.ucar.edu (in /itc/wag). In all these cases the Zope server is on port 8080 and the Apache is on port 80, both on the same localhost. The config is much the same for different hosts.

Virtual hosting with several sites per Zope server and dedicated virtual host for each site The folder http://localhost:8080/wag/ should be accessible as http://wag.ucar.edu:

<VirtualHost *:80>
ServerName wag.ucar.edu
RewriteEngine On
RewriteRule ^/(.*) http://localhost:8080/VirtualHostBase/http/wag.ucar.edu:80/wag/VirtualHostRoot/$1 [L,P]
</VirtualHost>

Inside Out Hosting 1: The folder http://localhost:8080/wag/ should be accessible as http://itc.ucar.edu/wag:

<VirtualHost *:80>
ServerName itc.ucar.edu
RewriteEngine On
RewriteRule ^/wag/?$ http://127.0.0.1:8080/VirtualHostBase/http/itc.ucar.edu:80/VirtualHostRoot/wag/ [L,P]
RewriteRule ^/wag/(.*)$ http://127.0.0.1:8080/VirtualHostBase/http/itc.ucar.edu:80/VirtualHostRoot/wag/$1 [L,P]
</VirtualHost>

Inside Out Hosting 2: All the folders in Zope/Plone are itc committee sites, so http://localhost:8080/(whatever)/ should be accessible as # http://plone.ucar.edu/itc/(whatever):

<VirtualHost *:80>
ServerName plone.ucar.edu
RewriteEngine On
RewriteRule ^/itc/wag/?$$ http://127.0.0.1:8080/VirtualHostBase/http/plone.ucar.edu:80/wag/VirtualHostRoot/_vh_itc/_vh_wag/ [L,P]
RewriteRule ^/itc/wag/(.*)$ http://127.0.0.1:8080/VirtualHostBase/http/plone.ucar.edu:80/wag/VirtualHostRoot/_vh_itc/_vh_wag/$1 [L,P]
</VirtualHost>

Posted in  | 1 comment | no trackbacks

Comments

  1. sito di casino said 680 days later:
    Il nostro sito di casino è zeppo di contenuti meravigliosi sui giochi e non vi deluderà.

Trackbacks

Use the following link to trackback from your own site:
http://typo.pburkholder.com/articles/trackback/14

(leave url/email »)

   Preview comment