f042b6d5881a6df8e55508a6201da6b7db326ef5
2 from Products
.CMFCore
.utils
import getToolByName
3 from Products
.Portfolio
.utils
import translate
4 def _(message
) : return translate(message
, context
).encode('utf-8')
8 uidh
= getToolByName(context
, 'portal_uidhandler')
9 utool
= getToolByName(context
, 'portal_url')
10 atool
= getToolByName(context
, 'portal_actions')
11 pptool
= getToolByName(context
, 'portal_photo_print', None)
13 selectionUrl
= atool
.getActionInfo('user/selection')['url']
14 portal
= utool
.getPortalObject()
15 portalDepth
= len(portal
.getPhysicalPath())
17 toUrl
= req
.physicalPathToURL
20 if traverse_subpath
[-1] == 'photo_view_ajax' :
21 photoSubPath
= traverse_subpath
[:-1]
24 photoSubPath
= traverse_subpath
27 photo
= portal
.restrictedTraverse(photoSubPath
)
28 photouid
= uidh
.register(photo
)
30 lightboxpath
= req
.SESSION
.get('lightboxpath', None)
31 selectionIsLightbox
= False
32 if lightboxpath
is None :
33 selection
= req
.SESSION
.get('objects_selection', [])
36 lightbox
= portal
.restrictedTraverse(lightboxpath
)
37 selection
= lightbox
.getUidList()
38 selectionIsLightbox
= True
40 req
.SESSION
.set('lightboxpath', None)
41 selection
= req
.SESSION
.get('objects_selection', [])
44 buyable
= bool(pptool
.getPrintingOptionsFor(photo
))
45 sd
= context
.session_data_manager
.getSessionData(create
=1)
46 cart
= sd
.get('cart', None)
47 if cart
and cart
.locked
:
51 options
['buyable'] = buyable
57 try : posOfPhoto
= selection
.index(photouid
)
58 except ValueError : pass
59 options
['backToContextUrl'] = '%s?b_start:int=%s' % (selectionUrl
, posOfPhoto
/bsize
*bsize
)
60 photoPath
= list(photo
.getPhysicalPath())
61 photoPath
.insert(portalDepth
, 'selectioncontext')
62 options
['lastBcUrl'] = toUrl(photoPath
)
63 meth
= getattr(photo
, 'photo_view_ajax_template')
64 return meth(req
, resp
, **options
)
67 for i
, uid
in enumerate(selection
) :
68 b
= uidh
.getBrain(uid
)
69 size
= b
.getThumbnailSize
70 size
= {'width':int(size
['width']/2.0), 'height':int(size
['height']/2.0)}
73 className
= 'selected displayed'
76 className
= 'selected'
78 path
= b
.getPath().split('/')
79 path
.insert(portalDepth
, 'selectioncontext')
81 d
= {'src': '%s/getThumbnail' % b
.getURL()
85 ,'className': className
91 previous
= infos
[posOfPhoto
- 1]['href']
93 previous
= infos
[0]['href']
95 if posOfPhoto
< len(infos
) -1 :
96 next
= infos
[posOfPhoto
+ 1]['href']
98 next
= infos
[-1]['href']
101 contextInfos
= {'infos':infos
,
103 'backUrl' : '%s?b_start:int=%s' % (selectionUrl
, posOfPhoto
/bsize
*bsize
),
104 'index' : posOfPhoto
,
105 'previous' : previous
,
107 'reBaseCtxUrl':'/^%s/' % (portal_url
+'/selectioncontext/').replace('/', '\/'),
108 'canonicalUrl': "'%s/'" % portal_url
}
110 options
['contextInfos'] = contextInfos
112 # breadcrumbs customization
113 if selectionIsLightbox
:
114 lastBcTitle
= '%s (%s)' % (_('My selection'), lightbox
.title_or_id())
116 lastBcTitle
= _('My selection')
120 , 'title' : portal
.title
121 , 'url' : portal_url
},
123 {'id' : 'selection_view'
124 ,'title' : lastBcTitle
125 , 'url' : selectionUrl
},
127 {'id' : photo
.getId()
128 ,'title' : photo
.title_or_id()
129 , 'url' : req
.ACTUAL_URL
}
132 options
['breadcrumbs'] = breadcrumbs
135 ti
= photo
.getTypeInfo()
136 method_id
= ti
.queryMethodID('view', context
=photo
)
137 meth
= getattr(photo
, method_id
)
138 return meth(req
, resp
, **options
)