← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~salgado/launchpad/request-to-base-template-adapter into lp:launchpad

 

Guilherme Salgado has proposed merging lp:~salgado/launchpad/request-to-base-template-adapter into lp:launchpad with lp:~mwhudson/launchpad/vostok-traverse-distro as a prerequisite.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)


This branch makes it possible to use vostok's base template with any of Launchpad's templates.
It also makes all existing pages accessed using the vostok.dev vhost use vostok's base template.
-- 
https://code.launchpad.net/~salgado/launchpad/request-to-base-template-adapter/+merge/31982
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~salgado/launchpad/request-to-base-template-adapter into lp:launchpad.
=== modified file 'lib/canonical/launchpad/webapp/configure.zcml'
--- lib/canonical/launchpad/webapp/configure.zcml	2010-07-23 13:24:58 +0000
+++ lib/canonical/launchpad/webapp/configure.zcml	2010-08-06 18:38:30 +0000
@@ -711,6 +711,10 @@
         />
 
     <adapter
+        factory="canonical.launchpad.webapp.tales.LaunchpadLayerToMainTemplateAdapter"
+        />
+
+    <adapter
         factory="canonical.launchpad.webapp.snapshot.snapshot_sql_result" />
     <!-- It also works for the legacy SQLObject interface. -->
     <adapter

=== modified file 'lib/canonical/launchpad/webapp/tales.py'
--- lib/canonical/launchpad/webapp/tales.py	2010-07-30 06:08:54 +0000
+++ lib/canonical/launchpad/webapp/tales.py	2010-08-06 18:38:30 +0000
@@ -22,7 +22,7 @@
 from lazr.uri import URI
 
 from zope.interface import Interface, Attribute, implements
-from zope.component import getUtility, queryAdapter, getMultiAdapter
+from zope.component import adapts, getUtility, queryAdapter, getMultiAdapter
 from zope.app import zapi
 from zope.publisher.browser import BrowserView
 from zope.publisher.interfaces import IApplicationRequest
@@ -31,6 +31,7 @@
     ITraversable, IPathAdapter, TraversalError)
 from zope.security.interfaces import Unauthorized
 from zope.security.proxy import isinstance as zope_isinstance
+from zope.schema import TextLine
 
 import pytz
 from z3c.ptcompat import ViewPageTemplateFile
@@ -41,6 +42,7 @@
     ISprint, LicenseStatus)
 from canonical.launchpad.interfaces.launchpad import (
     IHasIcon, IHasLogo, IHasMugshot, IPrivacy)
+from canonical.launchpad.layers import LaunchpadLayer
 import canonical.launchpad.pagetitles
 from canonical.launchpad.webapp import canonical_url, urlappend
 from canonical.launchpad.webapp.authorization import check_permission
@@ -2297,6 +2299,20 @@
         return check_permission(name, self.context)
 
 
+class IMainTemplateFile(Interface):
+    path = TextLine(title=u'The absolute path to this main template.')
+
+
+class LaunchpadLayerToMainTemplateAdapter:
+    adapts(LaunchpadLayer)
+    implements(IMainTemplateFile)
+
+    def __init__(self, context):
+        here = os.path.dirname(os.path.realpath(__file__))
+        self.path = os.path.join(
+            here, '../../../lp/app/templates/base-layout.pt')
+
+
 class PageMacroDispatcher:
     """Selects a macro, while storing information about page layout.
 
@@ -2316,12 +2332,15 @@
 
     implements(ITraversable)
 
-    base = ViewPageTemplateFile('../../../lp/app/templates/base-layout.pt')
-
     def __init__(self, context):
         # The context of this object is a view object.
         self.context = context
 
+    @property
+    def base(self):
+        return ViewPageTemplateFile(
+            IMainTemplateFile(self.context.request).path)
+
     def traverse(self, name, furtherPath):
         if name == 'page':
             if len(furtherPath) == 1:

=== modified file 'lib/lp/testing/factory.py'
--- lib/lp/testing/factory.py	2010-08-06 18:38:28 +0000
+++ lib/lp/testing/factory.py	2010-08-06 18:38:30 +0000
@@ -1902,13 +1902,9 @@
             archive=archive,
             requester=requester,
             pocket=pocket,
-            date_created=date_created)
-        removeSecurityProxy(spr_build).status = status
-        if duration is not None:
-            naked_sprb = removeSecurityProxy(spr_build)
-            if naked_sprb.date_started is None:
-                naked_sprb.date_started = spr_build.date_created
-            naked_sprb.date_finished = naked_sprb.date_started + duration
+            date_created=date_created,
+            duration=duration)
+        removeSecurityProxy(spr_build).buildstate = status
         return spr_build
 
     def makeSourcePackageRecipeBuildJob(

=== modified file 'lib/lp/vostok/browser/configure.zcml'
--- lib/lp/vostok/browser/configure.zcml	2010-08-06 18:38:28 +0000
+++ lib/lp/vostok/browser/configure.zcml	2010-08-06 18:38:30 +0000
@@ -32,4 +32,6 @@
       classes="VostokRootNavigation"
       />
 
+  <adapter factory="lp.vostok.browser.root.VostokLayerToMainTemplateAdapter" />
+
 </configure>

=== modified file 'lib/lp/vostok/browser/root.py'
--- lib/lp/vostok/browser/root.py	2010-07-30 03:50:17 +0000
+++ lib/lp/vostok/browser/root.py	2010-08-06 18:38:30 +0000
@@ -6,19 +6,37 @@
 __metaclass__ = type
 __all__ = [
     'VostokRootView',
+    'VostokLayerToMainTemplateAdapter',
     ]
 
-from zope.component import getUtility
+import os
+
+from zope.component import adapts, getUtility
+from zope.interface import implements
 
 from canonical.launchpad.webapp import LaunchpadView
+from canonical.launchpad.webapp.tales import IMainTemplateFile
 
 from lp.registry.interfaces.distribution import IDistributionSet
 
+from lp.vostok.publisher import VostokLayer
+
 
 class VostokRootView(LaunchpadView):
     """The view for the Vostok root object."""
 
+    page_title = 'Vostok'
+
     @property
     def distributions(self):
         """An iterable of all registered distributions."""
         return getUtility(IDistributionSet)
+
+
+class VostokLayerToMainTemplateAdapter:
+    adapts(VostokLayer)
+    implements(IMainTemplateFile)
+
+    def __init__(self, context):
+        here = os.path.dirname(os.path.realpath(__file__))
+        self.path = os.path.join(here, '../templates/main-template.pt')

=== modified file 'lib/lp/vostok/browser/tests/test_root.py'
--- lib/lp/vostok/browser/tests/test_root.py	2010-07-30 03:50:17 +0000
+++ lib/lp/vostok/browser/tests/test_root.py	2010-08-06 18:38:30 +0000
@@ -5,12 +5,14 @@
 
 __metaclass__ = type
 
+import os
 import unittest
 
 from zope.app.publisher.browser import getDefaultViewName
 
 from canonical.testing.layers import DatabaseFunctionalLayer, FunctionalLayer
 from canonical.launchpad.testing.pages import extract_text, find_tag_by_id
+from canonical.launchpad.webapp.tales import IMainTemplateFile
 
 from lp.testing import TestCase, TestCaseWithFactory
 from lp.testing.views import create_initialized_view
@@ -19,7 +21,6 @@
 from lp.vostok.publisher import VostokLayer, VostokRoot
 
 
-
 class TestRootRegistrations(TestCase):
     """Test the registration of views for `VostokRoot`."""
 
@@ -72,5 +73,15 @@
             self.assertEqual(distro.displayname, extract_text(link))
 
 
+class TestVostokLayerToMainTemplateAdapter(TestCase):
+
+    layer = FunctionalLayer
+
+    def test_path(self):
+        main_template_path = IMainTemplateFile(VostokTestRequest()).path
+        self.assertIn('lp/vostok', main_template_path)
+        self.assertTrue(os.path.isfile(main_template_path))
+
+
 def test_suite():
     return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/vostok/templates/main-template.pt'
--- lib/lp/vostok/templates/main-template.pt	2010-07-30 04:38:05 +0000
+++ lib/lp/vostok/templates/main-template.pt	2010-08-06 18:38:30 +0000
@@ -3,13 +3,16 @@
   xmlns:tal="http://xml.zope.org/namespaces/tal";
   define-macro="master"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
 <html xmlns="http://www.w3.org/1999/xhtml";>
+
   <head>
-    <!-- Obviously, we'll need to do something better here. -->
-    <title>Vostok page</title>
+
+    <title tal:content="view/fmt:pagetitle">Page Title</title>
+
   </head>
+
   <body>
     <h1 metal:define-slot="heading" />
-    <div metal:define-slot="content" />
+    <div metal:define-slot="main" />
   </body>
 </html>
 </metal:page>

=== modified file 'lib/lp/vostok/templates/root.pt'
--- lib/lp/vostok/templates/root.pt	2010-07-15 10:11:03 +0000
+++ lib/lp/vostok/templates/root.pt	2010-08-06 18:38:30 +0000
@@ -3,13 +3,13 @@
    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"
+   metal:use-macro="view/macro:page/main_only"
    i18n:domain="vostok">
   <body>
     <tal:heading metal:fill-slot="heading">
       <h1>Vostok</h1>
     </tal:heading>
-    <tal:content metal:fill-slot="content">
+    <tal:content metal:fill-slot="main">
       <ul id="distro-list">
         <tal:loop tal:repeat="distro view/distributions">
           <li tal:content="structure distro/fmt:link" />