← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~stevenk/launchpad/force-views-into-line into lp:launchpad

 

Steve Kowalik has proposed merging lp:~stevenk/launchpad/force-views-into-line into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~stevenk/launchpad/force-views-into-line/+merge/93523

By using a hacky one-liner I'd rather not get into, I found a number of views that did not descend from LaunchpadView. Most of them are used for special cases only, but I did catch a large number of views that have reimplemented RedirectionView, so they have been refactored.

If I knew a view was actually a portlet in disguise I used a shell loop and sed to rename them.
-- 
https://code.launchpad.net/~stevenk/launchpad/force-views-into-line/+merge/93523
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~stevenk/launchpad/force-views-into-line into lp:launchpad.
=== modified file 'lib/lp/answers/browser/configure.zcml'
--- lib/lp/answers/browser/configure.zcml	2011-12-24 17:49:30 +0000
+++ lib/lp/answers/browser/configure.zcml	2012-02-17 04:15:22 +0000
@@ -1,4 +1,4 @@
-<!-- Copyright 2009 Canonical Ltd.  This software is licensed under the
+<!-- Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
      GNU Affero General Public License version 3 (see the file LICENSE).
 -->
 
@@ -37,7 +37,7 @@
     />
   <browser:page
     for="lp.answers.interfaces.questioncollection.IQuestionCollection"
-    class=".questiontarget.QuestionCollectionLatestQuestionsView"
+    class=".questiontarget.QuestionCollectionLatestQuestionsPortlet"
     name="+portlet-latestquestions"
     permission="zope.Public"
     template="../templates/questiontarget-portlet-latestquestions.pt"
@@ -113,7 +113,7 @@
   <browser:page
     name="+ask-a-question-button"
     for="lp.answers.interfaces.questiontarget.IQuestionTarget"
-    class=".questiontarget.AskAQuestionButtonView"
+    class=".questiontarget.AskAQuestionButtonPortlet"
     permission="zope.Public"
     />
   <browser:menus

=== modified file 'lib/lp/answers/browser/questiontarget.py'
--- lib/lp/answers/browser/questiontarget.py	2012-02-10 07:17:58 +0000
+++ lib/lp/answers/browser/questiontarget.py	2012-02-17 04:15:22 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """IQuestionTarget browser views."""
@@ -7,11 +7,11 @@
 
 __all__ = [
     'AnswersVHostBreadcrumb',
-    'AskAQuestionButtonView',
+    'AskAQuestionButtonPortlet',
     'ManageAnswerContactView',
     'SearchQuestionsView',
     'QuestionCollectionByLanguageView',
-    'QuestionCollectionLatestQuestionsView',
+    'QuestionCollectionLatestQuestionsPortlet',
     'QuestionCollectionMyQuestionsView',
     'QuestionCollectionNeedAttentionView',
     'QuestionCollectionOpenCountView',
@@ -98,7 +98,7 @@
 from lp.services.worlddata.interfaces.language import ILanguageSet
 
 
-class AskAQuestionButtonView:
+class AskAQuestionButtonPortlet:
     """View that renders a button to ask a question on its context."""
 
     def __call__(self):
@@ -154,7 +154,7 @@
         return languages
 
 
-class QuestionCollectionLatestQuestionsView:
+class QuestionCollectionLatestQuestionsPortlet:
     """View used to display the latest questions on a question target."""
 
     @property

=== modified file 'lib/lp/blueprints/browser/configure.zcml'
--- lib/lp/blueprints/browser/configure.zcml	2011-12-24 17:49:30 +0000
+++ lib/lp/blueprints/browser/configure.zcml	2012-02-17 04:15:22 +0000
@@ -1,4 +1,4 @@
-<!-- Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
+<!-- Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
      GNU Affero General Public License version 3 (see the file LICENSE).
 -->
 
@@ -128,7 +128,7 @@
     <browser:page
         name="+register-a-blueprint-button"
         for="lp.blueprints.interfaces.sprint.ISprint"
-        class="lp.blueprints.browser.specificationtarget.RegisterABlueprintButtonView"
+        class="lp.blueprints.browser.specificationtarget.RegisterABlueprintButtonPortlet"
         permission="zope.Public"/>
     <browser:pages
         for="lp.blueprints.interfaces.sprint.IHasSprints"
@@ -562,7 +562,7 @@
         <browser:page
             name="+register-a-blueprint-button"
             for="lp.blueprints.interfaces.specificationtarget.ISpecificationTarget"
-            class="lp.blueprints.browser.specificationtarget.RegisterABlueprintButtonView"
+            class="lp.blueprints.browser.specificationtarget.RegisterABlueprintButtonPortlet"
             permission="zope.Public"/>
 
     <browser:page

=== modified file 'lib/lp/blueprints/browser/specificationtarget.py'
--- lib/lp/blueprints/browser/specificationtarget.py	2012-02-12 23:35:07 +0000
+++ lib/lp/blueprints/browser/specificationtarget.py	2012-02-17 04:15:22 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """ISpecificationTarget browser views."""
@@ -8,7 +8,7 @@
 __all__ = [
     'HasSpecificationsMenuMixin',
     'HasSpecificationsView',
-    'RegisterABlueprintButtonView',
+    'RegisterABlueprintButtonPortlet',
     'SpecificationAssignmentsView',
     'SpecificationDocumentationView',
     ]
@@ -431,7 +431,7 @@
                           self.context.displayname)
 
 
-class RegisterABlueprintButtonView:
+class RegisterABlueprintButtonPortlet:
     """View that renders a button to register a blueprint on its context."""
 
     @cachedproperty

=== modified file 'lib/lp/blueprints/browser/tests/test_specificationtarget.py'
--- lib/lp/blueprints/browser/tests/test_specificationtarget.py	2012-01-01 02:58:52 +0000
+++ lib/lp/blueprints/browser/tests/test_specificationtarget.py	2012-02-17 04:15:22 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 __metaclass__ = type
@@ -29,7 +29,7 @@
     )
 
 
-class TestRegisterABlueprintButtonView(TestCaseWithFactory):
+class TestRegisterABlueprintButtonPortlet(TestCaseWithFactory):
     """Test specification menus links."""
     layer = DatabaseFunctionalLayer
 

=== modified file 'lib/lp/bugs/browser/bug.py'
--- lib/lp/bugs/browser/bug.py	2012-01-01 02:58:52 +0000
+++ lib/lp/bugs/browser/bug.py	2012-02-17 04:15:22 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """IBug related view classes."""
@@ -121,6 +121,7 @@
     ICanonicalUrlData,
     ILaunchBag,
     )
+from lp.services.webapp.publisher import RedirectionView
 
 
 class BugNavigation(Navigation):
@@ -683,19 +684,16 @@
             cache['notifications_text'] = self.notifications_text
 
 
-class BugWithoutContextView:
+class BugWithoutContextView(RedirectionView):
     """View that redirects to the new bug page.
 
     The user is redirected, to the oldest IBugTask ('oldest' being
     defined as the IBugTask with the smallest ID.)
     """
-    # XXX: BradCrittenden 2009-04-28 This class can go away since the
-    # publisher now takes care of the redirection to a bug task.
-    def redirectToNewBugPage(self):
-        """Redirect the user to the 'first' report of this bug."""
-        # An example of practicality beating purity.
-        self.request.response.redirect(
-            canonical_url(self.context.default_bugtask))
+
+    def __init__(self, context, request):
+        super(BugWithoutContextView, self).__init__(
+            canonical_url(context.default_bugtask), request)
 
 
 class BugEditViewBase(LaunchpadEditFormView):
@@ -940,7 +938,7 @@
                 structured(notification_text))
 
 
-class DeprecatedAssignedBugsView:
+class DeprecatedAssignedBugsView(RedirectionView):
     """Deprecate the /malone/assigned namespace.
 
     It's important to ensure that this namespace continues to work, to
@@ -950,14 +948,10 @@
     """
 
     def __init__(self, context, request):
-        self.context = context
-        self.request = request
-
-    def redirect_to_assignedbugs(self):
-        """Redirect the user to their assigned bugs report."""
-        self.request.response.redirect(
-            canonical_url(getUtility(ILaunchBag).user) +
-            "/+assignedbugs")
+        target = canonical_url(
+            getUtility(ILaunchBag).user, view='+assignedbugs')
+        super(DeprecatedAssignedBugsView, self).__init__(
+            target, request)
 
 
 normalize_mime_type = re.compile(r'\s+')

=== modified file 'lib/lp/bugs/browser/configure.zcml'
--- lib/lp/bugs/browser/configure.zcml	2012-02-01 15:26:32 +0000
+++ lib/lp/bugs/browser/configure.zcml	2012-02-17 04:15:22 +0000
@@ -1,4 +1,4 @@
-<!-- Copyright 2010-2011 Canonical Ltd.  This software is licensed under the
+<!-- Copyright 2010-2012 Canonical Ltd.  This software is licensed under the
      GNU Affero General Public License version 3 (see the file LICENSE).
 -->
 
@@ -264,7 +264,7 @@
         for="lp.bugs.interfaces.malone.IMaloneApplication"
         name="assigned"
         class="lp.bugs.browser.bug.DeprecatedAssignedBugsView"
-        attribute="redirect_to_assignedbugs"
+        attribute="__call__"
         permission="launchpad.AnyPerson"/>
     <browser:page
         for="lp.registry.interfaces.person.IPerson"
@@ -932,7 +932,7 @@
             name="+index"
             class="lp.bugs.browser.bug.BugWithoutContextView"
             permission="zope.Public"
-            attribute="redirectToNewBugPage"/>
+            attribute="__call__"/>
         <browser:page
             for="lp.bugs.interfaces.bug.IBug"
             class="lp.bugs.browser.bugtask.BugTasksAndNominationsView"

=== modified file 'lib/lp/registry/browser/configure.zcml'
--- lib/lp/registry/browser/configure.zcml	2012-02-13 21:48:25 +0000
+++ lib/lp/registry/browser/configure.zcml	2012-02-17 04:15:22 +0000
@@ -163,7 +163,7 @@
     <browser:page
         name="+ask-a-question-button"
         for="lp.registry.interfaces.distroseries.IDistroSeries"
-        class="lp.answers.browser.questiontarget.AskAQuestionButtonView"
+        class="lp.answers.browser.questiontarget.AskAQuestionButtonPortlet"
         permission="zope.Public"/>
     <browser:page
         name="+missingpackages"
@@ -337,7 +337,7 @@
         <browser:page
             name="+ask-a-question-button"
             for="lp.registry.interfaces.projectgroup.IProjectGroup"
-            class="lp.answers.browser.questiontarget.AskAQuestionButtonView"
+            class="lp.answers.browser.questiontarget.AskAQuestionButtonPortlet"
             permission="zope.Public"/>
     </facet>
     <browser:navigation
@@ -389,7 +389,7 @@
     <browser:page
         name="+register-a-blueprint-button"
         for="lp.registry.interfaces.projectgroup.IProjectGroup"
-        class="lp.blueprints.browser.specificationtarget.RegisterABlueprintButtonView"
+        class="lp.blueprints.browser.specificationtarget.RegisterABlueprintButtonPortlet"
         permission="zope.Public"/>
     <browser:page
         name="+edit"
@@ -1792,7 +1792,7 @@
     <browser:page
         name="+ask-a-question-button"
         for="lp.registry.interfaces.productseries.IProductSeries"
-        class="lp.answers.browser.questiontarget.AskAQuestionButtonView"
+        class="lp.answers.browser.questiontarget.AskAQuestionButtonPortlet"
         permission="zope.Public"/>
     <browser:url
         for="lp.registry.interfaces.productseries.IProductSeriesSet"

=== modified file 'lib/lp/soyuz/browser/binarypackagerelease.py'
--- lib/lp/soyuz/browser/binarypackagerelease.py	2011-12-26 17:56:55 +0000
+++ lib/lp/soyuz/browser/binarypackagerelease.py	2012-02-17 04:15:22 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 __metaclass__ = type
@@ -11,6 +11,7 @@
 from apt_pkg import parse_depends
 
 from lp.services.webapp import Navigation
+from lp.services.webapp.publisher import LaunchpadView
 from lp.soyuz.browser.packagerelationship import relationship_builder
 from lp.soyuz.interfaces.binarypackagerelease import IBinaryPackageRelease
 
@@ -19,13 +20,9 @@
     usedfor = IBinaryPackageRelease
 
 
-class BinaryPackageView:
+class BinaryPackageView(LaunchpadView):
     """View class for BinaryPackage"""
 
-    def __init__(self, context, request):
-        self.context = context
-        self.request = request
-
     def _relationship_parser(self, content):
         """Wrap the relationship_builder for BinaryPackages.
 

=== modified file 'lib/lp/translations/browser/potemplate.py'
--- lib/lp/translations/browser/potemplate.py	2012-02-07 14:38:23 +0000
+++ lib/lp/translations/browser/potemplate.py	2012-02-17 04:15:22 +0000
@@ -81,7 +81,10 @@
     ILaunchBag,
     )
 from lp.services.webapp.menu import structured
-from lp.services.webapp.publisher import LaunchpadView
+from lp.services.webapp.publisher import (
+    LaunchpadView,
+    RedirectionView,
+    )
 from lp.services.worlddata.interfaces.language import ILanguageSet
 from lp.translations.browser.poexportrequest import BaseExportView
 from lp.translations.browser.translations import TranslationsMixin
@@ -230,15 +233,11 @@
         return Link('+admin', text, icon='edit')
 
 
-class POTemplateSubsetView:
+class POTemplateSubsetView(RedirectionView):
 
     def __init__(self, context, request):
-        self.context = context
-        self.request = request
-
-    def __call__(self):
-        # We are not using this context directly, only for traversals.
-        self.request.response.redirect('../+translations')
+        super(POTemplateSubsetView, self).__init__(
+            '../+translations', request)
 
 
 class POTemplateView(LaunchpadView,

=== modified file 'lib/lp/translations/browser/translationmessage.py'
--- lib/lp/translations/browser/translationmessage.py	2012-01-01 02:58:52 +0000
+++ lib/lp/translations/browser/translationmessage.py	2012-02-17 04:15:22 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 # pylint: disable-msg=W0404
@@ -52,6 +52,7 @@
 from lp.services.webapp.batching import BatchNavigator
 from lp.services.webapp.interfaces import ILaunchBag
 from lp.services.webapp.menu import structured
+from lp.services.webapp.publisher import RedirectionView
 from lp.translations.browser.browser_helpers import (
     contract_rosetta_escapes,
     convert_newlines_to_web_form,
@@ -224,17 +225,13 @@
         return Link('../+export', text, icon='download')
 
 
-class CurrentTranslationMessageIndexView:
+class CurrentTranslationMessageIndexView(RedirectionView):
     """A view to forward to the translation form."""
 
     def __init__(self, context, request):
-        self.context = context
-        self.request = request
-
-    def __call__(self):
-        """Redirect to the translation form."""
-        url = '%s/%s' % (canonical_url(self.context), '+translate')
-        self.request.response.redirect(url)
+        target = canonical_url(context, view='+translate')
+        super(CurrentTranslationMessageIndexView, self).__init__(
+            target, request)
 
 
 def _getSuggestionFromFormId(form_id):

=== modified file 'lib/lp/translations/browser/translations.py'
--- lib/lp/translations/browser/translations.py	2012-01-01 02:58:52 +0000
+++ lib/lp/translations/browser/translations.py	2012-02-17 04:15:22 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 __metaclass__ = type
@@ -31,6 +31,7 @@
 from lp.services.webapp.batching import BatchNavigator
 from lp.services.webapp.breadcrumb import Breadcrumb
 from lp.services.webapp.interfaces import ILaunchpadRoot
+from lp.services.webapp.publisher import RedirectionView
 from lp.services.worlddata.helpers import preferred_or_request_languages
 from lp.services.worlddata.interfaces.country import ICountry
 from lp.translations.interfaces.translations import IRosettaApplication
@@ -113,14 +114,10 @@
             getUtility(IProductSet).getTranslatables(), self.request)
 
 
-class RosettaStatsView:
+class RosettaStatsView(LaunchpadView):
     """A view class for objects that support IRosettaStats. This is mainly
     used for the sortable untranslated percentage."""
 
-    def __init__(self, context, request):
-        self.context = context
-        self.request = request
-
     def sortable_untranslated(self):
         return '%06.2f' % self.context.untranslatedPercentage()
 
@@ -158,35 +155,24 @@
         return getUtility(IProductSet)
 
 
-class PageRedirectView:
-    """Redirects to translations site for the given page."""
-
-    def __init__(self, context, request, page):
-        self.context = context
-        self.request = request
-        self.page = page
-
-    def __call__(self):
-        """Redirect to self.page in the translations site."""
-        self.request.response.redirect(
-            '/'.join([
-                canonical_url(self.context, rootsite='translations'),
-                self.page,
-                ]), status=301)
-
-
-class TranslateRedirectView(PageRedirectView):
+class TranslateRedirectView(RedirectionView):
     """Redirects to translations site for +translate page."""
 
     def __init__(self, context, request):
-        PageRedirectView.__init__(self, context, request, '+translate')
-
-
-class TranslationsRedirectView(PageRedirectView):
+        target = canonical_url(
+            context, rootsite='translations', view='+translate')
+        super(TranslateRedirectView, self).__init__(
+            target, request, status=301)
+
+
+class TranslationsRedirectView(RedirectionView):
     """Redirects to translations site for +translations page."""
 
     def __init__(self, context, request):
-        PageRedirectView.__init__(self, context, request, '+translations')
+        target = canonical_url(
+            context, rootsite='translations', view='+translations')
+        super(TranslationsRedirectView, self).__init__(
+            target, request, status=301)
 
 
 class TranslationsVHostBreadcrumb(Breadcrumb):