← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~jcsackett/launchpad/grackle-lp-views into lp:launchpad

 

j.c.sackett has proposed merging lp:~jcsackett/launchpad/grackle-lp-views into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~jcsackett/launchpad/grackle-lp-views/+merge/89758

Summary
=======
>From work at the epic, we've begun creation of a new mail
archiver--grackle--to be used in launchpad. This branch introduces the mail
archive list view to the lp codebase. It isn't wired in anywhere yet, just
getting the code into place so we can begin integrating grackle as the client
is finished.

Preimp
======
Curtis Hovey, Aaron Bentley

Implementation
==============
lp.registry.browser.team
* Added TeamMailingListArchiveView. This is a simple view that can eventually
  use the grackle client to fetch messages, process them, and dump them into
  the IJSONRequestCache for a YUI module to handle and display.
* This view has been added to the zcml, but is not linked to, so we have not
  put any of the code behind feature flags, as there is no way for a user to
  be sent to it at this time.

Tests
=====
bin/test -vvct MailingListArchiveView

QA
==
This is essentialy no-qa.

If you like, go to launchpad.net/$team/+mailing-list-archive. You will see an
empty page.

Lint
====
= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/registry/browser/configure.zcml
  lib/lp/registry/browser/team.py
  lib/lp/registry/browser/tests/test_team.py
  lib/lp/registry/templates/team-mailinglist-archive.pt

-- 
https://code.launchpad.net/~jcsackett/launchpad/grackle-lp-views/+merge/89758
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jcsackett/launchpad/grackle-lp-views into lp:launchpad.
=== modified file 'lib/lp/registry/browser/configure.zcml'
--- lib/lp/registry/browser/configure.zcml	2012-01-04 12:08:24 +0000
+++ lib/lp/registry/browser/configure.zcml	2012-01-23 18:21:20 +0000
@@ -1140,6 +1140,12 @@
             name="+mailinglist-moderate"
             template="../templates/team-mailinglist-moderate.pt"/>
         <browser:page
+            for="lp.registry.interfaces.person.ITeam"
+            class="lp.registry.browser.team.TeamMailingListArchiveView"
+            permission="zope.Public"
+            name="+mailing-list-archive"
+            template="../templates/team-mailinglist-archive.pt"/>
+        <browser:page
             name="+edit"
             for="lp.registry.interfaces.person.ITeam"
             class="lp.registry.browser.team.TeamEditView"

=== modified file 'lib/lp/registry/browser/team.py'
--- lib/lp/registry/browser/team.py	2012-01-18 00:15:38 +0000
+++ lib/lp/registry/browser/team.py	2012-01-23 18:21:20 +0000
@@ -19,6 +19,7 @@
     'TeamMailingListConfigurationView',
     'TeamMailingListModerationView',
     'TeamMailingListSubscribersView',
+    'TeamMailingListArchiveView',
     'TeamMapData',
     'TeamMapLtdData',
     'TeamMapView',
@@ -42,7 +43,9 @@
 import math
 from urllib import unquote
 
+from lazr.restful.interfaces import IJSONRequestCache
 from lazr.restful.utils import smartquote
+import simplejson
 import pytz
 from z3c.ptcompat import ViewPageTemplateFile
 from zope.app.form.browser import TextAreaWidget
@@ -947,6 +950,23 @@
         self.next_url = canonical_url(self.context)
 
 
+class TeamMailingListArchiveView(LaunchpadView):
+
+    label = "Mailing list archive"
+
+    def __init__(self, context, request):
+        super(TeamMailingListArchiveView, self).__init__(context, request)
+        self.messages = self._get_messages()
+        cache = IJSONRequestCache(request).objects
+        cache['mail'] = self.messages
+
+    def _get_messages(self):
+        # XXX: jcsackett 18-1-2012: This needs to be updated to use the
+        # grackle client, once that is available, instead of returning
+        # an empty list as it does now.
+        return simplejson.loads('[]')
+
+
 class TeamAddView(TeamFormMixin, HasRenewalPolicyMixin, LaunchpadFormView):
     """View for adding a new team."""
 

=== modified file 'lib/lp/registry/browser/tests/test_team.py'
--- lib/lp/registry/browser/tests/test_team.py	2012-01-18 22:05:33 +0000
+++ lib/lp/registry/browser/tests/test_team.py	2012-01-23 18:21:20 +0000
@@ -3,6 +3,9 @@
 
 __metaclass__ = type
 
+import contextlib
+from lazr.restful.interfaces import IJSONRequestCache
+import simplejson
 import transaction
 from zope.component import getUtility
 from zope.security.proxy import removeSecurityProxy
@@ -21,6 +24,7 @@
     ITeamMembershipSet,
     TeamMembershipStatus,
     )
+from lp.registry.browser.team import TeamMailingListArchiveView
 from lp.services.propertycache import get_property_cache
 from lp.services.webapp.authorization import check_permission
 from lp.services.webapp.publisher import canonical_url
@@ -461,6 +465,43 @@
         self.assertEqual('Configure mailing list', link.text)
 
 
+class TestMailingListArchiveView(TestCaseWithFactory):
+
+    layer = DatabaseFunctionalLayer
+
+    def test_no_messages(self):
+        team = self.factory.makeTeam()
+        self.factory.makeMailingList(team, team.teamowner)
+        view = create_view(team, name='+mailing-list-archive')
+        messages = IJSONRequestCache(view.request).objects['mail']
+        self.assertEqual(0, len(messages))
+
+    @contextlib.contextmanager
+    def _override_messages(self, view_class, messages):
+        def _message_shim(self):
+            return simplejson.loads(messages)
+        tmp = TeamMailingListArchiveView._get_messages
+        TeamMailingListArchiveView._get_messages = _message_shim
+        yield TeamMailingListArchiveView
+        TeamMailingListArchiveView._get_messages = tmp
+
+    def test_messages_are_in_json(self):
+        team = self.factory.makeTeam()
+        self.factory.makeMailingList(team, team.teamowner)
+        messages = '''[{
+            "headers": {
+                "To": "somelist@xxxxxxxxxxx",
+                "From": "someguy@xxxxxxxxxxx",
+                "Subject": "foobar"},
+            "message_id": "foo"}]'''
+
+        with self._override_messages(TeamMailingListArchiveView, messages):
+            view = create_view(team, name='+mailing-list-archive')
+            messages = IJSONRequestCache(view.request).objects['mail']
+            self.assertEqual(1, len(messages))
+            self.assertEqual('foo', messages[0]['message_id'])
+
+
 class TestModeration(TestCaseWithFactory):
 
     layer = DatabaseFunctionalLayer

=== added file 'lib/lp/registry/templates/team-mailinglist-archive.pt'
--- lib/lp/registry/templates/team-mailinglist-archive.pt	1970-01-01 00:00:00 +0000
+++ lib/lp/registry/templates/team-mailinglist-archive.pt	2012-01-23 18:21:20 +0000
@@ -0,0 +1,21 @@
+<html
+  xmlns="http://www.w3.org/1999/xhtml";
+  xmlns:tal="http://xml.zope.org/namespaces/tal";
+  xmlns:metal="http://xml.zope.org/namespaces/metal";
+  xmlns:i18n="http://xml.zope.org/namespaces/i18n";
+  metal:use-macro="view/macro:page/main_only"
+  i18n:domain="launchpad"
+>
+
+
+<body>
+  <div metal:fill-slot="main">
+    <h2>Message archive for <tal:teamname replace="view/context/displayname" /></h2>
+    <ul id="messagelist">
+        <tal:comment replace="nothing">
+        The json loaded and manipulated messages go here.
+        </tal:comment>
+    </ul>
+  </div>
+</body>
+</html>