Improved pod field with specific, static or dynamic pod context.
This commit is contained in:
parent
ecd9c66ca1
commit
9974769075
|
@ -470,12 +470,13 @@ class Pod(Type):
|
||||||
searchable=False, specificReadPermission=False,
|
searchable=False, specificReadPermission=False,
|
||||||
specificWritePermission=False, width=None, height=None,
|
specificWritePermission=False, width=None, height=None,
|
||||||
master=None, masterValue=None, focus=False, historized=False,
|
master=None, masterValue=None, focus=False, historized=False,
|
||||||
template=None):
|
template=None, context=None):
|
||||||
Type.__init__(self, None, (0,1), index, default, optional,
|
Type.__init__(self, None, (0,1), index, default, optional,
|
||||||
False, show, page, group, move, indexed, searchable,
|
False, show, page, group, move, indexed, searchable,
|
||||||
specificReadPermission, specificWritePermission, width,
|
specificReadPermission, specificWritePermission, width,
|
||||||
height, master, masterValue, focus, historized)
|
height, master, masterValue, focus, historized)
|
||||||
self.template = template # The path to a POD template
|
self.template = template # The path to a POD template
|
||||||
|
self.context = context # A dict containing a specific pod context
|
||||||
|
|
||||||
# Workflow-specific types ------------------------------------------------------
|
# Workflow-specific types ------------------------------------------------------
|
||||||
class State:
|
class State:
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
import os, os.path, time
|
import os, os.path, time, types
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
from appy.shared import mimeTypes
|
from appy.shared import mimeTypes
|
||||||
from appy.shared.utils import getOsTempFolder
|
from appy.shared.utils import getOsTempFolder
|
||||||
|
@ -128,7 +128,9 @@ class FlavourMixin(AbstractMixin):
|
||||||
res['formats'] = getattr(appyFlavour, n)
|
res['formats'] = getattr(appyFlavour, n)
|
||||||
n = appyFlavour.getAttributeName('podTemplate', appyClass, fieldName)
|
n = appyFlavour.getAttributeName('podTemplate', appyClass, fieldName)
|
||||||
res['template'] = getattr(appyFlavour, n)
|
res['template'] = getattr(appyFlavour, n)
|
||||||
res['title'] = self.translate(getattr(appyClass, fieldName).label)
|
appyType = ploneObj.getAppyType(fieldName)
|
||||||
|
res['title'] = self.translate(appyType['label'])
|
||||||
|
res['context'] = appyType['context']
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def generateDocument(self):
|
def generateDocument(self):
|
||||||
|
@ -141,11 +143,13 @@ class FlavourMixin(AbstractMixin):
|
||||||
# Get the object
|
# Get the object
|
||||||
objectUid = rq.get('objectUid')
|
objectUid = rq.get('objectUid')
|
||||||
obj = self.uid_catalog(UID=objectUid)[0].getObject()
|
obj = self.uid_catalog(UID=objectUid)[0].getObject()
|
||||||
|
appyObj = obj.appy()
|
||||||
# Get information about the document to render. Information comes from
|
# Get information about the document to render. Information comes from
|
||||||
# a PodTemplate instance or from the flavour itself, depending on
|
# a PodTemplate instance or from the flavour itself, depending on
|
||||||
# whether we generate a doc from a class-wide template or from a pod
|
# whether we generate a doc from a class-wide template or from a pod
|
||||||
# field.
|
# field.
|
||||||
templateUid = rq.get('templateUid', None)
|
templateUid = rq.get('templateUid', None)
|
||||||
|
specificPodContext = None
|
||||||
if templateUid:
|
if templateUid:
|
||||||
podTemplate = self.uid_catalog(UID=templateUid)[0].getObject()
|
podTemplate = self.uid_catalog(UID=templateUid)[0].getObject()
|
||||||
appyPt = podTemplate.appy()
|
appyPt = podTemplate.appy()
|
||||||
|
@ -158,18 +162,25 @@ class FlavourMixin(AbstractMixin):
|
||||||
format = podInfo['formats'][0]
|
format = podInfo['formats'][0]
|
||||||
template = podInfo['template'].content
|
template = podInfo['template'].content
|
||||||
podTitle = podInfo['title']
|
podTitle = podInfo['title']
|
||||||
|
if podInfo['context']:
|
||||||
|
if type(podInfo['context']) == types.FunctionType:
|
||||||
|
specificPodContext = podInfo['context'](appyObj)
|
||||||
|
else:
|
||||||
|
specificPodContext = podInfo['context']
|
||||||
# Temporary file where to generate the result
|
# Temporary file where to generate the result
|
||||||
tempFileName = '%s/%s_%f.%s' % (
|
tempFileName = '%s/%s_%f.%s' % (
|
||||||
getOsTempFolder(), obj.UID(), time.time(), format)
|
getOsTempFolder(), obj.UID(), time.time(), format)
|
||||||
# Define parameters to pass to the appy.pod renderer
|
# Define parameters to pass to the appy.pod renderer
|
||||||
currentUser = self.portal_membership.getAuthenticatedMember()
|
currentUser = self.portal_membership.getAuthenticatedMember()
|
||||||
podContext = {'tool': appyTool, 'flavour': self.appy(),
|
podContext = {'tool': appyTool, 'flavour': self.appy(),
|
||||||
'user': currentUser,
|
'user': currentUser, 'self': appyObj,
|
||||||
'now': self.getProductConfig().DateTime(),
|
'now': self.getProductConfig().DateTime(),
|
||||||
'projectFolder': appyTool.getDiskFolder(),
|
'projectFolder': appyTool.getDiskFolder(),
|
||||||
}
|
}
|
||||||
|
if specificPodContext:
|
||||||
|
podContext.update(specificPodContext)
|
||||||
if templateUid:
|
if templateUid:
|
||||||
podContext['podTemplate'] = podContext['self'] = appyPt
|
podContext['podTemplate'] = appyPt
|
||||||
rendererParams = {'template': StringIO(template),
|
rendererParams = {'template': StringIO(template),
|
||||||
'context': podContext,
|
'context': podContext,
|
||||||
'result': tempFileName}
|
'result': tempFileName}
|
||||||
|
|
Loading…
Reference in a new issue