Package qm :: Package external :: Package DocumentTemplate :: Module DT_In
[hide private]
[frames] | no frames]

Module DT_In

source code

Sequence insertion

   A sequence may be inserted using an 'in' command.  The 'in'
   command specifies the name of a sequence object and text to
   be inserted for each element in the sequence.

   The EPFS syntax for the in command is::

      %(in name)[
           text
      %(in name)]

   The HTML syntax for the in command is::

      <!--#in name-->
           text
      <!--#/in name-->

  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::

     <!--#in sequence-->some markup<!--#/in-->

  A more complete case is used as follows::

    <!--#in sequence sort=age-->
      <!--#var sequence-number-->) <!--#var age-->
    <!--#/in-->

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::

      <!--#in values start=start_var size=7-->

  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 3.

      '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::

             <!--#in search_results size=20 start=batch_start-->

                ... display rows

                <!--#if sequence-end--> <!--#if next-sequence-->
                  <a href="<!--#var URL-->/<!--#var sequence-query
                      -->&batch_start=<!--#var
                      next-sequence-start-number-->">
                  (Next <!--#var next-sequence-size--> results)
                  </a>
                <!--#/if--> <!--#/if-->

             <!--#/in-->

         If the original URL is: 'foo/bar?x=1&y=2', then the
         rendered text (after row data are displayed) will be::

                  <a href="foo/bar?x=1&amp;y=2&amp;batch_start=20">
                  (Next 20 results)
                  </a>

         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::

                  <a href="foo/bar?x=1&amp;y=2&amp;batch_start=30">
                  (Next 20 results)
                  </a>

      '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


Version: 1069

Classes [hide private]
  InFactory
  InClass
Functions [hide private]
True if D has a key k, else False
basic_type(D, k) source code
 
int_param(params, md, name, default=0, st=<type 'str'>) source code
Variables [hide private]
  __rcs_id__ = '$Id: DT_In.py 1069 2008-11-13 21:55:43Z stefan $'
  In = InFactory()
  __package__ = 'qm.external.DocumentTemplate'