From: Daniel N. <svn...@pl...> - 2008-11-13 22:04:14
|
Author: nouri Date: Thu Nov 13 22:04:10 2008 New Revision: 75794 Modified: collective.singing/trunk/collective/singing/browser/subscribe.py collective.singing/trunk/collective/singing/browser/subscribe.txt collective.singing/trunk/docs/HISTORY.txt Log: Add the subscriber languages to subscription metadata at subscription time. Modified: collective.singing/trunk/collective/singing/browser/subscribe.py ============================================================================== --- collective.singing/trunk/collective/singing/browser/subscribe.py (original) +++ collective.singing/trunk/collective/singing/browser/subscribe.py Thu Nov 13 22:04:10 2008 @@ -2,6 +2,7 @@ from zope import component from zope import schema +import zope.i18n.interfaces import zope.schema.interfaces import zope.schema.vocabulary import zope.publisher.browser @@ -179,6 +180,18 @@ self.current_step.updateActions() return + # Set the language of the subscription. This is the only + # place we can assume that the language of the request is the + # language of the subscription: + try: + languages = zope.i18n.interfaces.IUserPreferredLanguages( + self.request).getPreferredLanguages() + except TypeError, e: + # No such adapter available + pass + else: + subscription.metadata['languages'] = languages + # Ask the composer to render a confirmation message composer = self.context.composers[self.format()] msg = composer.render_confirmation(subscription) Modified: collective.singing/trunk/collective/singing/browser/subscribe.txt ============================================================================== --- collective.singing/trunk/collective/singing/browser/subscribe.txt (original) +++ collective.singing/trunk/collective/singing/browser/subscribe.txt Thu Nov 13 22:04:10 2008 @@ -211,10 +211,40 @@ Trying to subscribe again for the same format and e-mail address will produce a form error: - >>> html = subscribe() # doctest: +NORMALIZE_WHITESPACE + >>> html = subscribe() >>> "You are already subscribed" in html True +Another language +---------------- + +The subscription add form will keep track of the preferred user's +language as defined by the ``IUserPreferredLanguages`` adapter. Let's +define such an adapter: + + >>> from zope.i18n.interfaces import IUserPreferredLanguages + >>> from zope.publisher.interfaces import IRequest + >>> class MyUserPreferredLanguages(object): + ... component.adapts(IRequest) + ... interface.implements(IUserPreferredLanguages) + ... + ... def __init__(self, request): + ... pass + ... def getPreferredLanguages(self): + ... return ['ba', 'bm'] + ... + >>> component.provideAdapter(MyUserPreferredLanguages) + + >>> request.form['composer.widgets.email'] = u'ha...@te...' + >>> html = subscribe() + This is your dispatcher speaking: This is a message to ha...@te... to confirm their subscription. + >>> 'Thanks for your subscription' in html + True + >>> sub = [s for s in channel.subscriptions.values() + ... if s.composer_data['email'].startswith('hanno')][0] + >>> sub.metadata['languages'] + ['ba', 'bm'] + Another format -------------- @@ -259,16 +289,16 @@ True >>> len(channel.subscriptions) - 2 + 3 >>> html = [sub for sub in channel.subscriptions.values() - ... if sub.metadata['format'] == 'html'][0] + ... if sub.metadata['format'] == 'html' and + ... sub.composer_data['email'].startswith('daniel')][0] >>> plaintext = [sub for sub in channel.subscriptions.values() - ... if sub.metadata['format'] == 'plaintext'][0] + ... if sub.metadata['format'] == 'plaintext' and + ... sub.composer_data['email'].startswith('daniel')][0] -We need to adapt the subscription objects to ``IComposerData`` and -``ICollectorData`` to confirm that the data we entered is actually -stored: +The data we entered was stored correctly: >>> dict(html.collector_data) {'colour': 'red'} @@ -332,8 +362,8 @@ >>> request.form['secret'] = u'da...@te...' >>> unsubscribe = Unsubscribe(channel, request) >>> len(channel.subscriptions) - 2 + 3 >>> unsubscribe() # doctest: +ELLIPSIS u'...You have been unsubscribed...' >>> len(channel.subscriptions) - 0 + 1 Modified: collective.singing/trunk/docs/HISTORY.txt ============================================================================== --- collective.singing/trunk/docs/HISTORY.txt (original) +++ collective.singing/trunk/docs/HISTORY.txt Thu Nov 13 22:04:10 2008 @@ -4,6 +4,9 @@ Version 0.6.6 - Unreleased -------------------------- +- Add the subscriber languages to subscription metadata at + subscription time. [nouri] + Version 0.6.5 - 2008-11-05 -------------------------- |