1 # (c) 2003 Centre de Recherche en Informatique ENSMP Fontainebleau <http://cri.ensmp.fr>
2 # (c) 2003 Benoît PIN <mailto:pin@cri.ensmp.fr>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 2 as published
6 # by the Free Software Foundation.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 from OFS
.Image
import cookId
20 from Globals
import InitializeClass
22 from Products
.CMFCore
.permissions
import View
, ModifyPortalContent
23 from AccessControl
import ClassSecurityInfo
24 from Products
.Photo
import Photo
25 from BaseSlot
import BaseSlot
27 factory_type_information
= ( {'id' : 'Image Slot',
28 'meta_type' : 'Image Slot',
29 'description' : "Image Slot for Mosaic Document",
30 'icon' : 'mosaic_tool/photo_icon.gif',
31 'product' : 'MosaicDocument',
32 'factory' : 'addImageSlot',
33 'immediate_view' : 'view',
37 'action' : 'slot_image_view',
38 'permissions' : (View
, )
43 'action' : 'slot_image_form',
44 'permissions' : (ModifyPortalContent
, )
50 class ImageSlot(BaseSlot
, Photo
) :
52 meta_type
= 'Image Slot'
53 manage_options
= Photo
.manage_options
55 _indexableFields
= ('title',)
57 security
= ClassSecurityInfo()
60 def __init__(self
, parentContainer
, id, title
='', file='',
61 content_type
='', precondition
='', blankThumbnail
= '', **kw
) :
62 blankThumbnailOb
= None
64 blankThumbnailOb
= parentContainer
.restrictedTraverse(blankThumbnail
)
65 Photo
.__init
__(self
, id, title
=title
, file=file,
66 defaultBlankThumbnail
= blankThumbnailOb
, **kw
)
69 # This method is overloaded to manage file upload.
70 # It's necessary to use manage_upload method from image
71 # because manage_upload invoke update_data and the overload of
72 # update_data in Photo product update the internal thumbnail image.
73 security
.declareProtected(ModifyPortalContent
, 'edit')
74 def edit(self
, title
='', thumb_width
='440', thumb_height
='440', file='', REQUEST
=None):
75 """ Edit image slot"""
77 self
.manage_upload(file=file)
79 if self
.thumb_height
!= thumb_height
or thumb_width
!= thumb_width
:
80 if thumb_width
<= thumb_height
:
81 self
.manage_editProperties(thumb_width
=thumb_width
, thumb_height
=thumb_height
)
83 self
.manage_editProperties(thumb_width
=thumb_height
, thumb_height
=thumb_width
)
85 self
.manage_editProperties(title
= title
, no_refresh
= 1)
87 view
= index_html
= __call__
= Photo
.index_html
89 InitializeClass(ImageSlot
)
91 def addImageSlot(dispatcher
, id, file='', title
='',
92 precondition
='', content_type
='', REQUEST
=None, **kw
) :
94 Add a new Photo object.
95 Creates a new Photo object 'id' with the contents of 'file'.
99 content_type
=str(content_type
)
100 precondition
=str(precondition
)
102 id, title
= cookId(id, title
, file)
103 parentContainer
= dispatcher
.Destination()
105 # First, we create the image without data:
106 parentContainer
._setObject
(id, ImageSlot(parentContainer
, id,title
,'',content_type
, precondition
, **kw
))
108 # Now we "upload" the data. By doing this in two steps, we
109 # can use a database trick to make the upload more efficient.
111 parentContainer
._getOb
(id).manage_upload(file)
113 parentContainer
._getOb
(id).content_type
=content_type
115 if REQUEST
is not None:
116 try: url
=dispatcher
.DestinationURL()
117 except: url
=REQUEST
['URL1']
118 REQUEST
.RESPONSE
.redirect('%s/manage_main' % url
)