diff --git a/__init__.py b/__init__.py index a0d691a..b8dade4 100755 --- a/__init__.py +++ b/__init__.py @@ -1,3 +1,14 @@ import os.path 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 diff --git a/doc/version.txt b/doc/version.txt index bb3d09d..d74b4d6 100755 --- a/doc/version.txt +++ b/doc/version.txt @@ -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) - Ajax framework within appy.gen - More improvements in XHTML->ODT conversion within appy.pod diff --git a/gen/plone25/mixins/PodTemplateMixin.py b/gen/plone25/mixins/PodTemplateMixin.py index 4aa1634..2a13ab3 100644 --- a/gen/plone25/mixins/PodTemplateMixin.py +++ b/gen/plone25/mixins/PodTemplateMixin.py @@ -1,5 +1,5 @@ # ------------------------------------------------------------------------------ -import os, os.path, time +import os, os.path, time, unicodedata from appy.shared import mimeTypes from appy.gen.plone25.mixins import AbstractMixin from StringIO import StringIO @@ -40,6 +40,23 @@ DELETE_TEMP_DOC_ERROR = 'A temporary document could not be removed. %s.' # ------------------------------------------------------------------------------ class PodTemplateMixin(AbstractMixin): _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): '''Generates a document from this template, for object p_obj.''' appySelf = self._appy_getWrapper(force=True) @@ -76,16 +93,12 @@ class PodTemplateMixin(AbstractMixin): raise PodError(POD_ERROR % str(pe)) # Open the temp file on the filesystem f = file(tempFileName, 'rb') - forBrowser = True - if forBrowser: - # Create a OFS.Image.File object that will manage correclty HTTP - # headers, etc. - theFile = self.getProductConfig().File('dummyId', 'dummyTitle', f, - content_type=mimeTypes[appySelf.podFormat]) - res = theFile.index_html(self.REQUEST, self.REQUEST.RESPONSE) - else: - # I must return the raw document content. - res = f.read() + res = f.read() + fileName = self._getFileName(obj) + response = obj.REQUEST.RESPONSE + response.setHeader('Content-Type', mimeTypes[self.getPodFormat()]) + response.setHeader('Content-Disposition', 'inline;filename="%s.%s"'\ + % (fileName, self.getPodFormat())) f.close() # Returns the doc and removes the temp file try: