[pod] Bugfix: error when a pod template does not have a 'mimetype' file inside (https://bugs.launchpad.net/bugs/1173009); bugfix: error when parsing some ods pod templates: some cells do not have attribute 'office:value-type' (see bug https://bugs.launchpad.net/bugs/1173301). [gen] Added a basic integration of gen applications with Google Analytics.

This commit is contained in:
Gaetan Delannay 2013-04-29 21:32:05 +02:00
parent 1c3555fd28
commit a94d400d03
7 changed files with 40 additions and 2 deletions

View file

@ -3013,4 +3013,6 @@ class Config:
# When using Ogone, place an instance of appy.gen.ogone.OgoneConfig in # When using Ogone, place an instance of appy.gen.ogone.OgoneConfig in
# the field below. # the field below.
self.ogone = None self.ogone = None
# When using Google analytics, specify here the Analytics ID
self.googleAnalyticsId = None
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------

View file

@ -605,6 +605,7 @@ class ZopeGenerator(Generator):
repls['sourceLanguage'] = self.config.sourceLanguage repls['sourceLanguage'] = self.config.sourceLanguage
repls['enableSessionTimeout'] = self.config.enableSessionTimeout repls['enableSessionTimeout'] = self.config.enableSessionTimeout
repls['ogone'] = repr(self.config.ogone) repls['ogone'] = repr(self.config.ogone)
repls['googleAnalyticsId'] = repr(self.config.googleAnalyticsId)
repls['activateForgotPassword'] = self.config.activateForgotPassword repls['activateForgotPassword'] = self.config.activateForgotPassword
self.copyFile('config.pyt', repls, destName='config.py') self.copyFile('config.pyt', repls, destName='config.py')

View file

@ -1222,4 +1222,29 @@ class ToolMixin(BaseMixin):
else: else:
objects = method.__get__(tool)(tool) objects = method.__get__(tool)(tool)
return [(o.uid, o) for o in objects] return [(o.uid, o) for o in objects]
def getGoogleAnalyticsCode(self):
'''If the config defined a Google Analytics ID, this method returns the
Javascript code to be included in every page, allowing Google
Analytics to work.'''
# Disable Google Analytics when we are in debug mode.
if self.isDebug(): return
# Disable Google Analytics if no ID is found in the config.
gaId = self.getProductConfig().googleAnalyticsId
if not gaid: return
# Google Analytics must be enabled: return the chunk of Javascript
# code specified by Google.
code = "var _gaq = _gaq || [];\n" \
"_gaq.push(['_setAccount', '%s']);\n" \
"_gaq.push(['_trackPageview']);\n" \
"(function() {\n" \
" var ga = document.createElement('script'); " \
"ga.type = 'text/javascript'; ga.async = true;\n" \
" ga.src = ('https:' == document.location.protocol ? " \
"'https://ssl' : 'http://www') + " \
"'.google-analytics.com/ga.js';\n" \
" var s = document.getElementsByTagName('script')[0]; " \
"s.parentNode.insertBefore(ga, s);\n" \
"})();\n" % gaId
return code
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------

View file

@ -50,6 +50,7 @@ sourceLanguage = '<!sourceLanguage!>'
activateForgotPassword = <!activateForgotPassword!> activateForgotPassword = <!activateForgotPassword!>
enableSessionTimeout = <!enableSessionTimeout!> enableSessionTimeout = <!enableSessionTimeout!>
ogone = <!ogone!> ogone = <!ogone!>
googleAnalyticsId = <!googleAnalyticsId!>
# When Zope is starting or runs in test mode, there is no request object. We # When Zope is starting or runs in test mode, there is no request object. We
# create here a fake one for storing Appy wrappers. # create here a fake one for storing Appy wrappers.

View file

@ -34,6 +34,9 @@
</head> </head>
<body tal:on-error="structure python: tool.manageError(error)"> <body tal:on-error="structure python: tool.manageError(error)">
<tal:comment replace="nothing">Google Analytics stuff, if enabled</tal:comment>
<script tal:define="gaCode tool/getGoogleAnalyticsCode" tal:condition="gaCode"
type="text/javascript" tal:content="gaCode"></script>
<tal:comment replace="nothing">Grey background shown when popups are shown</tal:comment> <tal:comment replace="nothing">Grey background shown when popups are shown</tal:comment>
<div id="grey" class="grey"></div> <div id="grey" class="grey"></div>

View file

@ -248,6 +248,7 @@ class PodParser(OdfParser):
e.exprHasStyle = False e.exprHasStyle = False
elif (elem == e.tags['table-cell']) and \ elif (elem == e.tags['table-cell']) and \
attrs.has_key(e.tags['formula']) and \ attrs.has_key(e.tags['formula']) and \
attrs.has_key(e.tags['value-type']) and \
(attrs[e.tags['value-type']] == 'string') and \ (attrs[e.tags['value-type']] == 'string') and \
attrs[e.tags['formula']].startswith('of:="'): attrs[e.tags['formula']].startswith('of:="'):
# In an ODS template, any cell containing a formula of type "string" # In an ODS template, any cell containing a formula of type "string"

View file

@ -540,8 +540,13 @@ class Renderer:
# Linux/Unix, are unable to detect the correct mimetype for a pod result # Linux/Unix, are unable to detect the correct mimetype for a pod result
# (it simply recognizes it as a "application/zip" and not a # (it simply recognizes it as a "application/zip" and not a
# "application/vnd.oasis.opendocument.text)". # "application/vnd.oasis.opendocument.text)".
resultZip.write(os.path.join(self.unzipFolder, 'mimetype'), mimetypeFile = os.path.join(self.unzipFolder, 'mimetype')
'mimetype', zipfile.ZIP_STORED) # This file may not exist (presumably, ods files from Google Drive)
if not os.path.exists(mimetypeFile):
f = open(mimetypeFile, 'w')
f.write(mimeTypes[resultExt])
f.close()
resultZip.write(mimetypeFile, 'mimetype', zipfile.ZIP_STORED)
for dir, dirnames, filenames in os.walk(self.unzipFolder): for dir, dirnames, filenames in os.walk(self.unzipFolder):
for f in filenames: for f in filenames:
folderName = dir[len(self.unzipFolder)+1:] folderName = dir[len(self.unzipFolder)+1:]