df3e63b551d8e560acf811185581dba0b8df8998
2 from Products
.CMFCore
.utils
import getToolByName
3 from Products
.Portfolio
.utils
import translate
4 def _(message
) : return translate(message
, context
).encode('utf-8')
7 uidh
= getToolByName(context
, 'portal_uidhandler')
8 utool
= getToolByName(context
, 'portal_url')
9 atool
= getToolByName(context
, 'portal_actions')
10 pptool
= getToolByName(context
, 'portal_photo_print', None)
12 selectionUrl
= atool
.getActionInfo('user/selection')['url']
13 portal
= utool
.getPortalObject()
14 portalDepth
= len(portal
.getPhysicalPath())
16 toUrl
= req
.physicalPathToURL
18 bsize
= portal
.getProperty('default_batch_size', 20)
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 app
= context
.restrictedTraverse('/')
64 meth
= app
.restrictedTraverse(photo
.getPhysicalPath() + ('photo_view_ajax_template',))
65 return meth(req
, resp
, **options
)
68 for i
, uid
in enumerate(selection
) :
69 b
= uidh
.getBrain(uid
)
70 size
= b
.getThumbnailSize
71 size
= {'width':int(size
['width']/2.0), 'height':int(size
['height']/2.0)}
74 className
= 'selected displayed'
77 className
= 'selected'
79 path
= b
.getPath().split('/')
80 path
.insert(portalDepth
, 'selectioncontext')
82 d
= {'src': '%s/getThumbnail' % b
.getURL()
86 ,'className': className
92 previous
= infos
[posOfPhoto
- 1]['href']
94 previous
= infos
[0]['href']
96 if posOfPhoto
< len(infos
) -1 :
97 next
= infos
[posOfPhoto
+ 1]['href']
99 next
= infos
[-1]['href']
102 contextInfos
= {'infos':infos
,
104 'backUrl' : '%s?b_start:int=%s' % (selectionUrl
, posOfPhoto
/bsize
*bsize
),
105 'index' : posOfPhoto
,
106 'previous' : previous
,
108 'reBaseCtxUrl':'/^%s/' % (portal_url
+'/selectioncontext/').replace('/', '\/'),
109 'canonicalUrl': "'%s/'" % portal_url
}
111 options
['contextInfos'] = contextInfos
113 # breadcrumbs customization
114 if selectionIsLightbox
:
115 lastBcTitle
= '%s (%s)' % (_('My selection'), lightbox
.title_or_id())
117 lastBcTitle
= _('My selection')
121 , 'title' : portal
.title
122 , 'url' : portal_url
},
124 {'id' : 'selection_view'
125 ,'title' : lastBcTitle
126 , 'url' : selectionUrl
},
128 {'id' : photo
.getId()
129 ,'title' : photo
.title_or_id()
130 , 'url' : req
.ACTUAL_URL
}
133 options
['breadcrumbs'] = breadcrumbs
136 ti
= photo
.getTypeInfo()
137 method_id
= ti
.queryMethodID('view', context
=photo
)
138 app
= context
.restrictedTraverse('/')
139 meth
= app
.restrictedTraverse(photo
.getPhysicalPath() + (method_id
,))
140 return meth(req
, resp
, **options
)