Modified:
doc/plonebook/trunk/130-archetypes.rst
Log:
chinese title--此行及以下内容将会被忽略--
M 130-archetypes.rst
Modified: doc/plonebook/trunk/130-archetypes.rst
==============================================================================
--- doc/plonebook/trunk/130-archetypes.rst (original)
+++ doc/plonebook/trunk/130-archetypes.rst Mon Aug 21 21:07:56 2006
@@ -129,8 +129,8 @@
If you do make any of these changes to try the following examples, you'll have to restart Plone. Only then will all the new changes be loaded and properly registered. For more information on this, see the 'Developing with Archetypes” section later in this chapter.
-解释Schemas, Fields, and Widgets
-.......................................
+解释语义(Schemas), 字段(Fields), 和控件(Widgets)
+...............................................................
Merriam-Webster's dictionary definition of a schema is as follows:
@@ -176,8 +176,8 @@
It's worth noting that the items are returned from queries of the schema in the order they're added to the schema. This means you can rearrange the order that elements appear in the user interface by moving the fields around in the schema. That's also why the *BaseSchema* is added at the beginning so that the ID and title fields will appear at the top of the view and edit page, rather than at the bottom.
-Fields
-,,,,,,
+字段(Field)
+,,,,,,,,,,,,,,,,,,,,,,,,,
So far you've seen the *StringField* field, which is a common field that represents a string on your content type. A number of fields are available in Archetypes, as described in Table 13-1. Over time, more fields are being added, and if you need to, it's possible to create your own.
@@ -278,8 +278,8 @@
Now that I've covered the default fields and attributes, it's time to move onto the actual widgets that are available.
-Widgets
-,,,,,,,
+控件(Widgets)
+,,,,,,,,,,,,,,,,
A widget contains the information about how the object will be represented visually. The view of an attribute displayed is often closely related to the type of the attribute; however, you have options for the display—a string could be selected in many ways. Given the set of widgets, the widget object can be almost anything. You can import any of the widgets from the Archetypes *public* module. For example:
@@ -395,7 +395,7 @@
visible If the attribute should be visible in the user interface. This is a dictionary mapping the view mode to a string, describing the visibility. Choices are *visible*, *hidden* (shown in an HTML hidden form value), *invisible* (not shown at all). For example, *{'view': 'visible', 'edit': 'hidden' }* means that the view will show, but the edit page will hide the value.
========== ================================================================================================================================================================================================================================================== ===========================================================================================================================
-Some Example Field and Widget Combinations
+某些示例字段和控件组合
..........................................
This section contains some useful combinations that seem to be commonly used and that you may find as useful examples. For this example, make a drop-down list of your favorite fruits. You'll define the *vocabulary* attribute as a list of strings. Each of the values in the list is a string of the *fruit* type; hence, the field type is a *StringField*. Because you're defining the widget as a *SelectionWidget*, it'll show up as a drop-down list, like so:
@@ -432,7 +432,7 @@
widget = RichWidget(label = 'Body'),
)
-The Primary Field: Marhsaling and Responding to FTP and WebDAV
+主字段:FTP和WebDAV的返回字段
..............................................................
Plone is an object-oriented system where an object has many attributes and can't simply be represented as a plain file. Unfortunately, most the existing protocols such as FTP and WebDAV treat content in exactly this manner. So there needs to be some way to translate between the two, and the primary field does this. By setting the primary field on an object, this field will become the one that's sent and received by these protocols—rather than the entire object.
@@ -441,7 +441,7 @@
To set up primary field marshaling, you need to add the following to your schema: *marshall=some_marshaller()*. Currently, there are only two marshalers: a *PrimaryFieldMarshaller*, which takes the whole content and places into your object, and an *RFC822Marshaller*. This second marshaler handles the content for field name/value pairs as used in e-mail. For this chapter's purposes, I'll use the *PrimaryFieldMarshaller* to handle content with External Editor.
-Validations of Input
+输入的校验
....................
Although the forms handle the content and some basic errors, such as omitted content, quite well, you'll probably want some more sophisticated error handling. You can make a series of validations to test that the content in your content type is correct. For example, if you have an integer field, you'll probably want to test that the data they've added is what it's meant to be.
@@ -542,7 +542,7 @@
validators=("christmas",)
-Overriding Views and Actions in the Base Class
+覆盖基础类中定义的视图(View)和操作项(Action)
..............................................
Archetypes creates default views and actions for you based on a standard set of requirements that will suit many needs. The actions are view, edit, and properties, of course; references is another action you'll look at it a moment. You won't find any view or edit page templates for the object; those are generated automatically for you by Archetypes. However, you can override them.
@@ -577,7 +577,7 @@
""" Some product """
content_icon = "some_icon.gif"
-Overriding the Default Methods
+覆盖默认的方法
..............................
In Table 13-2, I mentioned the option of overriding some of the default methods that occur on content types, such as accessor and mutator. This is an advanced option that allows you to manipulate the way fields are edited.
@@ -612,7 +612,7 @@
The practical upshot of this is that now, no matter when or how a person types in the word Perl
-Putting Together the Rest of the Content Type
+将内容类型的余下部分组合起来
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I've now covered all the main elements of the content type. Listing 13-1 shows all the code together. You'll note that the rest of the code is more compact than the Python product because Archetypes does so much work for you.
@@ -736,7 +736,7 @@
The full version of ArchExample is available from the Plone Book Web site at *http://plone-book.agmweb.ca*, and you should be able to drop this and run it on your site. As you've seen, this content type is quick and easy to develop and easy to alter, without having to write lots of code.
-Archetypes based Development
+基于Archetypes的开发
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This section provides some more in-depth coverage on some of Archetypes' more advanced features. These features will provide some useful tools for the development of your content types. This will include making references, creating new widgets, and transforming content.
@@ -747,7 +747,7 @@
If you change a schema, then you just need to restart Plone, and all new instances of your class in Plone will be updated. However, what about all the old instances of the product? Fortunately, Archetypes has provided a dynamic update tool that goes through all the old instances of your product and updates them to the new schema. In the ZMI, click archetype_tool
-Using Unique IDs
+使用唯一ID
................
The concept of unique IDs is simple but something that was missing in Zope. Originally Zope developers assumed using the path to an object would do; unfortunately, this has shown to be inadequate. As a simple example, consider what happens when someone moves the location of a document—your unique reference to that document has been lost. A unique ID is a truly useful tool to have. Archetypes creates a unique ID on every object it creates and saves it for you on the object. It also saves it in a separate catalog for you called *uid_catalog*.
@@ -858,7 +858,7 @@
)
)
-Developing Folderish Objects
+开发文件夹类型的对象
............................
You've already worked with folderish objects a lot in Plone, but you may not have known it. A folderish object is one that exhibits similar characteristics to a folder or directory, namely, that it can contain separate individual objects. There really is nothing special about a folderish object—just that it inherits from a certain base class to provide its properties, and new content can be added to it.
@@ -881,7 +881,7 @@
If you're going to store a huge amount of content in a folder, then a folder tends to become inefficient at about 100 objects. That's a rather arbitrary figure that should be taken with a pinch of salt; normal folderish objects are designed to be fast for small numbers of object. If you wanted, you could use a binary tree folder, which stores the objects internally in a more efficient binary tree, rather than a Python dictionary. To use this, just import *BaseBTreeFolder* and *BaseBTreeFolderSchema* and use these in your object instead. As far as developing a product is concerned, they work just the same, but unless you put a lot of data into them, you wouldn't likely notice any difference. I've stored more than 100,000 objects in *BTreeFolder*, and it's always responded well.
-Handling Microsoft Office Content
+处理微软的Office内容
.................................
Handling Microsoft Office content such as Word and Excel documents is a bane that all content management systems face at some point. However, this is really the case for every type of content—Microsoft Office, OpenOffice.org, Portable Document Format (PDF), images, and so on. Using these content forms on Web sites usually causes a few problems; this is well known, of course. Editing is clumsy because clicking a document causes you to download it or, even worse, open it in your browser. When you've finished, you have to upload back up to the Web site, which can normally mean clicking around a bit to get back to it. When the content is online, the contents aren't searchable because they aren't in a plain-text format the catalog can understand. Further, you can't view the content online because again it isn't in a Web-friendly format.
@@ -896,7 +896,7 @@
I recommend thinking first about exactly what you want to transform and then taking a look at the Portal Transforms source code to see if you can find a transformation that will do the job for you.
-Setting Up a Content Type
+设置一个内容类型
~~~~~~~~~~~~~~~~~~~~~~~~~
You'll now create a simple content type for handling Microsoft Word documents, probably the most common type of content you'll have to handle. For this example, I did the transformation on Windows. However, if you can set up an alternative system, most of the following worked on Linux. In this case, the easiest thing to do is to use Windows to install your Plone instance. This creates an install with all the Win32 API modules installed and working. I had Microsoft Office installed on the server. Then you need to make a content type to handle the example, called *WordExample*. Essentially one field in the schema handles the content so that the schema looks like the following:
@@ -924,7 +924,7 @@
This content type is about as simple as you can get at this point. But you could plug more stuff into this into the content type—such as a description or more properties. If you're doing a lot of work, then it'd conceivably be possible even to pull the metadata information from the Word document and place it as metadata inside Plone.
-Setting Up a Transformation on Windows
+在Windows中设置转换
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The transformation should be set up for you automatically inside the *portal_transforms* tool. There isn't really a lot to look at in the tool; it merely provides a list of the transforms that are available. A transformation has a list of incoming MIME types that it'll transform (such as *application/msword*) and the output that will be produced (such as *text/html*). Each transformation is a module on the file system; in this case, you can find it in *PortalTransforms/transforms/word_to_html*.
@@ -933,7 +933,7 @@
You can now close Pythonwin and restart Plone.
-Testing the Content Type
+测试内容类型
~~~~~~~~~~~~~~~~~~~~~~~~
To test your content type, you'll need to restart Plone, ensure that the product is registered as usual, and install it using the Add/Remove Products screen. To add a new Word document, go to the Plone interface and in the drop-down box select Word Document; it's pretty obvious since you'll also see a little Word logo.
@@ -955,7 +955,7 @@
*http://sf.net/projects/archetypes*
*http://www.logilab.org/projects/portaltransforms/documentation*
-Going Further: Writing Content Types in a UML Diagram
+深入:使用UML图编写内容类型
.....................................................
So you have a complicated content type and the idea of writing it manually is boring? Well, never fear, because ArchGenXML is here! This is a neat product that allows you to write your content in a UML graphical modeling tool and develop a product straight from that.
@@ -990,7 +990,7 @@
*http://plone.org/documentation/archetypes/ArchetypesDeveloperGuide/index_html#archgenxml-generating-archetypes-using-uml*
-Storing Your Content in a SQL Database
+把你的内容存放到SQL数据库中
......................................
For almost all of this book, the content you've seen has been stored in the Zope object database. I've shown you how to store content on the file system, but a commonly asked question is, How do you store it in a relational database? Placing it inside a relational database is often a good thing to do if the following are true:
@@ -1007,7 +1007,7 @@
*SQLStorage* uses the fact that Archetypes provides an extra layer on top of normal objects to allow for special persistence mechanisms. Zope provides many different relational database adapters, and *SQLStorage* plugs into those. Currently there are two adapters, Postgres and MySQL. However, if the database supports standard SQL, then there's no reason one of these existing *SQLStorage* formats can't be used. If you find that your database adapter needs to do something different, then it wouldn't be difficult to alter the SQL statements inside *SQLStorage* so it worked with another database.
-Making a Content Type Persist in a Relational Database
+让一个内容类型在关系数据库中存放
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To persist the data, you must set up a relational database and make a Zope connection to it. In this case, I'll use Postgres, mainly because I already have a Postgres database for other work available but also because Postgres is good database for all levels of users. To connect Zope to Postgres, psycopg and ZPsycopg are probably to hardest to pronounce but most commonly used and best supported. You'll also find Debian packages and even Windows packages available from *http://initd.org/software/psycopg*.