Utilisation des attributs.
[Plinn.git] / skins / generic / load_revision.py
1 ##parameters=pos
2 from Products.CMFCore.utils import getToolByName
3 from Products.CMFCore.permissions import ModifyPortalContent
4 from Products.Plinn.utils import getAdapterByInterface, translate
5 def _(message) : return translate(message, context).encode('utf-8')
6 mtool = getToolByName(context, 'portal_membership')
7
8 req = context.REQUEST
9 resp = req.RESPONSE
10 form = req.form
11
12 req.other['syncFragments'] = ['Breadcrumbs']
13 options = {}
14 ctxOptions = {}
15
16 history = getAdapterByInterface(context, 'Products.Plinn.interfaces.IContentHistory', None)
17 key = traverse_subpath[0]
18
19 rev, revCtx = history.getHistoricalRevisionByKey(key, withContext=form['pos'])
20 ctxOptions['rev'] = rev
21 ctxOptions['currentOb'] = context
22 ctxOptions['pos'] = pos
23 ctxOptions['revCtx'] = revCtx
24 userName = revCtx['current']['user_name']
25 if userName :
26 userId = userName.split()[-1]
27 memberFullName = mtool.getMemberFullNameById(userId, nameBefore=False)
28 else :
29 memberFullName = _('nobody')
30 ctxOptions['ctUser'] = memberFullName
31 ctxOptions['ctTime'] = revCtx['current']['time'].strftime(_('%Y/%m/%d at %I:%M:%S %p'))
32 ctxOptions['restorationAllowed'] = mtool.checkPermission(ModifyPortalContent, context)
33 options['specialCtxHeader'] = context.revision_context_header(**ctxOptions).encode('utf-8')
34
35 breadcrumbs = context.breadcrumbs()
36 breadcrumbs.append(
37 {'id' : key
38 ,'title' : _('state of %s') % revCtx['current']['time'].strftime(_('%Y/%m/%d at %I:%M:%S %p'))
39 , 'url' : '%s?pos:int=%d' % (req.ACTUAL_URL, pos)}
40 )
41
42 options['breadcrumbs'] = breadcrumbs
43
44 ti = context.getTypeInfo()
45 method_id = ti.queryMethodID('view', context=context)
46 meth = getattr(rev, method_id)
47 return meth(**options)