launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #00332
[Merge] lp:~mwhudson/launchpad/vostok-main-template into lp:launchpad/devel
Michael Hudson has proposed merging lp:~mwhudson/launchpad/vostok-main-template into lp:launchpad/devel with lp:~mwhudson/launchpad/vostok-add-root as a prerequisite.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
Hi,
This branch adds a very simple main template METAL macro for the vostok layer
and makes the view for the root object use it.
The macro is done in an old-school way compared to how it's done in Launchpad
today, mostly because we couldn't be bothered to figure out how to make the
macro: tales stuff be layer dependent and also because we should be able to get
away with all our pages using the same main template macro.
Cheers,
mwh
--
https://code.launchpad.net/~mwhudson/launchpad/vostok-main-template/+merge/31240
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~mwhudson/launchpad/vostok-main-template into lp:launchpad/devel.
=== modified file 'lib/lp/vostok/browser/configure.zcml'
--- lib/lp/vostok/browser/configure.zcml 2010-07-29 05:16:03 +0000
+++ lib/lp/vostok/browser/configure.zcml 2010-07-29 05:16:05 +0000
@@ -5,6 +5,14 @@
xmlns:xmlrpc="http://namespaces.zope.org/xmlrpc"
i18n_domain="launchpad">
+ <browser:page
+ for="*"
+ name="main_template"
+ template="../templates/main-template.pt"
+ permission="zope.Public"
+ layer="lp.vostok.publisher.VostokLayer"
+ />
+
<browser:defaultView
for="lp.vostok.publisher.IVostokRoot"
name="+index"
=== modified file 'lib/lp/vostok/browser/root.py'
--- lib/lp/vostok/browser/root.py 2010-07-29 05:16:03 +0000
+++ lib/lp/vostok/browser/root.py 2010-07-29 05:16:05 +0000
@@ -8,8 +8,15 @@
'VostokRootView',
]
+from zope.component import getUtility
+
from canonical.launchpad.webapp import LaunchpadView
+from lp.registry.interfaces.distribution import IDistributionSet
+
class VostokRootView(LaunchpadView):
- pass
+
+ @property
+ def distributions(self):
+ return getUtility(IDistributionSet)
=== modified file 'lib/lp/vostok/browser/tests/request.py'
--- lib/lp/vostok/browser/tests/request.py 2010-07-29 05:16:03 +0000
+++ lib/lp/vostok/browser/tests/request.py 2010-07-29 05:16:05 +0000
@@ -8,12 +8,10 @@
'VostokTestRequest',
]
-from zope.interface import implements
-
from canonical.launchpad.webapp.servers import LaunchpadTestRequest
-from lp.vostok.publisher import VostokLayer
-
-
-class VostokTestRequest(LaunchpadTestRequest):
- implements(VostokLayer)
+from lp.vostok.publisher import VostokRequestMixin
+
+
+class VostokTestRequest(VostokRequestMixin, LaunchpadTestRequest):
+ pass
=== added file 'lib/lp/vostok/browser/tests/test_main_template.py'
--- lib/lp/vostok/browser/tests/test_main_template.py 1970-01-01 00:00:00 +0000
+++ lib/lp/vostok/browser/tests/test_main_template.py 2010-07-29 05:16:05 +0000
@@ -0,0 +1,33 @@
+# Copyright 2010 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Tests for the vostok 'main_template'."""
+
+__metaclass__ = type
+
+import unittest
+
+from zope.component import getMultiAdapter
+
+from canonical.testing.layers import FunctionalLayer
+
+from lp.testing import TestCase
+from lp.vostok.browser.tests.request import VostokTestRequest
+
+
+class TestMainTemplate(TestCase):
+ """Tests for our main template."""
+
+ layer = FunctionalLayer
+
+ def test_main_template_defines_master_macro(self):
+ # The main template, which is registered as a view for any object at
+ # all when in the VostokLayer, defines a 'master' macro.
+ adapter = getMultiAdapter(
+ (None, VostokTestRequest()), name='main_template')
+ self.assertEqual(['master'], adapter.index.macros.keys())
+ self.assertIn('lp/vostok', adapter.index.filename)
+
+
+def test_suite():
+ return unittest.TestLoader().loadTestsFromName(__name__)
=== modified file 'lib/lp/vostok/browser/tests/test_root.py'
--- lib/lp/vostok/browser/tests/test_root.py 2010-07-29 05:16:03 +0000
+++ lib/lp/vostok/browser/tests/test_root.py 2010-07-29 05:16:05 +0000
@@ -10,14 +10,15 @@
from zope.app.publisher.browser import getDefaultViewName
from zope.component import getMultiAdapter
-from canonical.testing.layers import FunctionalLayer
+from canonical.testing.layers import DatabaseFunctionalLayer, FunctionalLayer
+from canonical.launchpad.testing.pages import extract_text, find_tag_by_id
-from lp.testing import TestCase
+from lp.testing import TestCase, TestCaseWithFactory, with_anonymous_login
from lp.vostok.browser.root import VostokRootView
from lp.vostok.browser.tests.request import VostokTestRequest
from lp.vostok.publisher import VostokRoot
-class TestBrowseRoot(TestCase):
+class TestRootRegistrations(TestCase):
layer = FunctionalLayer
@@ -34,5 +35,39 @@
self.assertIsInstance(view, VostokRootView)
+class TestRootView(TestCaseWithFactory):
+
+ layer = DatabaseFunctionalLayer
+
+ def view(self):
+ return getMultiAdapter(
+ (VostokRoot(), VostokTestRequest()), name='+index')
+
+ def test_distributions(self):
+ # VostokRootView.distributions is an iterable of all registered
+ # distributions.
+ root_view = self.view()
+ new_distro = self.factory.makeDistribution()
+ self.assertIn(new_distro, list(root_view.distributions))
+
+
+class TestRootTemplate(TestCaseWithFactory):
+
+ layer = DatabaseFunctionalLayer
+
+ def test_distribution_list(self):
+ # The element with id 'distro-list' on the root page contains a list
+ # of links to all registered distributions.
+ v = getMultiAdapter(
+ (VostokRoot(), VostokTestRequest()), name='+index')
+ v.initialize()
+ contents = v.render()
+ link_list = find_tag_by_id(contents, 'distro-list')('a')
+ distro_list = list(v.distributions)
+ self.assertEqual(len(link_list), len(distro_list))
+ for distro, link in zip(distro_list, link_list):
+ self.assertEqual(distro.displayname, extract_text(link))
+
+
def test_suite():
return unittest.TestLoader().loadTestsFromName(__name__)
=== modified file 'lib/lp/vostok/publisher.py'
--- lib/lp/vostok/publisher.py 2010-07-29 05:16:03 +0000
+++ lib/lp/vostok/publisher.py 2010-07-29 05:16:05 +0000
@@ -18,15 +18,25 @@
from canonical.launchpad.webapp.publication import LaunchpadBrowserPublication
from canonical.launchpad.webapp.servers import (
LaunchpadBrowserRequest, VirtualHostRequestPublicationFactory)
+from canonical.launchpad.webapp.vhosts import allvhosts
class VostokLayer(IBrowserRequest, IDefaultBrowserLayer):
"""The Vostok layer."""
-class VostokBrowserRequest(LaunchpadBrowserRequest):
+class VostokRequestMixin:
+
implements(VostokLayer)
+ def getRootURL(self, rootsite):
+ """See `IBasicLaunchpadRequest`."""
+ return allvhosts.configs['vostok'].rooturl
+
+
+class VostokBrowserRequest(VostokRequestMixin, LaunchpadBrowserRequest):
+ pass
+
class IVostokRoot(Interface): # might need to inherit from some IRoot thing
"""Marker interface for the root vostok object."""
=== added file 'lib/lp/vostok/templates/main-template.pt'
--- lib/lp/vostok/templates/main-template.pt 1970-01-01 00:00:00 +0000
+++ lib/lp/vostok/templates/main-template.pt 2010-07-29 05:16:05 +0000
@@ -0,0 +1,7 @@
+<metal:page
+ xmlns:metal="http://xml.zope.org/namespaces/metal"
+ xmlns:tal="http://xml.zope.org/namespaces/tal"
+ define-macro="master">
+<h1 metal:define-slot="heading" />
+<div metal:define-slot="content" />
+</metal:page>
=== modified file 'lib/lp/vostok/templates/root.pt'
--- lib/lp/vostok/templates/root.pt 2010-07-29 05:16:03 +0000
+++ lib/lp/vostok/templates/root.pt 2010-07-29 05:16:05 +0000
@@ -1,3 +1,20 @@
-<big>
-THIS IS VOSTOK
-</big>
+<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="context/@@main_template/master"
+ i18n:domain="vostok">
+ <body>
+ <tal:heading metal:fill-slot="heading">
+ <h1>Vostok</h1>
+ </tal:heading>
+ <tal:content metal:fill-slot="content">
+ <ul id="distro-list">
+ <tal:loop tal:repeat="distro view/distributions">
+ <li tal:content="structure distro/fmt:link" />
+ </tal:loop>
+ </ul>
+ </tal:content>
+ </body>
+</html>