Zope
  Home arrow Zope arrow Page 3 - Plone Content Types With Archetypes
CIO Insight
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM Rational Software Development Conference
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ZOPE

Plone Content Types With Archetypes
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 15
    2006-02-28

    Table of Contents:
  • Plone Content Types With Archetypes
  • A Quotation Content Type
  • Mutators and Accessors
  • Validators

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    PCmover - $15 Off with Coupon Code CJPH7Q

    Plone Content Types With Archetypes - Mutators and Accessors
    (Page 3 of 4 )

    Archetypes enables you to manipulate the values of fields. When you manipulate the value of a field when it is set, you are using a mutator. When you manipulate the value of a field when it is requested, you are using an accessor. Both mutators and accessors are simple to create and use in content types.

    Let's take another look at our Quotation product above. Let's say we want to modify the field for the quotation. When the user sets the value, we'll put quotation marks around everything. To do this, we simply create a method called setQuotation. The method will be automatically called when the value of the field is set. The method goes into our Quotation class:

    class Quotation(BaseContent):
       ...
       def setQuotation(self, value):
          value = '"' + value + '"'
          self.getField('quotation').set(self, value)

    Restart Zope and install the product again. Add a quotation and look at the result—the value of the quotation field now has quotation marks around it. However, our system has a serious flaw. Click the “edit” tab and notice how the value of the text area has quotation marks around it. Save it and look again. There are now two sets of quotation marks, which is no good. While we could modify our mutator to work around this, the easiest way to fix this is to use an accessor instead.

    Accessors, too, are methods, but they don't have any sort of value argument. Here's an accessor that does what we want:

    class Quotation(BaseContent):
       ...

       def getQuotation(self):
          return '"' + self.getField('quotation').get(self) + '"'

    Remember to delete the mutator we defined above in order for our content type to function properly. Restart Zope and reinstall our product. Create a quotation, or edit one, and save it. If quotation marks are left over from our mutator, make sure to delete them. You should now see quotation marks wrapped around your quotation. Notice that they do not appear when editing.

    More Zope Articles
    More By Peyton McCullough


       · Hello,Archetypes is an extremely simple tool, as this article illustrates. Using...
       · Should it be in Quotation.py?
       · Yes, it should be. Thanks for pointing that missing bit of information out to...
       · Thanks for a very simple into to archetypes (the ones on plone.org semmed too...
       · i created a folder named Quotation and did as the text said but i am not able to c...
       · The accessor and mutator described on page 3 of this tutorial need to be declared in...
     

       

    ZOPE ARTICLES

    - Creating Zope Products
    - Plone Content Types With Archetypes
    - Flat User Management in Zope
    - Creating Basic Zope Applications
    - Getting started with Zope for Linux and Sola...
    - ZPT Basics (part 4)
    - ZPT Basics (part 3)
    - ZPT Basics (part 2)
    - ZPT Basics (part 1)
    - Exception Handling In DTML
    - DTML Basics (part 4)
    - DTML Basics (part 3)
    - DTML Basics (part 2)
    - DTML Basics (part 1)
    - Using Zope With Apache

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway