m
rFc           @   s  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 l Z d k l Z l Z d k l Z d	 k Td
 k Z d
 k Z d
 k Z d
 k Z h  d d d f <d d d f <d d d f <d d d f <d d d f <d d d f <Z d Z d Z e i e e  Z d   Z d e e
 e e e f d     YZ e d e    Z  d d d d  d  d  e! d!  Z" e e  d" e# f d#     YZ$ d
 S($   s   Photo Folder

Photo Folder objects help manage a group of Photo objects by providing
an interface for adding, removing, and modifying the properties and
display sizes of all contained photos, and by providing defaults for
newly created photos.
(   s
   Persistents   InitializeClasss   DTMLFile(   s   ObjectManager(   s   Item(   s   PropertyManager(   s   FindSupport(   s   RoleManager(   s   getSecurityManagers   ClassSecurityInfo(   s   Photo(   t   *Nt	   thumbnaili   t   xsmalli   t   smalli@  t   mediumi  t   largei   t   xlargei   sJ    ,+&;()[]{}ݟtJ   ___________AAAAAAaaaaaaCcEEEEEeeeeeIIIIiiiiNnOOOOOOooooooSssUUUUuuuuYYyyZzc         C   s   t  i |  t  S(   sX    Cleanup an id
        Should be more thorough and e.g. remove trailing dots/spaces
    N(   t   stringt	   translatet   strt   TRANSMAP(   R
   (    (    t@   /home2/kennisonb/webapps/zope/Zope/Products/Photo/PhotoFolder.pyt
   cleanup_idF   s     t   PhotoFolderc           B   s  t  Z d  Z d Z h  d d <d d <d d <h  d d <d d	 <d d
 <d d <f 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 e i e i e i e	 i Z e
   Z d d d d d d  Z e i d d  e d e    Z e e e d   Z e i d! d"  d#   Z d$   Z e i d! d%  d&   Z e i d! d'  d(   Z e i d! d)  d*   Z e i d! d+  dP d-  Z e i d.  d/   Z e i d0 d  e d1 e    Z e i d0 d2  e d3  Z e i d0 d4  e d5  Z e i d0 d6  e d7  Z e i d0 d8  e d9  Z e i d0 d  e d: e    Z  e i d0 d;  e d<  Z! e i d0 d=  e d>  Z" e i d0 d?  e d@  Z# e i d0 dA  e dB  Z$ e i d0 dC  e e dD  Z% e i d0 dE  e e dF  Z& e i d dG  dH   Z' dI   Z( e i dJ d  e dK e    Z) dL   Z* e i dJ dM  d d e dN  Z+ dO   Z, RS(Q   s1  Photo Folder object implementation.

    Photo Folder objects are folders that can contain Photo objects
    and other supporting objects.  They provide properties to all
    Photos and other Photo Folders in them.  They also provide
    support methods for displaying Photos in an album-like manner.
    s   Photo Foldert   idt   titlet   typeR   t   modet   wt   imaget	   selectiont   wdt   select_variablet   image_selectt   labelt   Contentst   actiont   manage_mains   Photo Propertiest   manage_editPhotoPropertiesFormt   Displayst   manage_editDisplaysFormt   Viewt    t	   Zipuploadt   manage_addzipfileformt   Imaget   ImageMagickiK   i    c   	      C   s   d |  _ | |  _ | |  _ d |  _ |  i i d d  |  i i d  } | i	 d | d  | i	 d | d  | i	 d | d  | i	 d	 | d
  | i	 d | d  |  i i d d  t i   |  _ d  S(   Ns   1.2.3R!   t	   photoconft   storeR   t   enginet   qualityt   intt   pregent   booleant   timeoutt   photos(   t   selft   __version__R   R   R   t   propertysheetst   manage_addPropertySheett   getR&   t   manage_addPropertyR'   R(   R)   R+   R-   t   defaultdisplayst   copyt	   _displays(	   R/   R   R   R'   R(   R)   R+   R-   R&   (    (    R   t   __init__m   s    				t   default_htmls   dtml/sampleFolderViewc         K   s   d } t |  i |  o% t |  i |  } | i |   } nB t |  i |  o% t |  i |  } | i |   } n
 |  i } t	 | | |  f | f |  S(   s    Show default view t   photo_folder_indexN(   t   template_idt   hasattrR/   t   aq_baset   getattrt   templatet   __of__t	   aq_parentR9   t   applyt   clientt   REQUESTt   kw(   R/   RC   RD   t   RESPONSERE   R;   R?   (    (    R   t
   index_html   s     	s   Access contents informationt   photoIdsc         C   s   |  i d g  S(   s%   Return list of Photos in this folder.t   PhotoN(   R/   t	   objectIds(   R/   (    (    R   RH      s     c         C   s   d g |  i   S(   NR!   (   R/   RH   (   R/   (    (    R   R      s    t	   numPhotosc         C   sI   t  |  i d g   } x* |  i d g  D] } | | i   } q+ W| S(   s'   Return number of Photos in folder tree.RI   s   Photo FolderN(   t   lenR/   RJ   R.   t   objectValuest   folderRK   (   R/   R.   RN   (    (    R   RK      s      t   nextPhotoFolderc         C   se   |  i   } |  i i d g  } | i   | | d j o d Sn t |  i | | i	 |  d  S(   s   Return next Photo Folder.s   Photo Folderii   N(
   R/   t   getIdR   RA   RJ   t	   folderIdst   sortt   NoneR>   t   index(   R/   RQ   R   (    (    R   RO      s     
t   prevPhotoFolderc         C   se   |  i   } |  i i d g  } | i   | | d j o d Sn t |  i | | i	 |  d  S(   s   Return previous Photo Folder.s   Photo Folderi    i   N(
   R/   RP   R   RA   RJ   RQ   RR   RS   R>   RT   (   R/   RQ   R   (    (    R   RU      s     
t
   displayIdsR   c         C   sX   |  i i   } x, | D]$ } | | j o | i |  q q W| i |  i d   | S(   s   Return list of display Ids.c         C   s5   t  | |  d | |  d | | d | | d  S(   Ni    i   (   t   cmpt   dt   xt   y(   RY   RZ   RX   (    (    R   t   <lambda>   s    N(   R/   R7   t   keyst   idst   excludeR   t   removeRR   (   R/   R^   R]   R   (    (    R   RV      s      t
   displayMapc         C   sb   g  } xU |  i g   D]D } | i h  d | <d |  i | d <d |  i | d < q W| S(   s'   Return list of displays with size info.R   t   widthi    t   heighti   N(   t   displaysR/   RV   R   t   appendR7   (   R/   Rc   R   (    (    R   R`      s      Bs   Manage propertiess   dtml/editPhotoPropertiesFormt   manage_editPhotoSettingsc         C   s   |  i i d  } | i |  | i i d d  o_ x\ |  i d g  D]D } | i
 d | i i d  i d   | i i d  i |  qH Wn | d j	 o |  i | d d Sn d S(   s   Edit photo settings.R&   t	   changeallRI   R'   t   manage_tabs_messages   Default photo settings updated.N(   R/   R1   R3   R&   t   manage_editPropertiesRD   t   formRS   RM   t   photot   sett   getPropertyR   (   R/   RD   Rj   R&   (    (    R   Re      s      %!	t   manage_editPhotoPropertiesc         C   sG   |  i i d  } | i |  | d j	 o |  i | d d Sn d S(   s   Edit photo properties.R.   Rg   s   Photo properties updated.N(   R/   R1   R3   t
   photosheetRh   RD   RS   R   (   R/   RD   Rn   (    (    R   Rm      s     	t   manage_delPhotoPropertiesc         C   s   |  i i d  } | i |  x5 |  i d g  D]! } y | i |  Wq2 q2 Xq2 W| d j	 o |  i
 | d d Sn d S(   s   Delete photo properties.R.   RI   Rg   s   Photo properties deleted.N(   R/   R1   R3   Rn   t   manage_delPropertiesR]   RM   Rj   RD   RS   R   (   R/   R]   RD   Rj   Rn   (    (    R   Ro      s        	t   manage_addPhotoPropertyc         C   s   |  i i d  } | i | | |  x; |  i d g  D]' } y | i | | |  Wq8 q8 Xq8 W| d j	 o |  i | d d Sn d S(   s   Add photo property.R.   RI   Rg   s   Photo property added.N(   R/   R1   R3   Rn   R4   R   t   valueR   RM   Rj   RD   RS   R   (   R/   R   Rr   R   RD   Rj   Rn   (    (    R   Rq     s        	s   dtml/editFolderDisplaysFormt   manage_editDisplaysc         C   s   |  i } xK | D]C } | | i | i | i f j o | i | i f | | i <q q W| |  _ | d j	 o |  i
 | d d Sn d S(   s   Edit displays.Rg   s   Displays changed.N(   R/   R7   RX   Rc   t   displayR   Ra   Rb   RD   RS   R   (   R/   Rc   RD   RX   Rt   (    (    R   Rs     s     	  !		t   manage_delDisplaysc         C   s   |  i } x# | D] } y | | =Wq q Xq W| |  _ x5 |  i d g  D]! } y | i |  WqK qK XqK W| d j	 o |  i
 | d d Sn d S(   s   Delete displays.RI   Rg   s   Displays deleted.N(   R/   R7   RX   R]   R   RM   Rj   Ru   RD   RS   R   (   R/   R]   RD   RX   Rj   R   (    (    R   Ru     s$     	   	   	t   manage_addDisplayc         C   s   |  i } | | f | | <| |  _ x; |  i d g  D]' } y | i | | |  Wq5 q5 Xq5 W| d j	 o |  i | d d Sn d S(   s   Add display.RI   Rg   s   Display added.N(   R/   R7   RX   Ra   Rb   R   RM   Rj   Rv   RD   RS   R   (   R/   R   Ra   Rb   RD   RX   Rj   (    (    R   Rv   -  s     		   	t   manage_regenDisplaysc         C   sO   x$ |  i d g  D] } | i   q W| d j	 o |  i | d d Sn d S(   s,   Regenerate all displays of contained photos.RI   Rg   s   Displays regenerated.N(   R/   RM   Rj   Rw   RD   RS   R   (   R/   RD   Rj   (    (    R   Rw   ;  s      	t   manage_purgeDisplaysc         C   s   | d j o& | d j	 o | i i d g   } n x' |  i d g  D] } | i |  qF W| d j	 o |  i	 | d d Sn d S(   s1   Purge all generated displays of contained photos.R]   RI   Rg   s   Displays purged.N(
   R^   RS   RD   Ri   R3   R/   RM   Rj   Rx   R   (   R/   R^   RD   Rj   (    (    R   Rx   D  s      	t   manage_cleanDisplaysc         C   s   | d j o& | d j	 o | i i d g   } n x' |  i d g  D] } | i |  qF W| d j	 o |  i	 | d d Sn d S(   sC   Purge all generated displays of contained photos that have expired.R]   RI   Rg   s   Expired displays purged.N(
   R^   RS   RD   Ri   R3   R/   RM   Rj   Ry   R   (   R/   R^   RD   Rj   (    (    R   Ry   O  s      	t   zipc         C   s;  t  i d  } |  i } | i }	 |	 d } z t	 | d t
  } x~ | i d  D]m } | i i d  i d  }
 t   i d |  o6 |
 d j o) | i | i i   t | i     qP qP W| i   t i |  } | i d	 d
  | i d d |  i  | i d | d  |  i | |  Wd t i  |  Xd S(   s    Go through the photo folder and find all the external images
            then zip them and send the result to the user
            FIXME: Only try it for those that store data on filesystem.
        s   .tempi    R   RI   R&   R'   R    t   ExtImages   Content-Types   application/x-zips   Content-Dispositions   attachment; filename="%s.zip"s   Content-Lengthi   NR!   (!   t   tempfilet   mktempt   tmpfileR/   RD   t   requestt   PARENTSt   parentst   parentt   ZipFilet   ZIP_DEFLATEDt   outzdRM   t   pR1   R3   Rl   R'   t   getSecurityManagert   checkPermissiont   writet	   _originalt   _get_filenameR
   RP   t   closet   ost   statRF   t	   setHeaderR   t   _copyt   unlink(   R/   RD   RF   R~   R   R   R   R   R   R   R'   (    (    R   Rz   Z  s,     		
 #-
	 c   	      C   s  t  |  t i j oI y t | d  } Wn) t j
 o t d |  i | f  n Xd } n | } d } t  |  t i j oI y t | d  } Wn) t j
 o t d |  i | f  n Xd } n | } d } ya d d >} | i |  } | i |  x4 t |  | j o  | i |  } | i |  qWWn) t j
 o t d |  i t f  n X| o | i   n | o | i   n d S(	   s    Read binary data from infile and write it to outfile
            infile and outfile may be strings, in which case a file with that
            name is opened, or filehandles, in which case they are accessed
            directly.
        t   rbs   %s (%s)i   i    t   wbi   i   N(   R   t   infilet   typest
   StringTypet   opent   instreamt   IOErrorR/   R   t   close_int   outfilet	   outstreamt	   close_outt	   blocksizet   readt   blockR   RL   t   filenameR   (	   R/   R   R   R   R   R   R   R   R   (    (    R   R   w  s>     


   s   Change Photos   dtml/zipfileAddc         C   sn   | t t i | d  t i | d  t i | d   d } t |  } |  i d i | d d d | d	 S(
   s]    Generate id from filename and make sure,
            there are no spaces in the id.
        t   /s   \t   :i   RI   R   R!   t   fileN(
   t   namet   maxR   t   rfindR   R   R/   t   manage_addProductt   manage_addPhotot   zipfile(   R/   R   R   R   (    (    R   t   _add_file_from_zip  s     t   manage_addzipfilec         C   s   t  |  t  d  j	 o{ t | d  ok t |  } x1 | i   D]# } | i |  |  i	 | |  qB W| o  d } |  i |  | d | Sq n. | d j	 o  d } |  i |  | d | Sn d S(   s    Expand a zipfile into a number of Documents.
            Go through the zipfile and for each file in there call
            self.manage_addProduct['Report Document'].manageaddDocument(id,...
        R!   R   s%   The images were successfully created!Rg   s   You must specify a file!N(   R   R   R<   t   ZZipFilet   zft   namelistR   t   setcurrentfileR/   R   RD   t   messageR   RS   (   R/   R   t   content_typeRD   R   R   R   (    (    R   R     s     ) c         C   s  | d  d j o |  i i d  i d  }
 t | d d d |
 } |  i i d  } xD | i
   D]6 \ }	 } y  | i |	 | | i |	   Wqc qc Xqc W|  i i d  } h  } x$ | i
   D] \ }	 } | | |	 <q W| i i d  i |  |  i i   | _ | Sn d S(   s0   Create Photo objects by default for image types.i   s   image/R&   R'   R!   R.   N(   t   typR/   R1   R3   Rl   R'   RI   R   Rj   t   propst   propertyItemst   propidRr   R4   t   getPropertyTypeR&   t   settingst   manage_changePropertiesR7   R6   RS   (   R/   R   R   t   bodyR   Rj   R   Rr   R&   R   R'   (    (    R   t   PUT_factory  s(          (   s	   thumbnail(-   t   __name__t
   __module__t   __doc__t	   meta_typet   _propertiest   PropertyManagert   manage_optionst   RoleManagert   Itemt   FindSupportt   ClassSecurityInfot   securityR8   t   declareProtectedt   DTMLFilet   globalsR9   RS   RG   RH   R   RK   RO   RU   RV   t   declarePrivateR`   R   Re   Rm   Ro   Rq   R   Rs   Ru   Rv   Rw   Rx   Ry   Rz   R   R#   R   R   R   (    (    (    R   R   L   sn    K									

		*	s   dtml/addPhotoFolderFormR$   R%   iK   i    c
      
   C   s   |  i | t | | | | | | |   | o |  i |  } t d t    } | i d d  | i d  i | d  t d t    }
 | i d d  | i d  i |
 d  n |	 d
 j	 o |  i |  |	 d d	 Sn d
 S(   s   Add Photo Folder objects   dtml/sampleViewt
   photo_viewR!   s   Sample Views   dtml/sampleFolderViewR:   s   Sample Folder Viewt   update_menui   N(   R/   t
   _setObjectR   R   R   R'   R(   R)   R+   R-   t   createsamplest   _getObt   obR   R   t
   sampleViewt   manage_addDTMLMethodt   manage_editt   sampleFolderViewRD   RS   R   (   R/   R   R   R'   R(   R)   R+   R-   R   RD   R   R   R   (    (    R   t   manage_addPhotoFolder  s     (R   c           B   s/   t  Z d d  Z d   Z d   Z d   Z RS(   Nic         C   s8   |  i d j o  d |  _ t i |  |  i  Sn d Sd  S(   Ni    i   R!   (   R/   t   hasbeenreadR   R   R   (   R/   t   size(    (    R   R     s    	c         C   s   d |  _ d S(   s0   Ignore since it is only used to figure out size.i    N(   R/   R   (   R/   (    (    R   t   seek  s     	c         C   s   |  i t  i S(   N(   R/   t   getinfoR   t	   file_size(   R/   (    (    R   t   tell  s    c         C   s   d |  _ | |  _ d  S(   Ni    (   R/   R   R   (   R/   R   (    (    R   R     s    	(   R   R   R   R   R   R   (    (    (    R   R     s   		(%   R   t   Globalst
   Persistentt   InitializeClassR   t   OFS.ObjectManagert   ObjectManagert   OFS.SimpleItemR   t   OFS.PropertyManagerR   t   OFS.FindSupportR   t   AccessControl.RoleR   t   AccessControlR   R   RI   R   R|   R   R   R   R5   t	   bad_charst
   good_charst	   maketransR   R   R   R   t   manage_addPhotoFolderFormRS   R   R   R   (   R   R   R5   R|   R   R   R   R   R   R   R   R   R   R   R   R   R   RI   R   R   R   R   R   R   (    (    R   t   ?    s*   $`		" 

