make message data provider configurable by subclassing MessageInstance
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@3145 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
1d4363f23c
commit
470bb050fa
2 changed files with 44 additions and 40 deletions
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# Copyright (c) 2007 Helmut Merz helmutm@cy55.de
|
# Copyright (c) 2009 Helmut Merz helmutm@cy55.de
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -39,43 +39,6 @@ from cybertools.composer.interfaces import IInstance
|
||||||
from cybertools.util.jeep import Jeep
|
from cybertools.util.jeep import Jeep
|
||||||
|
|
||||||
|
|
||||||
class MessageInstance(Instance):
|
|
||||||
|
|
||||||
template = client = None
|
|
||||||
|
|
||||||
def __init__(self, client, template, manager):
|
|
||||||
self.client = client
|
|
||||||
self.template = template
|
|
||||||
self.manager = manager
|
|
||||||
|
|
||||||
def applyTemplate(self, data=None, **kw):
|
|
||||||
if data is None:
|
|
||||||
data = {}
|
|
||||||
request = data.get('request') or TestRequest()
|
|
||||||
if 'url' not in data:
|
|
||||||
data['url'] = self.getClientUrl(request)
|
|
||||||
dp = DataProvider(self, data)
|
|
||||||
text = MessageTemplate(self.template.text).safe_substitute(dp)
|
|
||||||
subject = self.template.subjectLine
|
|
||||||
data.update(dict(subjectLine=subject, text=text))
|
|
||||||
return data
|
|
||||||
|
|
||||||
def getClientUrl(self, request):
|
|
||||||
if self.client is None:
|
|
||||||
return ''
|
|
||||||
if zope29:
|
|
||||||
#path = aq_inner(self.client.manager).getPhysicalPath()
|
|
||||||
path = self.client.manager.getPhysicalPath()
|
|
||||||
if len(path) >= 3 and path[-3] == 'sm_clients':
|
|
||||||
print '*** path correction:', path
|
|
||||||
# evil hack for aqcuisition-wrapped manager object
|
|
||||||
path = path[:-3]
|
|
||||||
url = request.physicalPathToURL(path)
|
|
||||||
else:
|
|
||||||
url = absoluteURL(self.client.manager, request)
|
|
||||||
return '%s?id=%s' % (url, self.client.__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class DataProvider(object):
|
class DataProvider(object):
|
||||||
|
|
||||||
def __init__(self, context, data):
|
def __init__(self, context, data):
|
||||||
|
@ -123,8 +86,48 @@ class DataProvider(object):
|
||||||
|
|
||||||
def getView(self, name):
|
def getView(self, name):
|
||||||
request = self.data.get('request') or TestRequest()
|
request = self.data.get('request') or TestRequest()
|
||||||
return component.queryMultiAdapter(
|
view = component.queryMultiAdapter(
|
||||||
(self.context.client.manager, request), name=name)
|
(self.context.client.manager, request), name=name)
|
||||||
|
return view
|
||||||
|
|
||||||
|
|
||||||
|
class MessageInstance(Instance):
|
||||||
|
|
||||||
|
template = client = None
|
||||||
|
|
||||||
|
dataProvider = DataProvider
|
||||||
|
|
||||||
|
def __init__(self, client, template, manager):
|
||||||
|
self.client = client
|
||||||
|
self.template = template
|
||||||
|
self.manager = manager
|
||||||
|
|
||||||
|
def applyTemplate(self, data=None, **kw):
|
||||||
|
if data is None:
|
||||||
|
data = {}
|
||||||
|
request = data.get('request') or TestRequest()
|
||||||
|
if 'url' not in data:
|
||||||
|
data['url'] = self.getClientUrl(request)
|
||||||
|
dp = self.dataProvider(self, data)
|
||||||
|
text = MessageTemplate(self.template.text).safe_substitute(dp)
|
||||||
|
subject = self.template.subjectLine
|
||||||
|
data.update(dict(subjectLine=subject, text=text))
|
||||||
|
return data
|
||||||
|
|
||||||
|
def getClientUrl(self, request):
|
||||||
|
if self.client is None:
|
||||||
|
return ''
|
||||||
|
if zope29:
|
||||||
|
#path = aq_inner(self.client.manager).getPhysicalPath()
|
||||||
|
path = self.client.manager.getPhysicalPath()
|
||||||
|
if len(path) >= 3 and path[-3] == 'sm_clients':
|
||||||
|
print '*** path correction:', path
|
||||||
|
# evil hack for aqcuisition-wrapped manager object
|
||||||
|
path = path[:-3]
|
||||||
|
url = request.physicalPathToURL(path)
|
||||||
|
else:
|
||||||
|
url = absoluteURL(self.client.manager, request)
|
||||||
|
return '%s?id=%s' % (url, self.client.__name__)
|
||||||
|
|
||||||
|
|
||||||
class MessageTemplate(Template):
|
class MessageTemplate(Template):
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# Copyright (c) 2007 Helmut Merz helmutm@cy55.de
|
# Copyright (c) 2009 Helmut Merz helmutm@cy55.de
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -27,6 +27,7 @@ from zope.i18nmessageid import MessageFactory
|
||||||
from zope import schema
|
from zope import schema
|
||||||
|
|
||||||
from cybertools.composer.interfaces import ITemplate, IComponent
|
from cybertools.composer.interfaces import ITemplate, IComponent
|
||||||
|
from cybertools.composer.interfaces import IInstance
|
||||||
|
|
||||||
_ = MessageFactory('zope')
|
_ = MessageFactory('zope')
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue