[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:
parent
1c3555fd28
commit
a94d400d03
|
@ -3013,4 +3013,6 @@ class Config:
|
|||
# When using Ogone, place an instance of appy.gen.ogone.OgoneConfig in
|
||||
# the field below.
|
||||
self.ogone = None
|
||||
# When using Google analytics, specify here the Analytics ID
|
||||
self.googleAnalyticsId = None
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
|
@ -605,6 +605,7 @@ class ZopeGenerator(Generator):
|
|||
repls['sourceLanguage'] = self.config.sourceLanguage
|
||||
repls['enableSessionTimeout'] = self.config.enableSessionTimeout
|
||||
repls['ogone'] = repr(self.config.ogone)
|
||||
repls['googleAnalyticsId'] = repr(self.config.googleAnalyticsId)
|
||||
repls['activateForgotPassword'] = self.config.activateForgotPassword
|
||||
self.copyFile('config.pyt', repls, destName='config.py')
|
||||
|
||||
|
|
|
@ -1222,4 +1222,29 @@ class ToolMixin(BaseMixin):
|
|||
else:
|
||||
objects = method.__get__(tool)(tool)
|
||||
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
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
|
@ -50,6 +50,7 @@ sourceLanguage = '<!sourceLanguage!>'
|
|||
activateForgotPassword = <!activateForgotPassword!>
|
||||
enableSessionTimeout = <!enableSessionTimeout!>
|
||||
ogone = <!ogone!>
|
||||
googleAnalyticsId = <!googleAnalyticsId!>
|
||||
|
||||
# When Zope is starting or runs in test mode, there is no request object. We
|
||||
# create here a fake one for storing Appy wrappers.
|
||||
|
|
|
@ -34,6 +34,9 @@
|
|||
</head>
|
||||
|
||||
<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>
|
||||
<div id="grey" class="grey"></div>
|
||||
|
||||
|
|
|
@ -248,6 +248,7 @@ class PodParser(OdfParser):
|
|||
e.exprHasStyle = False
|
||||
elif (elem == e.tags['table-cell']) 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['formula']].startswith('of:="'):
|
||||
# In an ODS template, any cell containing a formula of type "string"
|
||||
|
|
|
@ -540,8 +540,13 @@ class Renderer:
|
|||
# Linux/Unix, are unable to detect the correct mimetype for a pod result
|
||||
# (it simply recognizes it as a "application/zip" and not a
|
||||
# "application/vnd.oasis.opendocument.text)".
|
||||
resultZip.write(os.path.join(self.unzipFolder, 'mimetype'),
|
||||
'mimetype', zipfile.ZIP_STORED)
|
||||
mimetypeFile = os.path.join(self.unzipFolder, 'mimetype')
|
||||
# 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 f in filenames:
|
||||
folderName = dir[len(self.unzipFolder)+1:]
|
||||
|
|
Loading…
Reference in a new issue