mò
T¬ Gc           @   sŒ  d  Z  d d d !Z d k l Z l Z l Z d k l Z d k l	 Z	 d k
 l
 Z
 d k l Z d	 k Z d	 k Z d	 k Z d	 k Z d	 k Z d	 k Z d	 k Z d	 k Z d	 k Z e d
 e ƒ  ƒ Z d d e d „ Z d Z d Z d Z d Z d Z  d Z! h  e d <e d <e d <e d <e  d <e! d <Z" d „  Z# d „  Z$ d e i% i& e e i' e i( i) f d „  ƒ  YZ* d f  d „  ƒ  YZ+ d	 S(   s   Tiny Table data manager products   $Revision: 1.29 $i   iþÿÿÿ(   s   HTMLFiles   MessageDialogs
   Persistent(   s   Results(   s   PersistentMapping(   s   DateTime(   s   getBrainNt   Addt    c         C   sA   |  i | t | | | ƒ ƒ | d j	 o |  i |  | ƒ Sn d S(   sË   Add a TinyTablePlus to a folder

    The argument 'self' will be bound to a folder.

    The arguments, 'id' and 'title' are minimal, and most applications
    will have additional needed arguments.
    N(	   t   selft
   _setObjectt   idt   TinyTablePlust   titlet   columnst   REQUESTt   Nonet   manage_main(   R   R   R   R   R   (    (    tJ   /home2/kennisonb/webapps/zope/Zope/Products/TinyTablePlus/TinyTablePlus.pyt   addItem/   s      t   it   lt   nt   st   dt   Ds   :ints   :longs   :floats	   :datetimes   :datec         C   s2   |  t j o d Sn |  t j o d Sn |  Sd  S(   NR   R   (   t   tt
   LongValuedt
   DateValued(   R   (    (    R   t   TypeCodeL   s
    c         C   s—  |  t i j o |  Sn|| t j o˜ t |  ƒ t d ƒ j o t |  ƒ Sn t |  ƒ t d ƒ j oP t |  ƒ t d ƒ j o t |  ƒ }  n y t i	 |  ƒ }  Wqµ d }  qµ Xn |  Sn×| t
 j oq t |  ƒ t d ƒ j oP t |  ƒ t d ƒ j o t |  ƒ }  n y t i |  ƒ }  Wq3d }  q3Xn |  SnY| t j oq t |  ƒ t d ƒ j oP t |  ƒ t d ƒ j o t |  ƒ }  n y t i |  ƒ }  Wq±d }  q±Xn |  SnÛ | t j oU t |  ƒ t i j o |  i t j p' y t |  ƒ }  Wqt i }  qXn |  Sny | t j oa t |  ƒ t i j o |  i t j p' y t |  ƒ }  Wqut i }  quXn t |  i ƒ  ƒ Sn t |  ƒ Sd  S(   Nf0.0i    R   l    (   t   xt   Missingt   ValueR   t	   IntValuedt   typet   intt   strt   stringt   atoiR   t   atolt   FloatValuedt   atoft   DateTimeValuedt   typest   InstanceTypet	   __class__t   DateTimeR   t   Date(   R   R   (    (    R   t
   CoerceTypeT   s\    &&R   c        	   B   s   t  Z d  Z d Z d Z h  d d <d d <h  d d <d d <h  d d	 <d d
 <h  d d <d d <h  d d <d d <f Z d d. f d d/ f d d0 f d d1 f f Z d d d „ Z e d	 e	 ƒ  ƒ Z
 e d e	 ƒ  ƒ Z e d e	 ƒ  ƒ Z e d „ Z d  „  Z e d e	 ƒ  ƒ Z e d! „ Z e d" „ Z d# „  Z d$ „  Z d% „  Z d& „  Z d' „  Z d( „  Z d) „  Z d* „  Z e Z d+ „  Z d, „  Z d- „  Z RS(2   s"  TinyTablePlus is a product designed to manage a small amount of
tabular data.  It's intended to fill the gap between a Z Table or an Z
SQL Methods accessed SQL table, which are overkill for many tasks, and
folder token properties, which allow only a single "column".  TinyTablePlus
also makes it possible to look up an item within the list, or to return
a subset of the list rows where columns equal particular values.

TinyTablePlus Properties

  Columns

    *Columns* is a list of one or more column names separated by
    spaces. Columns are string-typed by default, but may optionally
    be integers, long integers, floating-point, or DateTime if the
    column name is suffixed with ':int', ':long', ':float', or ':date'
    or ':datetime' respectively.  ':date' and ':datetime' both store
    Zope DateTime values, but ':date' values are forced to be date-only,
    with no time-of-day information.

    The first column is special. An index will be built on this
    column for "lookup" use (see below). The index built is unique.
    That is, if there are multiple rows with the same first-column
    value, only one row will appear in the index, and only one row
    will be returned from an index query. If this is a problem, use
    a filter on the first row instead (see below).

  Data

    The data consists of newline-separated rows containing columns
    separated by commas.  Any input data will be adjusted to conform to
    the column specification.  If the row contains too many columns the
    excess will be trimmed.  If the row contains to few columns, columns
    containing NULL will be added.  String values in a column specified
    to take a number will be replaced by 0.
    
    The form of values is similar to Python syntax. Strings are enclosed
    in single or double quotes, and backslash escapes are possible.
    Numbers may be entered just as in Python.  Full Python syntax for
    floating point numbers is supported, including exponent notation. 
    Dates and Date-Times are represented by strings in any of the
    formats thet the Zope DateTime class understands.  Missing (NULL)
    may also be given as a value for a cell, by using 'NULL' or 'None',
    or by simply omitting the value (for example, 1,,3' is treated as
    '1,NULL,3')

    Python comments ('#') and line continuations may also be used.
    Note, however, that once TinyTablePlus extracts the data from the input
    text, the text is thrown away.  When visiting the management edit
    interface again, the text will be regenerated from the stored data.
    Comments, blank lines, line continuations, and such will all be lost
    since they don't alter the data itself.
    
  Querying a TinyTablePlus

    Assume you have a table named MyTable. It has these properties:

    Columns::

      last first middle n:int x:long

    and the following data::

      "smith", "john", "x", 0, 0L
      "smith", "bob", "x", 0, 0L
      "smith", "bob", "z", 0, 0L
      "jones", "bob", "y", 0, 0L
      "jones", "john", "y", 0, 0L
      "jones", "john", "z", 0, 0L 

    The data can be queried from DTML in several ways:

      Full Query::

        <!--#in MyTable-->

        Iterates through all rows of the TinyTablePlus. Within the
        region contained by 'in' tag, the column names will be
        available as variables and so can be insterted. For
        example on the first iteration, '<!--#var first-->' will
        be replaced with 'john'.

      Index Query::

        <!--#in "MyTable('jones')"-->

        The passed argument will be looked up in the table's
        index of the first column. Because the index is unique,
        either zero (if no matching rows) or one (if any
        matching rows) rows will be iterated through. In this
        case, any *one* of the three rows with a last name of
        'jones' could be returned. The choice of which row is
        returned when multiple rows have the same index value is
        unspecified.

      Filter Query::

        <!--#in "MyTable(last='jones')"-->
        <!--#in "MyTable(first='john')"-->
        <!--#in "MyTable(last='jones', middle='y')"-->

        When one or more named arguments is given, a filter
        query is performed. Each argument name must be the name
        of a column, and the corresponding value is compared
        against that column in each row. Only matching rows are
        returned. The first example above, in contrast with the
        index query example, returns *all three* rows where the
        last name is 'jones'.

        While an Index Query operates only on the first column,
        a filter query can operate on any column. In the second
        exmple above, all three rows with the first name 'john'
        are returned.

        Finally, multiple filters may be specified. In this
        case only rows matching all contraints are iterated
        through. In the third example above, only the two rows
        where the last name is 'jones' and the middle initial is
        'y' will be returned.

      Shane's mods:
      
        There are four new methods, a change in the specification
        of column names, and minor mods throughout.
        These changes make it possible to use
        TinyTablePlus as a small database table, which can be very
        useful in a variety of situations.  It is recommended, however,
        that TinyTablePlus only be used this way when accessed through
        a DatabaseConnector, so that a better implementation can
        be swapped in easily.

        1. setRow(columnName=value, ...)

            setRows allows you to set the data in the table.  If there
            are any 'key' columns, it will try to match the key columns
            and update a row.  If there are no key columns or the
            values in the key are not matched by any row, a new row
            will be added.  See the explanation for key columns below.

        2. delRows(columnName=value, ...)

            Deletes all rows that match the filter.

        3. delAllRows()

            Deletes all rows.

        4. getRows(columnName=value, ...)

            A synonym for the query interface.  Using the getRows()
            method is sometimes easier to read in DTML or Python
            code.

        Key columns:

        In a real database, key columns let you specify columns that
        can uniquely identify a record.  If you try to add a row with
        values in the key column that are the same as the corresponding
        values in a row that already exists, the database will reject
        the new row.

        TinyTablePlus takes a less formal approach and only pays
        attention to key columns in the setRow() method.  setRow()
        is a combination of both 'insert' and 'update' operations.
        It tries to find a row with the specified values in the
        key columns, and if found will update that row.  It will
        ignore any other rows that happen to match.

        To specify which columns in the table are key columns,
        add an asterisk after the column name.  For example:

        login* name email birthdate

        A table that uses those column names might have the following
        data:

        "joe", "Joe Brown", "jbrown@xyz.com", "10/12/66"
        "eliza", "Eliza Weizenbaum", "eliza@univ.edu", "1/1/70"

        Because the login column is a key column, the following call:

        setRow(login='eliza', birthdate='unknown')

        ...would change the table data to:

        "joe", "Joe Brown", "jbrown@xyz.com", "10/12/66"
        "eliza", "Eliza Weizenbaum", "eliza@univ.edu", "unknown"

        setRow() found a row that matched all specified key
        columns and changed that row rather than add a new row.
        More than one key column is possible.
        The following call:

        setRow(login='harry', name='Harry Chaste', birthdate='1/1/00',
               email='unknown')

        ...would add to the table a new row since there is no
        row with the value of 'harry' in the login column.  The
        table would look like this:

        "joe", "Joe Brown", "jbrown@xyz.com", "10/12/66"
        "eliza", "Eliza Weizenbaum", "eliza@univ.edu", "unknown"
        "harry", "Harry Chaste", "unknown", "1/1/00"

        Please keep in mind that TinyTablePlus does *not* scale well.
        It is very useful for reference implementations of a database,
        but don't use it in the final version your new e-commerce product.
        I (Shane) have no intention of improving its scaleability
        because that is the need that DatabaseAPI / DatabaseConnector
        (a product which I wrote myself) is intended to address.
        
        R   s   misc_/TinyTablePlus/icont   labelt
   Propertiest   actionR
   t   Advancedt   manage_advancedFormt   Viewt   manage_viewt   Securityt   manage_accesst   Aboutt   manage_abouts   View management screenst   manage_tabss   Change permissionss   Change TinyTablet   manage_editt   manage_editDatat   manage_advancedt   delRowst
   delAllRowst   setRows   Query TinyTable DataR   t
   index_htmlt   getRowsc         C   sT   | |  _  d |  _ |  i | | ƒ g  |  _ t ƒ  |  _ d |  _	 |  _
 d  |  _ d  S(   Ni   R   (   R   R   t   _datavert	   _SetStateR   R   t   _rowst   PersistentMappingt   _indext   class_name_t   class_file_R	   t   _v_brain(   R   R   R   R   (    (    R   t   __init__€  s    			t   Editc         C   s?   |  i | | ƒ t |  i |  i ƒ |  _ |  i ƒ  |  i | ƒ S(   sq   Change item properties

	Note that we return people to our own interface, not to
	the folder we were in before.
	N(
   R   R?   R   R   t   mapt   _FixRowR@   t   _GenerateIndext   manage_editedDialogR   (   R   R   R   R   (    (    R   R6   ”  s
     
c         C   sA   | |  _  |  i d j  o |  i d =n |  i | ƒ d |  _ d  S(   Ni   t   delim_char_(   R   R   R>   t   __dict__t   _DigestColumnsR   (   R   R   R   (    (    R   R?   ¤  s
    	c         C   s;   | | |  _ |  _ t |  i |  i d ƒ |  _ |  i | ƒ S(   s   Change Advanced Settingsi   N(	   t
   class_namet
   class_fileR   RC   RD   t   getBrainRE   RK   R   (   R   RO   RP   R   (    (    R   R8   ®  s     c         C   s;   t  i | ƒ } t |  i | ƒ |  _ |  i ƒ  |  i	 | ƒ S(   s   Change item dataN(   t   ImportExportt
   ImportDatat   datat   newRowsRH   R   RI   R@   RJ   RK   R   (   R   RT   R   RU   (    (    R   R7   ´  s
     
c   	      C   sì  t  ƒ  |  _ g  |  _ g  |  _ g  |  _ t i | ƒ } g  |  _
 xS| D]K} t  ƒ  } t i | d ƒ } | d } | d d j o! | d d !} |  i
 i | ƒ n |  i i | ƒ | | d <t } t | ƒ d j o‹ | d d j o
 t } qa| d d j o
 t } qa| d d	 j o
 t } qa| d d
 j o
 t } qa| d d j o
 t } qan |  i i | ƒ t | ƒ | d <|  i i | ƒ qF Wt |  i ƒ |  _ |  i d |  _ d } x( |  i D] } | |  i | <| d } qÇWd  S(   Nt   :i    iÿÿÿÿt   *t   namei   R   t   longt   floatt   datetimet   dateR   (   RA   R   t
   _col_indext
   _col_namest   _typest   _itemsR   t   splitt   column_listt   colst	   _key_colst   colt   itemR   t   x0t   appendt   StringValuedR   t   lenR   R   R!   R#   R   R   t   n_colst   index_columnt   col_num(	   R   Rb   Rm   Rc   Rf   R   Rg   Re   R   (    (    R   RN   ½  sL    				 	






 c         C   sª   t  | ƒ |  i j o | |  i  } n< t  | ƒ |  i j  o% | |  i t  | ƒ t i g } n g  } x; t d |  i ƒ D]' } | i	 t
 | | |  i | ƒ ƒ q{ W| S(   Ni    (   Rj   t   rowR   Rk   R   R   t   newrowt   rangeR   Rh   R)   R_   (   R   Rn   Ro   R   (    (    R   RI   é  s    % %c         C   sN   t  ƒ  } x5 t d t |  i ƒ ƒ D] } | | |  i | d <q" W| |  _ d  S(   Ni    (   RA   t   indexRp   Rj   R   R@   R   RB   (   R   Rq   R   (    (    R   RJ   ÷  s
    	 c         C   sŠ   g  } xq t d |  i ƒ D]] } |  i | t |  i | } t	 |  d ƒ o | |  i
 j o | d } n | i | ƒ q Wt i | d ƒ S(   Ni    Rd   RW   t    (   R   Rp   R   Rk   R   R^   t	   TypeNamesR_   RX   t   hasattrRd   Rh   R   t   join(   R   RX   R   R   (    (    R   t	   cols_textý  s      c         C   s   t  i |  i ƒ S(   N(   RR   t
   ExportDataR   R@   (   R   (    (    R   t	   data_text	  s    c         C   sf   d } | t i |  i d ƒ d } x8 |  i D]- } | d t i t t | ƒ d ƒ d } q- W| d S(	   s:   Returns an HTML representation of the TinyTablePlus's datas$   <table border=1 summary=''><tr>
<th>s
   </th>
<th>s   </th>
</tr>
s	   <tr>
<td>s
   </td>
<td>s   </td>
</tr>
s   </table>N(	   R   R   Ru   R   R^   R@   Rn   RH   R   (   R   R   Rn   (    (    R   R<     s     
 +c         C   sX   t  |  d ƒ o |  i } n t |  i |  i ƒ } |  _ t |  i | f d | d d  ƒS(   NRE   t   brainst   parent(   Rt   R   RE   t   brainRQ   RD   RC   t   ResultsR`   t   rowsR	   (   R   R}   R{   (    (    R   t   _results  s    c         O   sî   t  | ƒ d j oE |  i i | d ƒ o& |  i |  i |  i | d g ƒ Sqê d  Sn“ t  | ƒ ou t	 |  | ƒ } g  } xL t d t  |  i ƒ ƒ D]2 } | |  i | ƒ o | i |  i | ƒ q“ q“ W|  i | ƒ Sn |  i |  i ƒ Sd  S(   Ni   i    (   Rj   t   argsR   RB   t   has_keyR~   R@   R	   t   kargst	   RowFiltert   rfR   Rp   R   Rh   (   R   R   R   R   R   Rƒ   (    (    R   t   __call__  s    & c         O   s  t  | ƒ d j o] |  i i | d ƒ o> |  i | d } | d j o |  i | =|  i ƒ  d Sql qd Sn“ t  | ƒ o t	 |  | ƒ } d } d } xQ | t  |  i ƒ j  o: | |  i | ƒ o |  i | =| d } q› | d } q› W|  i ƒ  | Sn d Sd S(   s,   Returns the number of rows deleted.
        i   i    N(   Rj   R   R   RB   R€   R   R@   RJ   R   R‚   Rƒ   t   count(   R   R   R   R…   R   Rƒ   (    (    R   R9   4  s,     

 

c         C   s   t  |  i ƒ } |  i 2| S(   s   Deletes all rows.
        N(   Rj   R   R@   R…   (   R   R…   (    (    R   R:   P  s     c         O   sæ  d } d } t |  d ƒ oþ |  i } t | ƒ d j oÞ h  } xl | D]d }
 |  i
 |
 } | i |
 ƒ o | |
 | | <qE | t | ƒ j  o | | | | <qE d | | <qE Wxf |  i D]W } d }	 x6 | i ƒ  D]( \ } } | | | j o d }	 PqÐ qÐ W|	 o | } Pq· q· Wqn | d j o |  i t i g } d } n x+ t d t | ƒ ƒ D] } | | | | <qZWxH | i ƒ  D]: \ } } |  i
 i | ƒ o |  i
 | } | | | <qqW| o |  i i | ƒ n |  i ƒ  d S(   s"   Adds or modifies one row.
        i    Rd   R   i   N(   R	   Rn   t   willAddRt   R   Rd   t   key_colsRj   t   filtert   key_colR]   Rq   t   kwR€   R   R@   t   rt   foundt   itemst   valRk   R   R   Rp   t   col_nameRh   RJ   (   R   R   RŠ   R‡   RŽ   Rq   R   Rˆ   R‹   RŒ   R‰   R†   Rn   (    (    R   R;   W  sP     	 
  	
  (   s   manage_tabss   manage_mains   manage_abouts   manage_advancedForm(   s   manage_access(   s   manage_edits   manage_editDatas   manage_advanceds   delRowss
   delAllRowss   setRow(   R   s
   index_htmls   manage_views   getRows(   t   __name__t
   __module__t   __doc__t	   meta_typet   icont   manage_optionst   __ac_permissions__RF   t   HTMLFilet   globalsR0   R4   R
   R	   R6   R?   R.   R8   R7   RN   RI   RJ   Rv   Rx   R<   R~   R„   R=   R9   R:   R;   (    (    (    R   R   ‹   s4   Ø o	*				,					
				R‚   c           B   s   t  Z d „  Z d „  Z RS(   Nc         C   sˆ   g  |  _ g  |  _ d |  _ xf | i ƒ  D]X } | i i	 | ƒ o? |  i i
 | i | ƒ |  i i
 | | ƒ |  i d |  _ q( q( Wd  S(   Ni    i   (   R   Rc   t   valst   n_rulest   rulest   keysRe   t   tableR]   R€   Rh   (   R   R   R›   Re   (    (    R   RF     s    			 c         C   sH   xA t  d |  i ƒ D]- } | |  i | |  i | j o d Sq q Wd S(   Ni    i   (   Rp   R   Rš   R   Rn   Rc   R™   (   R   Rn   R   (    (    R   R„   š  s
     (   R   R‘   RF   R„   (    (    (    R   R‚   Ž  s   	(,   R’   t   __version__t   GlobalsR—   t   MessageDialogt
   Persistentt   Shared.DC.ZRDB.ResultsR|   t   persistent.mappingRA   R'   t   App.ExtensionsRQ   t   OFS.ObjectManagert   OFSt   OFS.SimpleItemt   Acquisitiont   AccessControl.Rolet   AccessControlt   RecordR   R   R$   RR   R˜   t   addItemFormR	   R   R   R   R!   Ri   R#   R   Rs   R   R)   t
   SimpleItemt   Itemt   Implicitt   Rolet   RoleManagerR   R‚   (   R   R)   R   R!   R'   R#   Rs   RA   R   R   R‚   R¨   Rž   R’   Ri   R   R   R¡   RQ   R«   R   R    R¬   R$   Rª   RR   R¦   R—   R|   R   (    (    R   t   ?   s0   $$	<			7.ÿ ÿ 