fa7c0901be3910063b4f97a97ee06adda22e0a6b
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()
85 ,'title' : b
.Description
86 ,'className' : className
87 ,'displayed' : uid
== photouid
93 previous
= infos
[posOfPhoto
- 1]['href']
95 previous
= infos
[0]['href']
97 if posOfPhoto
< len(infos
) -1 :
98 next
= infos
[posOfPhoto
+ 1]['href']
100 next
= infos
[-1]['href']
103 contextInfos
= {'infos':infos
,
105 'backUrl' : '%s?b_start:int=%s' % (selectionUrl
, posOfPhoto
/bsize
*bsize
),
106 'index' : posOfPhoto
,
107 'previous' : previous
,
109 'reBaseCtxUrl':'/^%s/' % (portal_url
+'/selectioncontext/').replace('/', '\/'),
110 'canonicalUrl': "'%s/'" % portal_url
}
112 options
['contextInfos'] = contextInfos
114 # breadcrumbs customization
115 if selectionIsLightbox
:
116 lastBcTitle
= '%s (%s)' % (_('My selection'), lightbox
.title_or_id())
118 lastBcTitle
= _('My selection')
122 , 'title' : portal
.title
123 , 'url' : portal_url
},
125 {'id' : 'selection_view'
126 ,'title' : lastBcTitle
127 , 'url' : selectionUrl
},
129 {'id' : photo
.getId()
130 ,'title' : photo
.title_or_id()
131 , 'url' : req
.ACTUAL_URL
}
134 options
['breadcrumbs'] = breadcrumbs
137 ti
= photo
.getTypeInfo()
138 method_id
= ti
.queryMethodID('view', context
=photo
)
139 app
= context
.restrictedTraverse('/')
140 meth
= app
.restrictedTraverse(photo
.getPhysicalPath() + (method_id
,))
141 return meth(req
, resp
, **options
)