mò +á¸Ec@s¶dZdZddd!ZdkZdklZlZlZlZl Z dkl Z l Z l Z l Z dklZlZdkZd klZlZefƒZed ƒed ƒfZd fd „ƒYZeƒZdfd„ƒYZhed ƒd<edƒd<edƒd<efƒd<egƒd<eeƒd text See the example below that shows how 'if', 'else', and 'in' commands may be combined to display a possibly empty list of objects. The text included within an 'in' command will be refered to as an 'in' block. Synopsis If the variable 'sequence' exists as a sequence, a simple case of the 'in' tag is used as follows:: some markup A more complete case is used as follows:: ) Attributes sort -- Define the sort order for sequence items. Parameter to the attribute is either a sort option, or list of sort options separated by comma. Every sort option consists of variable name, optional comparison function name (default is cmp) and optional sort order (default is asc). Examples: sort="date" or sort="date,time" or sort="title/locale,date/cmp/desc". If you want to specify sort order, you cannot omit the function; use cmp for standard comparison. Few predefined comparison functions available: standard cmp, nocase (ignore string case), strcoll (alias "locale"), strcoll_nocase (alias "locale_nocase"). Locale functions are available only if module locale is already imported (you started Zope with -L locale). sort_expr -- The "sort" attribute accepts only static list of sort options. This calculated parameter allows you to calculate the list of sort options on the fly. sort_expr -- This allows an expression to control sort order. reverse -- Reverse the sequence (may be combined with sort). Note that this can cause a huge memory use in lazy activation instances. reverse_expr -- This calculated parameter allows you to calculate the need of reversing on the fly. Within an 'in' block, variables are substituted from the elements of the iteration unless the 'no_push_item' optional is specified. The elements may be either instance or mapping objects. In addition, the variables: 'sequence-item' -- The element. 'sequence-var-nnn' -- The value of a specific named attribute of the item, where 'nnn' is the name. For example, to get an items 'title' attribute, use 'sequence-var-title'. This construct is most useful in an 'if' tag to test whether an attribute is present, because the attribute lookup will be extended to the full document template namespace. 'sequence-key' -- The key associated with the element in an items list. See below. 'sequence-index' -- The index, starting from 0, of the element within the sequence. 'sequence-number' -- The index, starting from 1, of the element within the sequence. 'sequence-letter' -- The index, starting from 'a', of the element within the sequence. 'sequence-Letter' -- The index, starting from 'A', of the element within the sequence. 'sequence-roman' -- The index, starting from 'i', of the element within the sequence. 'sequence-Roman' -- The index, starting from 'I', of the element within the sequence. 'sequence-start' -- A variable that is true if the element being displayed is the first of the displayed elements, and false otherwise. 'sequence-end' -- A variable that is true if the element being displayed is the last of the displayed elements, and false otherwise. are defined for each element. Normally, 'in' blocks are used to iterate over sequences of instances. If the optional parameter 'mapping' is specified after the sequence name, then the elements of the sequence will be treated as mapping objects. An 'in' command may be used to iterate over a sequence of dictionary items. If the elements of the iteration are two-element tuples, then then the template code given in the 'in' block will be applied to the second element of each tuple and may use a variable, 'sequence-key' to access the first element in each tuple. Batch sequence insertion When displaying a large number of objects, it is sometimes desirable to display just a sub-sequence of the data. An 'in' command may have optional parameters, as in:: The parameter values may be either integer literals or variable names. Up to five parameters may be set: 'start' -- The number of the first element to be shown, where elements are numbered from 1. 'end' -- The number of the last element to be shown, where elements are numbered from 1. 'size' -- The desired number of elements to be shown at once. 'orphan' -- The desired minimum number of objects to be displayed. The default value for this parameter is 0. 'overlap' -- The desired overlap between batches. The default is no overlap. Typically, only 'start' and 'size' will be specified. When batch insertion is used, several additional variables are defined for use within the sequence insertion text: 'sequence-query' -- The original query string given in a get request with the form variable named in the 'start' attribute removed. This is extremely useful when building URLs to fetch another batch. To see how this is used, consider the following example:: ... display rows (Next &dtml-next-sequence-size; results) If the original URL is: 'foo/bar?x=1&y=2', then the rendered text (after row data are displayed) will be:: (Next 20 results) If the original URL is: 'foo/bar?batch_start=10&x=1&y=2', then the rendered text (after row data are displayed) will be:: (Next 20 results) 'sequence-step-start-index' -- The index, starting from 0, of the start of the current batch. 'sequence-step-end-index' -- The index, starting from 0, of the end of the current batch. 'sequence-step-size' -- The batch size used. 'previous-sequence' -- This variable will be true when the first element is displayed and when the first element displayed is not the first element in the sequence. 'previous-sequence-start-index' -- The index, starting from 0, of the start of the batch previous to the current batch. 'previous-sequence-end-index' -- The index, starting from 0, of the end of the batch previous to the current batch. 'previous-sequence-size' -- The size of the batch previous to the current batch. 'previous-batches' -- A sequence of mapping objects containing information about all of the batches prior to the batch being displayed. Each of these mapping objects include the following variables: batch-start-index -- The index, starting from 0, of the beginning of the batch. batch-end-index -- The index, starting from 0, of the end of the batch. batch-size -- The size of the batch. 'next-sequence' -- This variable will be true when the last element is displayed and when the last element displayed is not the last element in the sequence. 'next-sequence-start-index' -- The index, starting from 0, of the start of the batch after the current batch. 'next-sequence-end-index' -- The index, starting from 0, of the end of the batch after the current batch. 'next-sequence-size' -- The size of the batch after the current batch. 'next-batches' -- A sequence of mapping objects containing information about all of the batches after the batch being displayed. Each of these mapping objects include the following variables: batch-start-index -- The index, starting from 0, of the beginning of the batch. batch-end-index -- The index, starting from 0, of the end of the batch. batch-size -- The size of the batch. For each of the variables listed above with names ending in "-index", there are variables with names ending in "-number", "-roman", "-Roman", "-letter", and "-Letter" that are indexed from 1, "i", "I", "a", and "A", respectively. In addition, for every one of these variables there are variables with names ending in "-var-xxx", where "xxx" is an element attribute name or key. Summary statistics When performing sequence insertion, special variables may be used to obtain summary statistics. To obtain a summary statistic for a variable, use the variable name: 'statistic-name', where 'statistic' is a statistic name and 'name' is the name of a data variable. Currently supported statistic names are: total -- The total of numeric values. count -- The total number of non-missing values. min -- The minimum of non-missing values. max -- The maximum of non-missing values. median -- The median of non-missing values. mean -- The mean of numeric values values. variance -- The variance of numeric values computed with a degrees of freedom equal to the count - 1. variance-n -- The variance of numeric values computed with a degrees of freedom equal to the count. standard-deviation -- The standard deviation of numeric values computed with a degrees of freedom equal to the count - 1. standard-deviation-n -- The standard deviation of numeric values computed with a degrees of freedom equal to the count. Missing values are either 'None' or the attribute 'Value' of the module 'Missing', if present. 'else' continuation tag within in An 'else' tag may be used as a continuation tag in the 'in' tag. The source after the 'else' tag is inserted if: - The sequence given to the 'in' tag is of zero length, or - The 'previous' attribute was used and their are no previous batches, or - The 'next' attribute was used and their are no next batches, or s6$Id: DT_In.py 40218 2005-11-18 14:39:19Z andreasjung $s$Revision: 1.62 $i iþÿÿÿN(s ParseErrors parse_paramss name_paramsstrs join_unicode(s render_blockss InstanceDictsValidationErrorsEval(s simple_namesadd_with_prefix(ssequence_variablessopttut InFactorycBstZdZdZd„ZRS(NtelsetincCs,t|ƒ}|io |iSn|iSdS(N(tInClasstblockstitbatchtrenderwbt renderwob(tselfRR((t5/data/zmath/zope/lib/python/DocumentTemplate/DT_In.pyt__call__\s  (R(t__name__t __module__tblockContinuationstnameR (((R RXsRcBsgtZdZdZZZZZdZ dZ dZ Z d„Z d„Zd„Zd„Zd„ZRS(Nc$Csš|d\}}}t|dddddddd d d d dd dddddddddddddddddddddƒ}||_|i}|dƒo/|d|_}|djo d|_qÓn|dƒot|dƒ|_ n|dƒot|dƒ|_ n|dƒo|d|_ n|dƒo|d|_ n|d ƒo|d |_ nx(d#D] } || ƒo d|_q|q|W|idƒ}|o$t|ƒ ottddƒ‚nx=d$D]5} || ƒo"|i otd| df‚qáqáW|dƒo…|d} t| ƒtdƒjo^yt| ƒWq¨tiddig} | D]}| d|qx~ ƒdƒ|_q¨Xq¬nt|ddƒ\} } | dj o | i"} n| | |_#|_ |i|_t$|ƒdjo†t$|ƒd jo td%‚n|d\}}}t|ddƒ}|o*t|ƒ}|| jo td&‚q†n|i|_&ndS('NiRRtstartt1tends-1tsizet10torphant0toverlaptmappingit no_push_itemtskip_unauthorizedtprevioustnexttexprtsorttreverset sort_exprt reverse_exprtprefixs sequence-itemsprefix is not a simple nameRsÏ The %s attribute was used but neither of the start, end, or size attributes were used. s&+s[%s]s =[0-9]+&+istoo many else blockssname in else does not match in(RRR(RRRR(stoo many else blockssin(sname in else does not match insin('Rttnametargstsectiont parse_paramsR thas_keyRtEvalR!R"R RRtnRtgetR#t simple_namet ParseErrort_tmtvttypetinttretcompiletjoint_[1]tct start_name_ret name_paramRRtNonetevalR tlentenametelses(R RR<R#R(R$RR%R6RRR*R5R/R&((R t__init__jsr             N     c)CsE|i}|i}|djo||}h||<}n||ƒ}d}|p&|iot |i|ƒSndSnt |ƒt dƒjo t d‚n|i }'|i }|i}|i}|idj o+|ii|ƒ|_|i||ƒ}n'|idj o|i||ƒ}n|idj o&|ii|ƒo|i|ƒ}n$|idj o|i|ƒ}nd}}yt||ddƒ}Wn d}nXt||ddƒ}t||ddƒ} t||ddƒ}t||d d ƒ}t ||| ||ƒ\}}}|i"d ƒo d}n|i"d ƒo d}n|d}|d}(y|d }&Wn d}&nX|i&dƒ} t(|d|&|i)| ƒ}|i+}#t-|#d| ƒ}x$|#i/ƒD]\} }%|%|| t||ƒ}|ot d„|ƒ}q„|dd}n|i } | }g}x£|D]›}d} t|ƒtjo6t|ƒdjo#|o|d} n|d}n|o |} n|}|o|o–g} x|D]} y(| o|| } nt|| ƒ} Wntj o}d} nXt| ƒpy | ƒ} WqœqœXn| i| ƒq(Wq)y(| o||} nt||ƒ} Wntj o}d} nXtt| ƒƒpy | ƒ} Wq%q%Xq)n|i| |fƒq¡W|o t||ƒ} |i| ƒn |iƒg}x!|D]\} }|i|ƒq~W|S(Nt/it,icCs|dS(Ni(tx(Ru((R tãsi(R Rtfindt need_sortfunctsplitt sortfieldsR;tmultsorttmake_sortfunctionsRCtsf_listtmapRtisorttsRARfR9RWR0RlR/tsktakeyRctAttributeErrortKeyErrort basic_typeRbtSortBytby(R RARCRxR„R{R}RRR‚RR‡RWRR€RfR/Rz((R RHÍsx  &         cCst|ƒ}|iƒ|S(N(tlistRAR€R (R RAR€((R RIs  (R RR9R=RRRRRR7R R!R"R>RR RHRI(((R Rcs  J ¶ c Iiif0.0cCsty||}Wn |}nX|oKyt|ƒ}Wqp||}t|ƒ|jot|ƒ}qlqpXn|S(N(RGRR/tdefaultR1RCR0tst(RGRCRR‰RŠR/((R RJs  cCst|iƒ|iƒƒS(N(tcmptstr1tlowertstr2(RŒRŽ((R tnocase,stlocale(sstrcollcCst|iƒ|iƒƒS(N(tstrcollRŒRRŽ(RŒRŽ((R tstrcoll_nocase2sc Csrg}xe|D]]}|idƒ}t|ƒ}|djo|idƒ|idƒn9|djo|idƒn|djon td‚|d}|djo t }nX|djo t }nA|djo t }n*|djo t}n|i|d ƒ}|diƒ}|djo d} n!|djo d} n td‚|i|d || fƒq W|S(s‘Accepts a list of sort fields; splits every field, finds comparison function. Returns a list of 3-tuples (field, cmp_function, asc_multplier)RsiR‹tasciis/sort option must contain no more than 2 slashesRRR‘t locale_nocaseR’itdesciÿÿÿÿs$sort oder must be either ASC or DESCN(slocalesstrcoll(R”sstrcoll_nocase(R}RztfieldRytfR;RrRbt SyntaxErrortf_nameR‹tfuncRR‘R’RCtgetitemRt sort_ordert multiplier( RzRCR–R—RrR}RœRšR™R((R R|6s@                    R†cBstZd„Zd„ZRS(NcCs||_||_dS(N(R{R R}(R R{R}((R R>fs c Cs |i}|o|d}|d}n|i}t|ƒ}t|ƒ|d|jptd|||f‚t|ƒ|d|jptd|||f‚xbt|ƒD]T}||||} } ||dd!\} }| | | ƒ}|o ||Sq°q°WdS(Niis%s, %di(R R{to1to2R}R;RrtAssertionErrorRdRtc1tc2RšRR*( R RžRŸRRRrR*R}R{RšR¢R¡((R R js     33 (R RR>R (((R R†es (%t__doc__t __rcs_id__t __version__RitDT_UtilR-R'R8tstrRpRERoRgR)R,RTR2tDT_InSVRPRKR0RlRnRtInRR9R(R…RJRtmodulesRR‘R’R|R†(RKRRPR|R,R2RpRoR)RnR¥RTR’RgR-RRERRlR‘R8R'RiRJR…R¤R†R§R©((R R@Js,  %   ÿºc    /