1. Trang chủ
  2. » Công Nghệ Thông Tin

The Zope Bible phần 9 ppt

65 183 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 65
Dung lượng 529,08 KB

Nội dung

490 Part IV ✦ Advanced Zope Concepts To distribute your Product, select the Distribution tab from within the product. For example, click the Distribution tab within the ZFAQ product. The form on the Distribution tab gives you fine control over the distribution you create. The Version field specifies the version that will be visible in the products list for whoever installs the product. Every time you make a distribution, the number will be incremented, but you can change it to whatever number you want. We sug- gest leaving it at 1.0 unless you have some reason to do otherwise. Next on the form, there are two radio-buttons that let you select the kind of Distribution you want to create. If you want others to be able to customize and/or redistribute your Product, select the “Allow Redistribution” option. If you want to disallow redistribution, select the “Disallow redistribution and allow the user to configure only the selected objects:” option, and you can choose which objects your users can customize in your Product. The list defaults to having no objects selected, which won’t allow any changes to the distributed product. If you want them to be able to change the FAQManager ZClass, select that ZClass. If you want the whole product to be customizable but still disallow redistribution, select all of the objects in the list. Notice that the QandA Zclass, which is contained within the FAQManager Zclass, is not listed within this object list. This means that there is no way to allow or disallow customization of the QandA ZClass independently from the FAQManager ZClass. Whether the QandA Zclass is customizable is dependent on the whether the FAQManager ZClass is customizable. To get around this limitation, the QandA object would have to have been created in a separate product. After you made your decisions regarding the redistribution and customization of the ZFAQ product distribution, click the Create a distribution archive button. Zope will now create a file called ZFAQ-1.0.tar.gz, and attempt to download it to your com- puter. Save the file on your desktop or in a “Downloads” directory on your computer. The ZFAQ-1.0.tar.gz file can be installed in a Zope installation just like any other downloaded product. If you think that your product would be useful to other Zope users, we suggest that you add your product to your zope.org member folder to make it generally available. Summary In this chapter, you learned about creating through-the-Web products using ZClasses, defining property sheets and views, and building a simple Web applica- tion using them. You also learned to add permissions to ZClasses, make your ZClasses CatalogAware, subclass Python classes in your ZClass products, and distribute your through-the-Web products. ✦✦✦ i4857-3 Ch16.F 3/1/02 9:42 AM Page 490 Searching Content M ost of this book describes using Zope to accomplish fairly ordinary Web site building and maintenance tasks. Even Part II of the book, which shows you how to build custom object types using Zope’s object oriented framework, isn’t that different from building a similar application using JavaBeans, for example. In this chapter, we are going to introduce one of Zope’s fea- tures that sets Zope apart from other Web development envi- ronments — its integrated framework for indexing and searching objects and their attributes. Adding and Populating ZCatalogs Zope has built-in searching and indexing capabilities that enable you to easily find objects in your site that conform to various criteria (such as containing some text) via ad-hoc queries. What is a ZCatalog? ZCatalogs are Zope’s general-purpose search engines and indexers. A ZCatalog examines objects, indexes whatever properties you’ve marked as significant, and enables you to query the ZCatalog for objects whose properties match your criteria. Additionally, ZCatalogs don’t return the actual objects in their results, but instead return a special lightweight object with whatever metadata you’ve told the ZCatalog to retain for the object and a pointer to the actual object if you need it. 17 17 CHAPTER ✦✦✦✦ In This Chapter Adding and populating ZCatalogs Configuring and querying the ZCatalog Accessing ZCatalogs from Python More about ZCatalog ✦✦✦✦ i4857-3 Ch17.F 3/1/02 9:42 AM Page 491 492 Part IV ✦ Advanced Zope Concepts Adding a ZCatalog to your site In your root folder, click on the drop-down to select ZCatalog from the list of addable products. Fill the Add ZCatalog form that comes up with an id of Catalog, leave the title field blank, and leave the vocabulary drop-down set on the default of Create one for me (we’ll go into more detail about Vocabularies in the “About Vocabularies” sidebar in the “More about ZCatalog” section). Click the Add button. You should now have a ZCatalog instance named Catalog in your root folder. The icon for a ZCatalog is a folder with a magnifying glass, and the ZCatalog user inter- face does resemble that of a folder somewhat. But there are a few differences, as shown in Figure 17-1. Figure 17-1: The ZCatalog Contents tab ZCatalogs have several tabs that folders do not have, including the following: Catalog Indexes Metadata Advanced The Find tab that folders have is replaced with a Find Objects tab in a ZCatalog. i4857-3 Ch17.F 3/1/02 9:42 AM Page 492 493 Chapter 17 ✦ Searching Content Populating a ZCatalog ZCatalogs can be populated in two ways: manually and automatically. Populating a ZCatalog manually is fairly simple; just go to the Find Objects tab in a ZCatalog (shown in Figure 17-2), and select the criteria for the objects that you want to cata- log and index. Figure 17-2: The ZCatalog Find Objects tab For the time being, leave the default settings in the form, and click the Find and Catalog button at the bottom of the form. The operation may take a few moments, so be patient while Zope works. After Zope is done finding and cataloging the objects that meet the criteria you specified (in this case, all objects stored in the ZODB), the browser is redirected to the Catalog tab of the ZCatalog, and it shows you how long it took to complete the operation, as shown in Figure 17-3. As you can see, the find objects operation found all objects in the ZODB, all of which are now recorded in the ZCatalog. i4857-3 Ch17.F 3/1/02 9:42 AM Page 493 494 Part IV ✦ Advanced Zope Concepts Figure 17-3: The Catalog tab, after finding objects Configuring and Querying the ZCatalog ZCatalogs store two types of information about the objects that they catalog: indexes and metadata. Indexes are the lookup tables that the ZCatalog consults in order to determine which objects match a particular query, and metadata is the information about an object that a ZCatalog stores in order to make its result sets more meaningful. ZCatalog indexes The ZCatalog uses indexes to determine which objects that it knows about match a particular query. In order for you to query a ZCatalog about a particular object attribute, that attribute must be indexed by the ZCatalog in an Index. As you can see in Figure 17-4, the ZCatalog’s index tab has several indexes by default. i4857-3 Ch17.F 3/1/02 9:42 AM Page 494 495 Chapter 17 ✦ Searching Content Figure 17-4: The ZCatalog Indexes tab The following are the four built-in types of indexes: ✦ Text indexes. These indexes break up text contained in an attribute into indi- vidual words. The more times a particular word appears in an attribute indexed by a text index, the higher its score. Results are sorted by score, high- est to lowest from the most relevant to the lest relevant. Text indexes are often referred to as full-text indexes. PrincipiaSearchSource and title are text indexes included in a ZCatalog by default. ✦ Field indexes. These indexes treat the object’s attribute as a single unit, and they are used to keep track of object attributes that conform to a particular value. Field indexes included in a ZCatalog by default are bobobase_ modification_time, id, and meta_type. ✦ Keyword indexes. These indexes take a sequence of objects and break them up into keywords, which are then indexed individually. A Keyword index returns any objects that have one or more indexed keywords that match any keywords from the query. They are particularly useful for building categories. ✦ Path indexes. These indexes break up the physical path to an indexed object into all its subpaths. A Path index returns all objects that match a partial path specified in a search query. By default, a ZCatalog includes a path index named path. i4857-3 Ch17.F 3/1/02 9:42 AM Page 495 [...]... but it gets the job done This code loops through each result in the first sequence x, checking it against each item in the second sequence y (in a second loop) The code here has to check the actual cataloged objects (not the results themselves) by retrieving them using getObject() Only if there is no match does the result from the first sequence get appended to the returned sequence z Then the second... typically much lighter weight that the actual objects they represent, which makes them (and their associated getURL method) a better choice if the list is either very long, or the objects very large, either of which will increase the amount of memory Zope requires to retrieve the object list A hybrid approach can sometimes work, by having the Python Script simply return the result object list like this:... delete the existing Vocabulary object by selecting the checkbox next to it, and clicking the Delete button Next, choose Vocabulary from the drop-down list In the form that comes up, you can set the id of the Vocabulary object (you should type in Vocabulary), the Title (which you can omit), the type of Splitter (choose ZopeSplitter), and whether the Vocabulary object is Globbing (non-Globbing is the default,... tal:content=”template/title”, whereas the attribute on the tag in the body of the page is tal:replace=”template/title” Plainly, tal:replace is intended to replace the entire tag with the result of the expression, and tal:content is intended to replace the content of the tag only, leaving the tag itself intact i4857-3 Ch18.F 3/1/02 9: 42 AM Page 523 Chapter 18 ✦ Zope Page Templates Figure 18-3: The rendered Test... ZCatalog In fact, the ZCatalog is picking up the form fields and their values from the HTTP request (accessible in Zope through the REQUEST object), so no values need to be passed in explicitly This is why the attribute, the index, and the form field all share the same id — to make this transparency possible i4857-3 Ch17.F 3/1/02 9: 42 AM Page 501 Chapter 17 ✦ Searching Content Listing 17-2: The search_results... by the colon (:) in the attribute name The tal:replace attribute indicates that the result of the path expression that it is assigned as a value should replace the entire tag that the attribute is on, giving the following rendering: Hello, Bill! Assuming, of course, that the user viewing the rendered page has a username of “Bill.” We’ll get back to path expressions later in the chapter, as these... in this case, the words, The Title,” which are enclosed in the tag are plainly visible, as the unrendered template has not replaced the tag However, the tag in the template’s head section is plainly not being replaced, or it wouldn’t show up in the browser window’s title bar The reason the behavior is different is in the two TAL attributes The TAL attribute on the tag is tal:content=”template/title”,... 3/1/02 9: 42 AM Page 506 Part IV ✦ Advanced Zope Concepts Calling from a DTML method, as in the preceding code, produces a list of links to all cataloged documents containing the word about The catalog is being passed a dictionary, where the key is the index id, and the value is the indexed value that we’re looking for Notice that the Python Script takes the result object list x, and by calling the result... that it only causes Zope to replace the contents of the tag, not the whole tag Like replace, the content statement also has the optional flags text and structure, and the default behavior is also text For example, these statements populate an tag with the escaped title attribute of the template: The Title The Title This... 522 Part IV ✦ Advanced Zope Concepts Rather a lot is going on in the default template content, so before you go any further, change the title property to The Test Document, and edit the content of the template as follows: The title The Title Then click Save Changes . being, leave the default settings in the form, and click the Find and Catalog button at the bottom of the form. The operation may take a few moments, so be patient while Zope works. After Zope is. allow or disallow customization of the QandA ZClass independently from the FAQManager ZClass. Whether the QandA Zclass is customizable is dependent on the whether the FAQManager ZClass is customizable 490 Part IV ✦ Advanced Zope Concepts To distribute your Product, select the Distribution tab from within the product. For example, click the Distribution tab within the ZFAQ product. The form

Ngày đăng: 14/08/2014, 01:20

TỪ KHÓA LIÊN QUAN

w