diff --git a/gen/__init__.py b/gen/__init__.py index e2655e6..e2036da 100644 --- a/gen/__init__.py +++ b/gen/__init__.py @@ -470,13 +470,17 @@ class Pod(Type): searchable=False, specificReadPermission=False, specificWritePermission=False, width=None, height=None, master=None, masterValue=None, focus=False, historized=False, - template=None, context=None): + template=None, context=None, action=None, askAction=False): Type.__init__(self, None, (0,1), index, default, optional, False, show, page, group, move, indexed, searchable, specificReadPermission, specificWritePermission, width, height, master, masterValue, focus, historized) self.template = template # The path to a POD template self.context = context # A dict containing a specific pod context + self.action = action # A method that will be triggered after the + # document has been generated. + self.askAction = askAction # If True, the action will be triggered only + # if the user checks a checkbox, which, by default, will be unchecked. # Workflow-specific types ------------------------------------------------------ class State: diff --git a/gen/plone25/descriptors.py b/gen/plone25/descriptors.py index af298ea..bf99bed 100644 --- a/gen/plone25/descriptors.py +++ b/gen/plone25/descriptors.py @@ -198,6 +198,12 @@ class ArchetypeFieldDescriptor: self.fieldType = 'FileField' self.widgetType = 'FileWidget' self.fieldParams['storage'] = 'python:AttributeStorage()' + # Add i18n-specific messages + if self.appyType.askAction: + label = '%s_%s_askaction' % (self.classDescr.name, self.fieldName) + msg = PoMessage(label, '', PoMessage.POD_ASKACTION) + self.generator.labels.append(msg) + self.classDescr.labelsToPropagate.append(msg) # Add the POD-related fields on the Flavour Flavour._appy_addPodRelatedFields(self) diff --git a/gen/plone25/mixins/FlavourMixin.py b/gen/plone25/mixins/FlavourMixin.py index 71643d7..1db86ff 100644 --- a/gen/plone25/mixins/FlavourMixin.py +++ b/gen/plone25/mixins/FlavourMixin.py @@ -131,6 +131,7 @@ class FlavourMixin(AbstractMixin): appyType = ploneObj.getAppyType(fieldName) res['title'] = self.translate(appyType['label']) res['context'] = appyType['context'] + res['action'] = appyType['action'] return res def generateDocument(self): @@ -156,10 +157,11 @@ class FlavourMixin(AbstractMixin): format = podTemplate.getPodFormat() template = appyPt.podTemplate.content podTitle = podTemplate.Title() + doAction = False else: fieldName = rq.get('fieldName') + format = rq.get('podFormat') podInfo = self.getPodInfo(obj, fieldName) - format = podInfo['formats'][0] template = podInfo['template'].content podTitle = podInfo['title'] if podInfo['context']: @@ -167,6 +169,7 @@ class FlavourMixin(AbstractMixin): specificPodContext = podInfo['context'](appyObj) else: specificPodContext = podInfo['context'] + doAction = rq.get('askAction') == 'True' # Temporary file where to generate the result tempFileName = '%s/%s_%f.%s' % ( getOsTempFolder(), obj.UID(), time.time(), format) @@ -203,14 +206,16 @@ class FlavourMixin(AbstractMixin): f = file(tempFileName, 'rb') res = f.read() # Identify the filename to return - fileName = u'%s-%s' % (obj.Title().decode('utf-8'), - podTitle.decode('utf-8')) + fileName = u'%s-%s' % (obj.Title().decode('utf-8'), podTitle) fileName = appyTool.normalize(fileName) response = obj.REQUEST.RESPONSE response.setHeader('Content-Type', mimeTypes[format]) response.setHeader('Content-Disposition', 'inline;filename="%s.%s"'\ % (fileName, format)) f.close() + # Execute the related action if relevant + if doAction and podInfo['action']: + podInfo['action'](appyObj, podContext) # Returns the doc and removes the temp file try: os.remove(tempFileName) diff --git a/gen/plone25/skin/macros.pt b/gen/plone25/skin/macros.pt index 2bedcae..689d3dd 100644 --- a/gen/plone25/skin/macros.pt +++ b/gen/plone25/skin/macros.pt @@ -6,7 +6,7 @@ tal:repeat="podTemplate podTemplates"> + tal:attributes="onclick python: 'javascript:generatePodDocument(\'%s\',\'%s\', \'\', \'\')' % (contextObj.UID(), podTemplate.UID())" > @@ -15,7 +15,7 @@ @@ -138,12 +138,19 @@ - + + + + +
@@ -504,9 +517,11 @@
- templateUid is given if class-wide pod, fieldName is given if podField. + templateUid is given if class-wide pod, fieldName and podFormat are given if podField. + +
diff --git a/gen/po.py b/gen/po.py index db740ea..993d09d 100644 --- a/gen/po.py +++ b/gen/po.py @@ -40,6 +40,7 @@ class PoMessage: 'comment every time a transition is triggered' MSG_showAllStatesInPhaseFor = 'Show all states in phase' POD_TEMPLATE = 'POD template' + POD_ASKACTION = 'Trigger related action' DEFAULT_VALID_ERROR = 'Please fill or correct this.' REF_NO = 'No object.' REF_ADD = 'Add a new one'