[ Pobierz całość w formacie PDF ]
.Properties can be more complex than strings; they can also be numbers, lists, or other data structures.AllProperties are managed via the Properties view.Click on a folder's Properties tab and you will be taken to theproperties management view, as seen in Figure 3-7.Figure 3-7: The Properties Management ViewA property consists of a name, a value and a type.A property's type defines what kind of values it can have.In Figure 3-7 you can see that the folder has two properties.One is named Author, and the other is namedKeyWords.The Author property is a string, while the KeyWords property has a type of tokens.Atokens property is like a sequence of words.Using Object Properties 36 IntroductionZope supports a number of property types.Each type is suited to a specific task.This list gives a briefoverview of the kinds of properties you can create from the management interface:stringA string is an arbitrary length sequence of characters.Strings are the most basic and useful type ofproperty in Zope.intAn int property is an integer, which can be any positive or negative number that is not a fraction.Anint is guaranteed at least 32 bits of precision.longA long is like an integer that has no range limitation.floatA float holds a floating point, or decimal number.Monetary values, for example, often use floats.linesA lines property is a sequence of strings.tokensA tokens property is list of words separated by spaces.textA text property is just like a string property, except that Zope normalizes the line ending characters(different browsers use different line ending conventions).selectionA selection property is special, it is used to render an HTML select input widget.multiple selectionA multiple selection property is special, it is used to render an HTML multiple select form inputwidget.Properties are very useful tools for tagging your Zope objects with little bits of data or information.Inconjunction with methods and scripts, properties make extending simple objects like Folders a very powerfultechnique.Coding Logic with ScriptsIn traditional programming lingo, a script is a short piece of code written in a programming language.As ofversion 2.3, Zope now comes with two kinds of script objects: one that lets you write scripts in Python andone that lets you write scripts in Perl.Both Python and Perl are very popular and powerful programming languages.Both Python and Perl sharemany similar feature: both offer powerful, rapid development, simple syntax, many add-on libraries, strongcommunity following, and copious amounts of free, online documentation.Both languages are also opensource.Because scripts are so powerful and flexible, their possible uses are endless.Scripts are primarily used towrite what is called business logic.Business logic is different than presentation logic.Presentation logic isusually written in a presentation language, like DTML, and it's purpose is to display information to a user.Business logic is usually written in a scripting language, and its purpose is to manipulate information thatcomes from content sources (like documents or databases) or manipulate other objects.Often, presentationlogic is based on top of business logic.A simple example of using scripts is building an online web form to help your users calculate the amount ofcompound interest on their debts.This kind calculation involves the following procedure:Coding Logic with Scripts 37 Introduction1.You need the following information: your current account balance (or debt) called the "principal" ,the annual interest rate expressed as a decimal (like 0.095) called the "interest_rate", the number oftimes during the year interest in compounded (usually monthly), called the "periods" and the numberof years from now you want to calculate, called the "years".2.Divide your "interest_rate" by "periods" (usually 12).We'll call this result "i".3.Add 1 to "i".4.Take "periods" and multiply it by "years".We'll call this result "n".5.Raise (1 + "i") to the power "n".6.Multiply the result by your "principal".This is the new balance (or debt).For this example, you will need two DTML Methods named interestRateForm and interestRateDisplay tocollect the information from the user and display it, respectively.You will also need a Python-based scriptcalled calculateCompoundingInterest that will do the actual calculation.The first step is to create a web formin interestRateForm that collects "principal", "interest_rate", "periods" and "years" from your users.Here's anexample interestRateForm DTML Method:Please enter the following information:Your current balance (or debt):Your annual interest rate:Number of periods in a year:Number of years:This form collects information and calls the interestRateDisplay method.Now, create a Python-based scriptcalled calculateCompoundingInterest that accepts four parameters, "principal", "interest_rate", "periods" and"years" with the following python code:## Script (Python) "calculateCompoundInterest"##parameters=principal, interest_rate, periods, years##"""Calculate compounding interest."""i = interest_rate / periodsi = i + 1n = periods * yearsreturn ((1 + i) ** n) * principalThis will return the balance or debt compounded over the course of "years" [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • personata.xlx.pl