Archetypes and ATContentTypes, part 1: The Archetype Schema

All the default types in Plone – file, image, folder – are part of the ATContentTypes product, and are examples of archetypes. Archetypes were integrated into Plone 2.1, and allow you to create content types easily by providing a range of readymade tools so you can generate edit forms without using any HTML.

An example will perhaps best explain how Archetypes works – lets look at the familiar ‘image’ type. The edit form of an Archetype is generated using a schema, and the schema for image can be found in Products/ATContentTypes/content/image.py: here we’ve taken out some of the code to focus on the essentials:

ATImageSchema = ATContentTypeSchema.copy() + Schema((
  ImageField('image',
        required=True,
                ....(lots of other stuff here, to do with image sizing and such).....
        validators = (('isNonEmptyFile', V_REQUIRED),
                      ('checkImageMaxSize', V_REQUIRED)),
        widget = ImageWidget(
                   #description = "Select the image to be added by
                                   clicking the 'Browse' button.",
                   #description_msgid = "help_image",
                   description = "",
                   label= "Image",
                   label_msgid = "label_image",
                   i18n_domain = "plone",
                   show_content_type = False,)),

  ), marshall=PrimaryFieldMarshaller()
  )

That’s all a bit of a mouthful, so we’ll break it up and isolate the essential parts:

ATImageSchema = ATContentTypeSchema.copy() + Schema((
     ImageField(

Every schema contains a collection of fields; in the edit form the short name is one field , the Title is another and so on… The reason we don’t see the title, id, or description in the above schema is they are already defined in ATContentSchema (they are common to all types); the first line of the code joins ATContentTypeSchema to the schema we are creating above.

For an image, there is only one extra field, the ImageField. Lets say we want another field to specify the camera the image was taken with; our schema will then look like:

ATImageSchema = ATContentTypeSchema.copy() + Schema((
      ImageField(   # all the stuff above
           ),

       StringField('camera',
                  required=1,
                  widget=TextAreaWidget(),),

   ), marshall=PrimaryFieldMarshaller()
       )

Archetypes provides many different kinds of field you can include – TextField, BooleanField (for yes/no values) ect. In plone.org there is a list of available Archetypes fields….

OK, lets look at the arguments of ImageField:

ImageField('image',
       required=True,
               ....(lots of other stuff here).....
       validators = (('isNonEmptyFile', V_REQUIRED),
                     ('checkImageMaxSize', V_REQUIRED)),
       widget = ImageWidget(
                                # whatever goes here we'll explain
                                # when we talk about widgets
        )),

 )

The first argument ‘image’ is the title of the field, the required=True puts the little red ‘required’ dot beside the title. Now, the next two are important:

  • validators: these are classes which check that whatever we’ve entered into the field satisfies a set of conditions, and it won’t accept it if it doesn’t. For example, ImageField calls instances of two validator classes: one of them makes sure the uploaded file isn’t empty, and the other rejects the uploaded file if it is too large. There is some readymade validators at Products/validation/validators, although quite often people have the need to add extra ones of their own.
  • widget: the widget is the graphical layout that the field will take; it defines how to render the field into HTML/XML. For example a StringWidget will set out a one-line box; a TextAreaWidget will set out a bigger box, like what is used for the Description. On plone.org you can see pictures of all the available Archetypes widgets ; it is very unlikely you will need to make your own. In many cases, the field type suggests what widget type to use: an ImageField will use an ImageWidget, for example.

The arguments of ImageWidget are quite straightforward:

widget = ImageWidget(
       #description = "Select the image to be added by clicking the 'Browse' button.",
       #description_msgid = "help_image",
       description = "",
       label= "Image",
       label_msgid = "label_image",
       i18n_domain = "plone",
       show_content_type = False,)),

The _msgid label is used by the internationalization (i18n) mechanism to generate translations in other languages.

Ok, one final thing to deal with, the marshaller, this makes Archetype fields understandable to clients such as WebDAV. As you can see above, the schema took two arguments, the field and the marshaller.

Schema (    (ImageField( all the stuff we discussed ),),
                                    marshall=PrimaryFieldMarshaller()
     )

PrimaryFieldMarshaller is the most common marshaller used, apparently.

Ok, so that’s the first part of my ATContentTypes exploration; the second part will deal with the question I first asked when I saw a type schema: how does all this called by a template and end up on our screens?

Selecting content item as default view of a folder (including the /Members folder!)

I always wondered why the ‘Display’ tab containing the ‘select content item as default view’ was sometimes clickable and sometimes not. Well the answer is simple (it always is after you’ve found it): if you have an item in your folder called index_html, Plone will automatically recognise that as the default view item, and you have to rename it before you can access the ‘Display’ tab….

This also goes for the Members folder. By default, index_html will bring up a ‘search for members’ template, which I never found very useful, and always wanted to replace with a nice smart folder. First go into /Members in the zmi, select index_html (it’s in there somewhere amongst all the members), and rename it to something like index_html.old. Now, somewhere outside of Members, create the item you want to have as default view, and paste it into Members with title (guess) index_html.

This is a rather contrived way of going about things, I admit: Atmasamarpan tells me there is an index_home python script which calls index_html as the default view for the Members Large Plone Folder (which I have yet to find). Rename this script and you can access the display tab as normal. (Note: if you dont rename the script and there is no index_html item, you will get a site error when you try to acess the Members folder in Plone),.

Inserting content of Plone document into Zope template

As explained in an recent article titled ‘Edit ZPT content through Plone ‘ on plone.org, we can insert the content of a document called my-document, say, by inserting the following into your template:

<tal:block tal:condition="exists:here/footer-content/my_document"
             tal:replace="structure here/footer-content/my_document/getText">
              Document content here</tal:block>

Perhaps one of these days Plone can use this method so that we can edit footers and colophons directly through Plone; ive submitted a ticket to Plone here…

Perhaps we could even extend it to things like bylines, although that’s a harder kettle of fish as we’re dealing with variables like creator and modification date. Any ideas, anyone?

Negotiating the Plone security maze

If, like me, you have been trying to resolve permission problems by checking and unchecking boxes in the ZMI Security tab in a trial-and-error fashion, there is in fact an easier way (I never doubted Plone for an instant ๐Ÿ™‚ )

  • Before going to the Security tab, you should first find the Actions tab for the process you want to control permissions for. By default, things like the top navigation tabs and the buttons at the bottom of the folder listing are controlled in the Actions tab of portal_actions.
  • Things like the edit, properties and sharing tabs are defined seperately for each item type in portal_types: i.e to access the actions for an image, one would go to portal_types->image and click on the Actions tab. (The Content tab is defined globally in portal_actions).
  • Scroll down to see the action you want to change the permissions for, and you will see the permission you need to change (there are cases where you might want to change this permission: for example, to stop object owners from accessing the properties tab, you would have to change the permission from ‘modify portal content’ to something like ‘manage properties’ and restrict that permission).

Plone Screencasts

Plone have some screencasts which are an excellent introduction to Plone and how it works

Plone Videos

Includes Screencast Editing with Plone

"How to use the Plone content management system to edit both images and text in a site. Demonstrates Plone’s built-in image manipulation and rescaling, as well as its rich text editing capabilities." 12 mins

4 Second Rule for Websites

Users abandon sites that take longer than 4 seconds to load

Shoppers are likely to abandon a website if it takes longer than four seconds to load, a survey suggests.

The research by Akamai revealed users’ dwindling patience with websites that take time to show up.

It found 75% of the 1,058 people asked would not return to websites that took longer than four seconds to load.

More at BBC

CMFLinkChecker

This promises to be a very useful tool for webmasters of large sites or sites with many users. Sure, one could always check broken links using server states, but by having a link checking mechanism in the UI you can let each user in a multi-user site be responsible for keeping their own section 404-free.

The CMFlinkchecker program comes in two parts; the user interface (CMFLinkchecker) and the bit that actually crawls the site (LMS). These are distributed as two seperate programs. You can however, just install CMFLinkChecker and then go to ‘link management’ in plone preferences panel and register your website to access LMS on a server kindly provided by the authors somewhere over in Germany. After a couple of goes (the server might have benn down) I eventually got through and was given an id and password via email to enter in the ‘link monitoring server fields’ in the aforementioned ‘link management’ page. After that, I srolled down to the bottom of the page, hit ‘crawl my site for all links’, and got the ball rolling….

For a small site (around 200 links), about 20% of the links were evalusted straight away, the rest were queued up on the server and were ready the next time I logged in. The process probably goes a lot faster if you have LMS installed on your own server.

Looking at LinguaPlone

LinguaPlone is the standard multilingual translation solution for Plone, and is used to generate translations of websites like Oxfam .

Upon first hearing of LinguaPlone, I was expecting a scenario where the whole page – page body, tabs, portlets, the lot – would obediently translate given the necessary words and a couple of clicks of the mouse. Then again, the open source community was not made for demanding types like me who expects everything without putting in some spadework himself (I am only making my first forays into Python now…:) )

What LinguaPlone offers (so far) is a very easy way to translate the page body. Simply choose what languages you are going to have your site in in Preferences (they are pretty much all there), do up a page in your default language, and access the ‘translate’ tab at the top of the document to translate into the language of your choice. In addition, uninstalling Linguaplone doesn’t affect this translated content, it only removes the links between the different translations, which can be restored by reinstalling the product.

All the same, it’s a little hard to know if LinguaPlone offers all that much more convenience and functionality over manually creating new content for each language yourself. I’m sure it does, else it would not be so widely used, but the lack of decent documentation doesnt help much to illumine me. For example, a cool thing would be if LinguaPlone used the IP address of your computer to automatically serve you up the content in your own language – its a rather intuitive thing and one might reasonably expect a multilingual solution to have this facility. It’s not an easy thing to test (unless you have access to a private plane), and so I dont really know if it does this…..

(If my interest in Linguaplone persists over the next couple of months, I promise I will document answers as I find them here)

One thing that would really enhance LinguaPlone, in my view, is if translated objects could inherit the properties of the original object. Perhaps I want to use a couple of portlets in left_slots: in current LinguaPlone, I put the portlets in for a page, but they are not there for their translated counterpart. Not everyone will want this of course, but it would be nice if it were included as an option, along with an option to automatically update translation properties if the default properties are changed. Perhaps all the contents of the ZMI properties tab could even be displayed in the 2-column ‘translate’ page, and the user could pick which ones he wants to keep.

The top navigation bar tabs are a known issue with Plone multilingual sites, but if property inheritance were allowed the subsite feature of our vsCore product could then be enabled for those sites whose tabs bear the names of the content they point to.

Mozilla 2.0

This week Mozilla released the latest version of its popular Firefox browsers. Among the main benefits of Firefox 2.0 include:

  • Enhanced security Features new anti-phishing functionality, (identify’s scam sites)
  • Improved tabbed browsing.
  • Recovers your opened tabs if computer unexpectedly crashes. This will also save a half finished blog entry. – could be very useful.
  • More efficient use of memory. (Old versions could be heavy on memory use, causing my relatively small memory computer to close down) It is also worth pointing out that it is often "add on" products which use a lot of memory. Mozilla are trying to encourage these developers to use less.

very slowly internet explorer seems to be catching up with mozilla in terms of features. IE 7 has (for the first time) tabbed browsing and also boasts improved security settings. It will be interesting to see whether Mozilla is able to gain more market share.

Current market share

2006           IE7     IE6     IE5     Fx      Moz     N7/8    O7/8/9
October        3.1%    54.5%   3.2%    28.8%   2.4%    0.3%    1.4%


2003           IE6     IE5     Moz     N3      N7      N4      O7
November       71.2%   13.7%   7.2%    0.5%    1.6%    0.5%    1.9%

Generally Mozilla remain more popular with more experienced computer users with IE being first "choice" for most first time users.

How Viewers read a web page

Interesting blog entry about how viewers read a screen. What I learned from Eye Tracking Using an eye tracking programme the video plots how people scan across a screen. Often people go quickly from one thing to the next. There is little evidence of people actually reading the text. Most people are scanning for a subheading or picture that interests them.

See also Pro Blogger

What people look at:

  • Headings
  • pictures (including thumbnail
  • Buttons and Menus
  • Lists are popular – blocks of text aren’t.

A useful idea discussed in a previous blog entry is the idea of "don’t make me think " Users of a website don’t want to have to work anything out, they certainly don’t have time to read instructions. (I think even contributors to websites are a bit like this as well)

An interesting comment that Seth Godin made is that if a website is a little different it catches peoples attention.