Improved POD generation.

This commit is contained in:
Gaetan Delannay 2010-02-01 11:09:26 +01:00
parent 2e1c6a6999
commit 36a740ed7e
3 changed files with 38 additions and 11 deletions

View file

@ -1,3 +1,14 @@
import os.path import os.path
def getPath(): return os.path.dirname(__file__) def getPath(): return os.path.dirname(__file__)
def versionIsGreaterThanOrEquals(version):
'''This method returns True if the current Appy version is greater than or
equals p_version. p_version must have a format like "0.5.0".'''
import appy.version
if appy.version.short == 'dev':
# We suppose that a developer knows what he is doing, so we return True.
return True
else:
paramVersion = [int(i) for i in version.split('.')]
currentVersion = (int(i) for i in appy.version.short.split('.'))
return currentVersion >= paramVersion

View file

@ -1,3 +1,6 @@
0.5.0 (2010-01-29)
- Lots of appy.gen improvements due to the development of a big project with the framework.
0.4.1 (2009-11-03) 0.4.1 (2009-11-03)
- Ajax framework within appy.gen - Ajax framework within appy.gen
- More improvements in XHTML->ODT conversion within appy.pod - More improvements in XHTML->ODT conversion within appy.pod

View file

@ -1,5 +1,5 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
import os, os.path, time import os, os.path, time, unicodedata
from appy.shared import mimeTypes from appy.shared import mimeTypes
from appy.gen.plone25.mixins import AbstractMixin from appy.gen.plone25.mixins import AbstractMixin
from StringIO import StringIO from StringIO import StringIO
@ -40,6 +40,23 @@ DELETE_TEMP_DOC_ERROR = 'A temporary document could not be removed. %s.'
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
class PodTemplateMixin(AbstractMixin): class PodTemplateMixin(AbstractMixin):
_appy_meta_type = 'podtemplate' _appy_meta_type = 'podtemplate'
unwantedChars = ('\\', '/', ':', '*', '?', '"', '<', '>', '|', ' ')
def _getFileName(self, obj):
'''Returns a valid, clean fileName for the document generated from
p_self for p_obj.'''
res = u'%s-%s' % (obj.Title().decode('utf-8'),
self.Title().decode('utf-8'))
# Remove accents
res = unicodedata.normalize('NFKD', res).encode("ascii", "ignore")
# Remove unwanted chars (ie, chars that are not valid in file names
# under Windows)
finalRes = ''
for char in res:
if char not in self.unwantedChars:
finalRes += char
return finalRes
def generateDocument(self, obj): def generateDocument(self, obj):
'''Generates a document from this template, for object p_obj.''' '''Generates a document from this template, for object p_obj.'''
appySelf = self._appy_getWrapper(force=True) appySelf = self._appy_getWrapper(force=True)
@ -76,16 +93,12 @@ class PodTemplateMixin(AbstractMixin):
raise PodError(POD_ERROR % str(pe)) raise PodError(POD_ERROR % str(pe))
# Open the temp file on the filesystem # Open the temp file on the filesystem
f = file(tempFileName, 'rb') f = file(tempFileName, 'rb')
forBrowser = True res = f.read()
if forBrowser: fileName = self._getFileName(obj)
# Create a OFS.Image.File object that will manage correclty HTTP response = obj.REQUEST.RESPONSE
# headers, etc. response.setHeader('Content-Type', mimeTypes[self.getPodFormat()])
theFile = self.getProductConfig().File('dummyId', 'dummyTitle', f, response.setHeader('Content-Disposition', 'inline;filename="%s.%s"'\
content_type=mimeTypes[appySelf.podFormat]) % (fileName, self.getPodFormat()))
res = theFile.index_html(self.REQUEST, self.REQUEST.RESPONSE)
else:
# I must return the raw document content.
res = f.read()
f.close() f.close()
# Returns the doc and removes the temp file # Returns the doc and removes the temp file
try: try: