[Checkins] SVN: Products.CMFDefault/trunk/Products/CMFDefault/ - added 'registered_email' and 'password_email' views

Yvo Schubbe cvs-admin at zope.org
Mon Sep 3 10:48:23 UTC 2012


Log message for revision 127677:
  - added 'registered_email' and 'password_email' views

Changed:
  U   Products.CMFDefault/trunk/Products/CMFDefault/CHANGES.txt
  U   Products.CMFDefault/trunk/Products/CMFDefault/browser/membership/configure.zcml
  A   Products.CMFDefault/trunk/Products/CMFDefault/browser/membership/notify.py
  A   Products.CMFDefault/trunk/Products/CMFDefault/browser/membership/notify_password.pt
  A   Products.CMFDefault/trunk/Products/CMFDefault/browser/membership/notify_registered.pt
  A   Products.CMFDefault/trunk/Products/CMFDefault/browser/membership/tests/notify.txt
  A   Products.CMFDefault/trunk/Products/CMFDefault/browser/membership/tests/test_notify.py

-=-
Modified: Products.CMFDefault/trunk/Products/CMFDefault/CHANGES.txt
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/CHANGES.txt	2012-09-03 10:10:46 UTC (rev 127676)
+++ Products.CMFDefault/trunk/Products/CMFDefault/CHANGES.txt	2012-09-03 10:48:20 UTC (rev 127677)
@@ -4,6 +4,12 @@
 2.3.0 (unreleased)
 ------------------
 
+- browser views: Added 'registered_email' and 'password_email' views.
+  Please note that these views override the corresponding skin methods. If you
+  want to use customized versions from the skins tool you have to make sure
+  these views are not registered. It is recommended to customize the browser
+  views instead.
+
 - RegistrationTool: Improved 'mailPassword' and 'registeredNotify' methods.
   Mail templates can now be views. 'mail_password_response' is no longer
   required, using the return value of 'mailPassword' is deprecated.

Modified: Products.CMFDefault/trunk/Products/CMFDefault/browser/membership/configure.zcml
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/browser/membership/configure.zcml	2012-09-03 10:10:46 UTC (rev 127676)
+++ Products.CMFDefault/trunk/Products/CMFDefault/browser/membership/configure.zcml	2012-09-03 10:48:20 UTC (rev 127677)
@@ -91,4 +91,22 @@
       permission="cmf.ListPortalMembers"
       />
 
+  <browser:page
+      for="Products.CMFCore.interfaces.IRegistrationTool"
+      layer="Products.CMFDefault.interfaces.ICMFDefaultSkin"
+      name="registered_email"
+      class=".notify.RegisteredEmail"
+      template="notify_registered.pt"
+      permission="zope2.Private"
+      />
+
+  <browser:page
+      for="Products.CMFCore.interfaces.IRegistrationTool"
+      layer="Products.CMFDefault.interfaces.ICMFDefaultSkin"
+      name="password_email"
+      class=".notify.PasswordEmail"
+      template="notify_password.pt"
+      permission="zope2.Private"
+      />
+
 </configure>

Added: Products.CMFDefault/trunk/Products/CMFDefault/browser/membership/notify.py
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/browser/membership/notify.py	                        (rev 0)
+++ Products.CMFDefault/trunk/Products/CMFDefault/browser/membership/notify.py	2012-09-03 10:48:20 UTC (rev 127677)
@@ -0,0 +1,110 @@
+##############################################################################
+#
+# Copyright (c) 2012 Zope Foundation and Contributors.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Notification emails.
+"""
+
+from zope.component import getUtility
+
+from Products.CMFCore.interfaces import IActionsTool
+from Products.CMFCore.interfaces import IPropertiesTool
+from Products.CMFDefault.browser.utils import decode
+from Products.CMFDefault.browser.utils import memoize
+from Products.CMFDefault.browser.utils import ViewBase
+from Products.CMFDefault.utils import makeEmail
+from Products.CMFDefault.utils import Message as _
+
+
+class _EmailBase(ViewBase):
+
+    def _makeEmail(self):
+        mtext = self.index()
+        headers = {'Subject': self._subject,
+                   'From': self._from,
+                   'To': u'<{0}>'.format(self.email)}
+        return makeEmail(mtext, self.context, headers)
+
+    @property
+    @decode
+    def _from(self):
+        return '{0} <{1}>'.format(
+            self.ptool.getProperty('email_from_name'),
+            self.ptool.getProperty('email_from_address'))
+
+    @property
+    @memoize
+    def ptool(self):
+        return getUtility(IPropertiesTool)
+
+    @property
+    @memoize
+    @decode
+    def portal_title(self):
+        return self.ptool.title()
+
+    @property
+    @memoize
+    @decode
+    def portal_description(self):
+        return self.ptool.getProperty('description')
+
+    @property
+    @memoize
+    def portal_url(self):
+        return self._getPortalURL()
+
+
+class RegisteredEmail(_EmailBase):
+
+    """Email for registration notification.
+    """
+
+    def __call__(self, member=None, password='secret',
+                 email='foo at example.org'):
+        self.member_id = member and member.getId() or 'foo'
+        self.password = password
+        self.email = email
+        return self._makeEmail()
+
+    @property
+    def _subject(self):
+        return _(u'${portal_title}: Your Membership Information',
+                 mapping={'portal_title': self.portal_title})
+
+    @property
+    @memoize
+    def login_url(self):
+        atool = getUtility(IActionsTool)
+        return atool.getActionInfo('user/login')['url']
+
+    @property
+    @memoize
+    @decode
+    def signature(self):
+        return self.ptool.getProperty('email_from_name')
+
+
+class PasswordEmail(_EmailBase):
+
+    """Email for password notification.
+    """
+
+    def __call__(self, member=None, password='secret'):
+        self.password = password
+        self.email = member and member.getProperty('email') \
+                     or 'foo at example.org'
+        return self._makeEmail()
+
+    @property
+    def _subject(self):
+        return _(u'${portal_title}: Membership reminder',
+                 mapping={'portal_title': self.portal_title})


Property changes on: Products.CMFDefault/trunk/Products/CMFDefault/browser/membership/notify.py
___________________________________________________________________
Added: svn:eol-style
   + native

Copied: Products.CMFDefault/trunk/Products/CMFDefault/browser/membership/notify_password.pt (from rev 127674, Products.CMFDefault/trunk/Products/CMFDefault/skins/zpt_generic/password_email_template.pt)
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/browser/membership/notify_password.pt	                        (rev 0)
+++ Products.CMFDefault/trunk/Products/CMFDefault/browser/membership/notify_password.pt	2012-09-03 10:48:20 UTC (rev 127677)
@@ -0,0 +1,9 @@
+<tal:page i18n:domain="cmf_default"
+><tal:span i18n:translate="">Your password: <tal:span i18n:name="password"
+    tal:content="view/password | default">baz</tal:span></tal:span>
+
+<tal:span i18n:translate="">Request made by IP <tal:span i18n:name="ip"
+    tal:define="ip python:request.HTTP_X_FORWARDED_FOR or request.REMOTE_ADDR"
+    tal:content="ip" /> at <tal:span i18n:name="time"
+    tal:content="context/ZopeTime" /></tal:span>
+</tal:page>

Copied: Products.CMFDefault/trunk/Products/CMFDefault/browser/membership/notify_registered.pt (from rev 127674, Products.CMFDefault/trunk/Products/CMFDefault/skins/zpt_generic/registered_email_template.pt)
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/browser/membership/notify_registered.pt	                        (rev 0)
+++ Products.CMFDefault/trunk/Products/CMFDefault/browser/membership/notify_registered.pt	2012-09-03 10:48:20 UTC (rev 127677)
@@ -0,0 +1,37 @@
+<tal:page i18n:domain="cmf_default"
+><tal:span i18n:translate=""
+>You have been registered as a member of "<tal:span i18n:name="portal_title"
+   tal:content="view/portal_title" />", which
+allows you to personalize your view of the website and participate in the
+community.</tal:span>
+<tal:case tal:condition="view/portal_description">
+<tal:span i18n:translate=""
+>This describes the purpose of the website:</tal:span>
+
+<tal:span tal:content="view/portal_description" />
+</tal:case>
+<tal:span i18n:translate=""
+>Visit us at <tal:span i18n:name="portal_url"
+   tal:content="view/portal_url" /></tal:span>
+
+<tal:span i18n:translate=""
+>Here is your login data (mind upper and lower case):</tal:span>
+
+<tal:span i18n:translate=""
+>Member ID</tal:span>: <tal:span tal:content="view/member_id" />
+<tal:span i18n:translate=""
+>Password</tal:span>: <tal:span tal:content="view/password" />
+
+<tal:span i18n:translate=""
+>You can use this URL to log in:</tal:span>
+
+<tal:span tal:content="view/login_url" />
+<tal:case tal:condition="python:len(view.login_url)>70">
+<tal:span i18n:translate=""
+>Be aware that this URL might wrap over two lines. If your browser shows an
+error message when you try to access the URL please make sure that you put
+in the complete string.</tal:span>
+</tal:case>
+
+<tal:span tal:content="view/signature" />
+</tal:page>

Copied: Products.CMFDefault/trunk/Products/CMFDefault/browser/membership/tests/notify.txt (from rev 127674, Products.CMFDefault/trunk/Products/CMFDefault/tests/RegistrationTool.txt)
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/browser/membership/tests/notify.txt	                        (rev 0)
+++ Products.CMFDefault/trunk/Products/CMFDefault/browser/membership/tests/notify.txt	2012-09-03 10:48:20 UTC (rev 127677)
@@ -0,0 +1,106 @@
+password_email and registered_email
+-----------------------------------
+
+  First we have to set up some site properties::
+
+    >>> from zope.component import getSiteManager
+    >>> from zope.component import getUtility
+    >>> from zope.component.hooks import setSite
+    >>> from zope.globalrequest import setRequest
+    >>> from Products.CMFCore.interfaces import IRegistrationTool
+    >>> setSite(app.site)
+    >>> setRequest(app.REQUEST)
+    >>> sm = getSiteManager()
+    >>> rtool = sm.getUtility(IRegistrationTool)
+
+    >>> s = app.site
+    >>> s.REQUEST.environ['HTTP_X_FORWARDED_FOR'] = 'NNN.NNN.NNN.NNN'
+    >>> s.ZopeTime = 'NNNN/NN/NN'
+    >>> s.description = 'THE SITE DESCRIPTION.'
+    >>> s.default_charset = 'utf-8'
+    >>> s.email_from_name = u'WEBMASTER \xc4\xd6\xdc'.encode('utf-8')
+    >>> s.email_from_address = 'WEBMASTER at EXAMPLE.ORG'
+    >>> s.title = 'WWW.EXAMPLE.ORG'
+
+  password_email creates a complete reminder email::
+
+    >>> s.email_charset = 'iso-8859-1'
+    >>> print rtool.__of__(s).unrestrictedTraverse('password_email')()
+    Content-Type: text/plain; charset="us-ascii"
+    MIME-Version: 1.0
+    Content-Transfer-Encoding: 7bit
+    To: <foo at example.org>
+    From: WEBMASTER =?iso-8859-1?q?=C4=D6=DC?= <WEBMASTER at EXAMPLE.ORG>
+    Subject: [[cmf_default][WWW.EXAMPLE.ORG: Membership reminder]]
+    <BLANKLINE>
+    [[cmf_default][Your password: secret]]
+    <BLANKLINE>
+    [[cmf_default][Request made by IP NNN.NNN.NNN.NNN at NNNN/NN/NN]]
+    <BLANKLINE>
+    <BLANKLINE>
+
+    >>> s.email_charset = ''
+    >>> print rtool.__of__(s).unrestrictedTraverse('password_email')()
+    Content-Type: text/plain; charset="us-ascii"
+    MIME-Version: 1.0
+    Content-Transfer-Encoding: 7bit
+    To: <foo at example.org>
+    From: WEBMASTER =?utf-8?...?= <WEBMASTER at EXAMPLE.ORG>
+    Subject: [[cmf_default][WWW.EXAMPLE.ORG: Membership reminder]]
+    <BLANKLINE>
+    [[cmf_default][Your password: secret]]
+    <BLANKLINE>
+    [[cmf_default][Request made by IP NNN.NNN.NNN.NNN at NNNN/NN/NN]]
+    <BLANKLINE>
+    <BLANKLINE>
+
+  registered_email creates a complete welcome email::
+
+    >>> s.email_charset = 'iso-8859-1'
+    >>> print rtool.__of__(s).unrestrictedTraverse('registered_email')()
+    Content-Type: text/plain; charset="iso-8859-1"
+    MIME-Version: 1.0
+    Content-Transfer-Encoding: quoted-printable
+    To: <foo at example.org>
+    From: WEBMASTER =?iso-8859-1?q?=C4=D6=DC?= <WEBMASTER at EXAMPLE.ORG>
+    Subject: [[cmf_default][WWW.EXAMPLE.ORG: Your Membership Information]]
+    <BLANKLINE>
+    [[cmf_default][You have been ... (You have been ...)]]
+    <BLANKLINE>
+    [[cmf_default][This describes the purpose of the website:]]
+    <BLANKLINE>
+    THE SITE DESCRIPTION.
+    <BLANKLINE>
+    [[cmf_default][Visit us at http://nohost/site]]
+    <BLANKLINE>
+    [[cmf_default][Here is your login data (mind upper and lower case):]]
+    <BLANKLINE>
+    [[cmf_default][Member ID]]: foo
+    [[cmf_default][Password]]: secret
+    <BLANKLINE>
+    [[cmf_default][You can use this URL to log in:]]
+    <BLANKLINE>
+    http://nohost/site/login_form
+    <BLANKLINE>
+    <BLANKLINE>
+    WEBMASTER =C4=D6=DC
+    <BLANKLINE>
+    <BLANKLINE>
+
+    >>> s.email_charset = ''
+    >>> print rtool.__of__(s).unrestrictedTraverse('registered_email')()
+    Content-Type: text/plain; charset="utf-8"
+    MIME-Version: 1.0
+    Content-Transfer-Encoding: ...
+    To: <foo at example.org>
+    From: WEBMASTER =?utf-8?...?= <WEBMASTER at EXAMPLE.ORG>
+    Subject: [[cmf_default][WWW.EXAMPLE.ORG: Your Membership Information]]
+    <BLANKLINE>
+    ...
+    <BLANKLINE>
+
+Clean up
+--------
+
+    >>> from zope.globalrequest import clearRequest
+    >>> clearRequest()

Added: Products.CMFDefault/trunk/Products/CMFDefault/browser/membership/tests/test_notify.py
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/browser/membership/tests/test_notify.py	                        (rev 0)
+++ Products.CMFDefault/trunk/Products/CMFDefault/browser/membership/tests/test_notify.py	2012-09-03 10:48:20 UTC (rev 127677)
@@ -0,0 +1,27 @@
+##############################################################################
+#
+# Copyright (c) 2012 Zope Foundation and Contributors.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Notification email tests.
+"""
+
+import unittest
+from Testing import ZopeTestCase
+
+from Products.CMFDefault.testing import FunctionalLayer
+
+
+def test_suite():
+    suite = unittest.TestSuite()
+    s = ZopeTestCase.FunctionalDocFileSuite('notify.txt')
+    s.layer = FunctionalLayer
+    suite.addTest(s)
+    return suite


Property changes on: Products.CMFDefault/trunk/Products/CMFDefault/browser/membership/tests/test_notify.py
___________________________________________________________________
Added: svn:eol-style
   + native



More information about the checkins mailing list