Commit 015af31a authored by Julien Muchembled's avatar Julien Muchembled

MailTemplates: fix newlines in BaseMailTemplate.py (LF, no trailing space)

parent cd4ae3d6
This diff is collapsed.
# Copyright (c) 2005-2006 Simplistix Ltd # Copyright (c) 2005-2006 Simplistix Ltd
# #
# This Software is released under the MIT License: # This Software is released under the MIT License:
# http://www.opensource.org/licenses/mit-license.html # http://www.opensource.org/licenses/mit-license.html
# See license.txt for more details. # See license.txt for more details.
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from AccessControl import getSecurityManager from AccessControl import getSecurityManager
from App.class_init import default__class_init__ as InitializeClass from App.class_init import default__class_init__ as InitializeClass
from Products.CMFCore.FSPageTemplate import FSPageTemplate from Products.CMFCore.FSPageTemplate import FSPageTemplate
from Products.CMFCore.DirectoryView import registerFileExtension from Products.CMFCore.DirectoryView import registerFileExtension
from Products.CMFCore.DirectoryView import registerMetaType from Products.CMFCore.DirectoryView import registerMetaType
from BaseMailTemplate import BaseMailTemplate from BaseMailTemplate import BaseMailTemplate
from MailTemplate import MailTemplate from MailTemplate import MailTemplate
class FSMailTemplate(BaseMailTemplate,FSPageTemplate): class FSMailTemplate(BaseMailTemplate,FSPageTemplate):
"Wrapper for Mail Template" "Wrapper for Mail Template"
security = ClassSecurityInfo() security = ClassSecurityInfo()
meta_type = 'Filesystem Mail Template' meta_type = 'Filesystem Mail Template'
def __init__(self, id, filepath, fullname=None, properties=None): def __init__(self, id, filepath, fullname=None, properties=None):
FSPageTemplate.__init__(self,id,filepath,fullname,properties) FSPageTemplate.__init__(self,id,filepath,fullname,properties)
self._properties = properties self._properties = properties
security.declarePrivate('_createZODBClone') security.declarePrivate('_createZODBClone')
def _createZODBClone(self): def _createZODBClone(self):
"""Create a ZODB (editable) equivalent of this object.""" """Create a ZODB (editable) equivalent of this object."""
obj = MailTemplate(self.getId(), self._text, self.content_type) obj = MailTemplate(self.getId(), self._text, self.content_type)
obj.expand = 0 obj.expand = 0
obj.write(self.read()) obj.write(self.read())
obj._setPropValue('mailhost',self.mailhost) obj._setPropValue('mailhost',self.mailhost)
obj.content_type = self.content_type obj.content_type = self.content_type
if self._properties: if self._properties:
keys = self._properties.keys() keys = self._properties.keys()
keys.sort() keys.sort()
for id in keys: for id in keys:
if id not in ('mailhost','content_type'): if id not in ('mailhost','content_type'):
obj.manage_addProperty(id,self._properties[id],'string') obj.manage_addProperty(id,self._properties[id],'string')
return obj return obj
security.declarePrivate('_readFile') security.declarePrivate('_readFile')
def _readFile(self, reparse): def _readFile(self, reparse):
fp = self._filepath fp = self._filepath
file = open(fp, 'r') # not 'rb', as this is a text file! file = open(fp, 'r') # not 'rb', as this is a text file!
try: try:
data = file.read() data = file.read()
finally: finally:
file.close() file.close()
if reparse: if reparse:
self.write(data) self.write(data)
def _exec(self, bound_names, args, kw): def _exec(self, bound_names, args, kw):
"""Call a FSPageTemplate""" """Call a FSPageTemplate"""
try: try:
response = self.REQUEST.RESPONSE response = self.REQUEST.RESPONSE
except AttributeError: except AttributeError:
response = None response = None
# Read file first to get a correct content_type default value. # Read file first to get a correct content_type default value.
self._updateFromFS() self._updateFromFS()
if not kw.has_key('args'): if not kw.has_key('args'):
kw['args'] = args kw['args'] = args
bound_names['options'] = kw bound_names['options'] = kw
security=getSecurityManager() security=getSecurityManager()
bound_names['user'] = security.getUser().getIdOrUserName() bound_names['user'] = security.getUser().getIdOrUserName()
# Retrieve the value from the cache. # Retrieve the value from the cache.
keyset = None keyset = None
if self.ZCacheable_isCachingEnabled(): if self.ZCacheable_isCachingEnabled():
# Prepare a cache key. # Prepare a cache key.
keyset = { keyset = {
# Why oh why? # Why oh why?
# All this code is cut and paste # All this code is cut and paste
# here to make sure that we # here to make sure that we
# dont call _getContext and hence can't cache # dont call _getContext and hence can't cache
# Annoying huh? # Annoying huh?
'here': self.aq_parent.getPhysicalPath(), 'here': self.aq_parent.getPhysicalPath(),
'bound_names': bound_names} 'bound_names': bound_names}
result = self.ZCacheable_get(keywords=keyset) result = self.ZCacheable_get(keywords=keyset)
if result is not None: if result is not None:
# Got a cached value. # Got a cached value.
return result return result
# Execute the template in a new security context. # Execute the template in a new security context.
security.addContext(self) security.addContext(self)
try: try:
result = self.pt_render(extra_context=bound_names) result = self.pt_render(extra_context=bound_names)
if keyset is not None: if keyset is not None:
# Store the result in the cache. # Store the result in the cache.
self.ZCacheable_set(result, keywords=keyset) self.ZCacheable_set(result, keywords=keyset)
return result return result
finally: finally:
security.removeContext(self) security.removeContext(self)
return result return result
InitializeClass(FSMailTemplate) InitializeClass(FSMailTemplate)
registerFileExtension('mt', FSMailTemplate) registerFileExtension('mt', FSMailTemplate)
registerMetaType('Mail Template', FSMailTemplate) registerMetaType('Mail Template', FSMailTemplate)
# Copyright (c) 2005-2006 Simplistix Ltd # Copyright (c) 2005-2006 Simplistix Ltd
# #
# This Software is released under the MIT License: # This Software is released under the MIT License:
# http://www.opensource.org/licenses/mit-license.html # http://www.opensource.org/licenses/mit-license.html
# See license.txt for more details. # See license.txt for more details.
import os import os
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from AccessControl import getSecurityManager from AccessControl import getSecurityManager
from App.class_init import default__class_init__ as InitializeClass from App.class_init import default__class_init__ as InitializeClass
from App.Common import package_home from App.Common import package_home
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
from Products.PageTemplates.PageTemplate import PageTemplate from Products.PageTemplates.PageTemplate import PageTemplate
from Products.PageTemplates.PageTemplateFile import PageTemplateFile from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from BaseMailTemplate import BaseMailTemplate from BaseMailTemplate import BaseMailTemplate
class MailTemplate(BaseMailTemplate,ZopePageTemplate): class MailTemplate(BaseMailTemplate,ZopePageTemplate):
"A ZPT-like template for sending mails" "A ZPT-like template for sending mails"
security = ClassSecurityInfo() security = ClassSecurityInfo()
meta_type = 'Mail Template' meta_type = 'Mail Template'
_properties = () _properties = ()
manage_options = ZopePageTemplate.manage_options[0:1] + \ manage_options = ZopePageTemplate.manage_options[0:1] + \
ZopePageTemplate.manage_options[2:] ZopePageTemplate.manage_options[2:]
_default_content_fn = os.path.join(package_home(globals()), _default_content_fn = os.path.join(package_home(globals()),
'www', 'default.txt') 'www', 'default.txt')
security.declareProtected('View management screens','pt_editForm') security.declareProtected('View management screens','pt_editForm')
pt_editForm = PageTemplateFile('www/mtEdit', globals(), pt_editForm = PageTemplateFile('www/mtEdit', globals(),
__name__='pt_editForm') __name__='pt_editForm')
manage = manage_main = pt_editForm manage = manage_main = pt_editForm
security.declareProtected('Change Page Templates','pt_editAction') security.declareProtected('Change Page Templates','pt_editAction')
def pt_editAction(self, REQUEST, mailhost, text, content_type, expand): def pt_editAction(self, REQUEST, mailhost, text, content_type, expand):
"""Change the mailhost and document.""" """Change the mailhost and document."""
if self.wl_isLocked(): if self.wl_isLocked():
raise ResourceLockedError, "File is locked via WebDAV" raise ResourceLockedError, "File is locked via WebDAV"
self.expand=expand self.expand=expand
self._setPropValue('mailhost',mailhost) self._setPropValue('mailhost',mailhost)
self.pt_edit(text, content_type) self.pt_edit(text, content_type)
REQUEST.set('text', self.read()) # May not equal 'text'! REQUEST.set('text', self.read()) # May not equal 'text'!
message = "Saved changes." message = "Saved changes."
if getattr(self, '_v_warnings', None): if getattr(self, '_v_warnings', None):
message = ("<strong>Warning:</strong> <i>%s</i>" message = ("<strong>Warning:</strong> <i>%s</i>"
% '<br>'.join(self._v_warnings)) % '<br>'.join(self._v_warnings))
return self.pt_editForm(manage_tabs_message=message) return self.pt_editForm(manage_tabs_message=message)
def om_icons(self): def om_icons(self):
"""Return a list of icon URLs to be displayed by an ObjectManager""" """Return a list of icon URLs to be displayed by an ObjectManager"""
icons = ({'path': 'misc_/MailTemplates/mt.gif', icons = ({'path': 'misc_/MailTemplates/mt.gif',
'alt': self.meta_type, 'title': self.meta_type},) 'alt': self.meta_type, 'title': self.meta_type},)
if not self._v_cooked: if not self._v_cooked:
self._cook() self._cook()
if self._v_errors: if self._v_errors:
icons = icons + ({'path': 'misc_/PageTemplates/exclamation.gif', icons = icons + ({'path': 'misc_/PageTemplates/exclamation.gif',
'alt': 'Error', 'alt': 'Error',
'title': 'This template has an error'},) 'title': 'This template has an error'},)
return icons return icons
def _exec(self, bound_names, args, kw): def _exec(self, bound_names, args, kw):
"""Call a Page Template""" """Call a Page Template"""
if not kw.has_key('args'): if not kw.has_key('args'):
kw['args'] = args kw['args'] = args
bound_names['options'] = kw bound_names['options'] = kw
security=getSecurityManager() security=getSecurityManager()
bound_names['user'] = security.getUser().getIdOrUserName() bound_names['user'] = security.getUser().getIdOrUserName()
# Retrieve the value from the cache. # Retrieve the value from the cache.
keyset = None keyset = None
if self.ZCacheable_isCachingEnabled(): if self.ZCacheable_isCachingEnabled():
# Prepare a cache key. # Prepare a cache key.
keyset = {'here': self._getContext(), keyset = {'here': self._getContext(),
'bound_names': bound_names} 'bound_names': bound_names}
result = self.ZCacheable_get(keywords=keyset) result = self.ZCacheable_get(keywords=keyset)
if result is not None: if result is not None:
# Got a cached value. # Got a cached value.
return result return result
# Execute the template in a new security context. # Execute the template in a new security context.
security.addContext(self) security.addContext(self)
try: try:
result = self.pt_render(extra_context=bound_names) result = self.pt_render(extra_context=bound_names)
if keyset is not None: if keyset is not None:
# Store the result in the cache. # Store the result in the cache.
self.ZCacheable_set(result, keywords=keyset) self.ZCacheable_set(result, keywords=keyset)
return result return result
finally: finally:
security.removeContext(self) security.removeContext(self)
def pt_render(self, source=False, extra_context={}): def pt_render(self, source=False, extra_context={}):
# Override to support empty strings # Override to support empty strings
result = PageTemplate.pt_render(self, source, extra_context) or u'' result = PageTemplate.pt_render(self, source, extra_context) or u''
assert isinstance(result, unicode) assert isinstance(result, unicode)
return result return result
InitializeClass(MailTemplate) InitializeClass(MailTemplate)
# Copyright (c) 2005-2006 Simplistix Ltd # Copyright (c) 2005-2006 Simplistix Ltd
# #
# This Software is released under the MIT License: # This Software is released under the MIT License:
# http://www.opensource.org/licenses/mit-license.html # http://www.opensource.org/licenses/mit-license.html
# See license.txt for more details. # See license.txt for more details.
from AccessControl import allow_module,allow_class from AccessControl import allow_module,allow_class
from Products.PageTemplates.PageTemplateFile import PageTemplateFile from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from MailTemplate import MailTemplate from MailTemplate import MailTemplate
from types import ClassType from types import ClassType
from urllib import quote from urllib import quote
try: try:
import Products.CMFCore import Products.CMFCore
except ImportError: except ImportError:
pass pass
else: else:
import FSMailTemplate import FSMailTemplate
import Products.CMFCore.utils import Products.CMFCore.utils
Products.CMFCore.utils.registerIcon(FSMailTemplate.FSMailTemplate, Products.CMFCore.utils.registerIcon(FSMailTemplate.FSMailTemplate,
'www/fsmt.gif', globals()) 'www/fsmt.gif', globals())
def initialize( context ): def initialize( context ):
context.registerClass( context.registerClass(
MailTemplate, MailTemplate,
# we use the same permission as page templates # we use the same permission as page templates
# in order to keep things simple. # in order to keep things simple.
permission='Add Page Templates', permission='Add Page Templates',
constructors=(addMailTemplateForm, constructors=(addMailTemplateForm,
addMailTemplate), addMailTemplate),
icon='www/mt.gif', icon='www/mt.gif',
) )
addMailTemplateForm = PageTemplateFile( addMailTemplateForm = PageTemplateFile(
'www/mtAdd', 'www/mtAdd',
globals(), globals(),
__name__='addMailTemplateForm' __name__='addMailTemplateForm'
) )
def addMailTemplate(self, id, mailhost=None, text=None, def addMailTemplate(self, id, mailhost=None, text=None,
REQUEST=None, submit=None): REQUEST=None, submit=None):
"Add a Mail Template with optional file content." "Add a Mail Template with optional file content."
id = str(id) id = str(id)
if REQUEST is None: if REQUEST is None:
self._setObject(id, MailTemplate(id, text)) self._setObject(id, MailTemplate(id, text))
ob = getattr(self, id) ob = getattr(self, id)
if mailhost: if mailhost:
ob._setPropValue('mailhost',mailhost) ob._setPropValue('mailhost',mailhost)
return ob return ob
else: else:
file = REQUEST.form.get('file') file = REQUEST.form.get('file')
headers = getattr(file, 'headers', None) headers = getattr(file, 'headers', None)
if headers is None or not file.filename: if headers is None or not file.filename:
mt = MailTemplate(id, text) mt = MailTemplate(id, text)
else: else:
mt = MailTemplate(id, file, headers.get('content_type')) mt = MailTemplate(id, file, headers.get('content_type'))
self._setObject(id, mt) self._setObject(id, mt)
ob = getattr(self, id) ob = getattr(self, id)
if mailhost: if mailhost:
ob._setPropValue('mailhost',mailhost) ob._setPropValue('mailhost',mailhost)
if submit == " Add and Edit ": if submit == " Add and Edit ":
u = ob.absolute_url() u = ob.absolute_url()
else: else:
u = ob.aq_parent.absolute_url() u = ob.aq_parent.absolute_url()
REQUEST.RESPONSE.redirect(u+'/manage_main') REQUEST.RESPONSE.redirect(u+'/manage_main')
# allow all the email module's public bits # allow all the email module's public bits
import email import email
for name in email.__all__: for name in email.__all__:
path = 'email.'+name path = 'email.'+name
allow_module(path) allow_module(path)
try: try:
mod = __import__(path) mod = __import__(path)
except ImportError: except ImportError:
pass pass
else: else:
mod = getattr(mod,name) mod = getattr(mod,name)
for mod_name in dir(mod): for mod_name in dir(mod):
obj = getattr(mod,mod_name) obj = getattr(mod,mod_name)
if isinstance(obj,ClassType): if isinstance(obj,ClassType):
allow_class(obj) allow_class(obj)
# Copyright (c) 2005-2006 Simplistix Ltd # Copyright (c) 2005-2006 Simplistix Ltd
# #
# This Software is released under the MIT License: # This Software is released under the MIT License:
# http://www.opensource.org/licenses/mit-license.html # http://www.opensource.org/licenses/mit-license.html
# See license.txt for more details. # See license.txt for more details.
<tal:body xmlns:tal="http://xml.zope.org/namespaces/tal" <tal:body xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal" xmlns:metal="http://xml.zope.org/namespaces/metal"
>Dear <tal:x replace="options/mto"/>, >Dear <tal:x replace="options/mto"/>,
<tal:x replace="user/getId"/> would like to thank you for <tal:x replace="user/getId"/> would like to thank you for
your interest in: your interest in:
<tal:x replace="root/absolute_url"/> <tal:x replace="root/absolute_url"/>
<tal:x replace="options/message"/> <tal:x replace="options/message"/>
cheers, cheers,
The Web Team The Web Team
</tal:body> </tal:body>
<tal:body xmlns:tal="http://xml.zope.org/namespaces/tal" <tal:body xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal" xmlns:metal="http://xml.zope.org/namespaces/metal"
>Dear <tal:x replace="options/mto"/>, >Dear <tal:x replace="options/mto"/>,
Please find attached the file you requested. Please find attached the file you requested.
cheers, cheers,
The Web Team The Web Team
</tal:body> </tal:body>
<tal:body xmlns:tal="http://xml.zope.org/namespaces/tal" <tal:body xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal" xmlns:metal="http://xml.zope.org/namespaces/metal"
>Dear <tal:x replace="options/mto"/>, >Dear <tal:x replace="options/mto"/>,
Welcome to our site! Welcome to our site!
cheers, cheers,
The Web Team The Web Team
</tal:body> </tal:body>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment