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