← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~henninge/launchpad/devel-705176-sharing-info-on-page into lp:launchpad

 

Henning Eggers has proposed merging lp:~henninge/launchpad/devel-705176-sharing-info-on-page into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  #705176 Improve sharing information on translation pages
  https://bugs.launchpad.net/bugs/705176

For more details, see:
https://code.launchpad.net/~henninge/launchpad/devel-705176-sharing-info-on-page/+merge/51283

= Summary =

First step: display sharing information on translation pages. This
makes it easy for translators to go to the "other side" of a
translation link (i.e. a packaging link).

The next step will be to add a link to a page where more detail about
translation sharing can be found and which also allows to setup
sharing.

== Proposed fix ==

Use the functions provided in translationsharinginfo to display the
correct text and link on the pages.

== Pre-implementation notes ==

I chatted with Deryck about this. We weren't entirely sure, where
exactly to place the information on the pages. At least I was, so this
is still up to UI discussion.

== Implementation details ==

Pretty straight forward implementation of test, view class attributes
and templates.

I changed the get_ubuntu_sharing_info to return a list instead of a
generator. This was easier to handle and is also symmetric to
get_upstream_translation_info.

== Tests ==

bin/test -vvcm lp.translations.browser.test.test_sharing_information

== Demo and Q/A ==

View sharing information for a product series here:
http://translations.launchpad.dev/evolution/trunk

View sharing information for a template here:
http://translations.launchpad.dev/evolution/trunk/+pots/evolution-2.2

Once on the other side, you'll see the equivalent links there.


= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/translations/templates/sourcepackage-translations.pt
  lib/lp/translations/templates/potemplate-index.pt
  lib/lp/translations/utilities/translationsharinginfo.py
  lib/lp/translations/templates/productseries-translations.pt
  lib/lp/translations/browser/productseries.py
  lib/lp/translations/browser/tests/test_sharing_information.py
  lib/lp/translations/browser/sourcepackage.py
  lib/lp/translations/browser/potemplate.py

./lib/lp/translations/templates/potemplate-index.pt
      47: Line has trailing whitespace.
      76: Line has trailing whitespace.
-- 
https://code.launchpad.net/~henninge/launchpad/devel-705176-sharing-info-on-page/+merge/51283
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~henninge/launchpad/devel-705176-sharing-info-on-page into lp:launchpad.
=== modified file 'lib/lp/translations/browser/potemplate.py'
--- lib/lp/translations/browser/potemplate.py	2010-12-02 16:13:51 +0000
+++ lib/lp/translations/browser/potemplate.py	2011-02-25 12:10:00 +0000
@@ -77,12 +77,19 @@
     IPOTemplateSet,
     IPOTemplateSubset,
     )
+from lp.translations.interfaces.side import TranslationSide
 from lp.translations.interfaces.translationimporter import (
     ITranslationImporter,
     )
 from lp.translations.interfaces.translationimportqueue import (
     ITranslationImportQueue,
     )
+from lp.translations.utilities.translationsharinginfo import (
+    has_ubuntu_template,
+    get_ubuntu_sharing_info,
+    has_upstream_template,
+    get_upstream_sharing_info,
+    )
 
 
 class POTemplateNavigation(Navigation):
@@ -354,6 +361,35 @@
             pofile = pofileset.getDummy(self.context, language)
         return pofile
 
+    @property
+    def is_upstream_template(self):
+        return self.context.translation_side == TranslationSide.UPSTREAM
+
+    def is_sharing(self):
+        if self.is_upstream_template:
+            return has_ubuntu_template(
+                productseries=self.context.productseries,
+                templatename=self.context.name)
+        else:
+            return has_upstream_template(
+                sourcepackage=self.context.sourcepackage,
+                templatename=self.context.name)
+
+    @property
+    def sharing_template(self):
+        if self.is_upstream_template:
+            infos = get_ubuntu_sharing_info(
+                productseries=self.context.productseries,
+                templatename=self.context.name)
+        else:
+            infos = get_upstream_sharing_info(
+                sourcepackage=self.context.sourcepackage,
+                templatename=self.context.name)
+        if len(infos) == 0:
+            return None
+        obj, template = infos[0]
+        return template
+
 
 class POTemplateUploadView(LaunchpadView, TranslationsMixin):
     """Upload translations and updated template."""

=== modified file 'lib/lp/translations/browser/productseries.py'
--- lib/lp/translations/browser/productseries.py	2011-02-02 15:43:31 +0000
+++ lib/lp/translations/browser/productseries.py	2011-02-25 12:10:00 +0000
@@ -61,6 +61,10 @@
 from lp.translations.interfaces.translations import (
     TranslationsBranchImportMode,
     )
+from lp.translations.utilities.translationsharinginfo import (
+    has_ubuntu_template,
+    get_ubuntu_sharing_info,
+    )
 
 
 class ProductSeriesTranslationsMenuMixIn:
@@ -447,6 +451,17 @@
         """Whether or not the user is a translations admin."""
         return check_permission("launchpad.TranslationsAdmin", self.context)
 
+    def is_sharing(self):
+        return has_ubuntu_template(productseries=self.context)
+
+    @property
+    def sharing_sourcepackage(self):
+        infos = get_ubuntu_sharing_info(productseries=self.context)
+        if len(infos) == 0:
+            return None
+        sourcepackage, template = infos[0]
+        return sourcepackage
+
 
 class SettingsRadioWidget(LaunchpadRadioWidgetWithDescription):
     """Remove the confusing hint under the widget."""

=== modified file 'lib/lp/translations/browser/sourcepackage.py'
--- lib/lp/translations/browser/sourcepackage.py	2010-08-20 20:31:18 +0000
+++ lib/lp/translations/browser/sourcepackage.py	2011-02-25 12:10:00 +0000
@@ -19,9 +19,14 @@
 from lp.registry.interfaces.sourcepackage import ISourcePackage
 from lp.translations.browser.poexportrequest import BaseExportView
 from lp.translations.browser.translations import TranslationsMixin
+from lp.translations.utilities.translationsharinginfo import (
+    has_upstream_template,
+    get_upstream_sharing_info,
+    )
 
 
 class SourcePackageTranslationsView(TranslationsMixin):
+
     @property
     def potemplates(self):
         return list(self.context.getCurrentTranslationTemplates())
@@ -30,6 +35,18 @@
     def label(self):
         return "Translations for %s" % self.context.displayname
 
+    def is_sharing(self):
+        return has_upstream_template(self.context)
+
+    @property
+    def sharing_productseries(self):
+        infos = get_upstream_sharing_info(self.context)
+        if len(infos) == 0:
+            return None
+
+        productseries, template = infos[0]
+        return productseries
+
 
 class SourcePackageTranslationsMenu(NavigationMenu):
     usedfor = ISourcePackage

=== added file 'lib/lp/translations/browser/tests/test_sharing_information.py'
--- lib/lp/translations/browser/tests/test_sharing_information.py	1970-01-01 00:00:00 +0000
+++ lib/lp/translations/browser/tests/test_sharing_information.py	2011-02-25 12:10:00 +0000
@@ -0,0 +1,175 @@
+# Copyright 2010 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Tests for the POTemplate recipe view classes and templates."""
+
+__metaclass__ = type
+
+from canonical.testing.layers import DatabaseFunctionalLayer
+from canonical.launchpad.testing.pages import (
+    extract_text,
+    find_tag_by_id,
+    )
+from lp.app.enums import ServiceUsage
+from lp.testing import (
+    BrowserTestCase,
+    celebrity_logged_in,
+    )
+from lp.translations.interfaces.side import TranslationSide
+
+
+def set_translations_usage(obj):
+    """Set the translations_usage to LAUNCHPAD."""
+    with celebrity_logged_in('admin'):
+        obj.translations_usage = ServiceUsage.LAUNCHPAD
+
+
+def enable_translations_on_distroseries(distroseries):
+    with celebrity_logged_in('admin'):
+        distroseries.hide_all_translations = False
+
+
+class TestSharingInfoMixin:
+    """Test display of sharing info."""
+
+    def makeNotSharingObject(self):
+        """Create an object that is not sharing."""
+        raise NotImplementedError
+
+    NOT_SHARING_TEXT = None
+
+    def makeSharingObject(self):
+        """Create an object that is sharing."""
+        raise NotImplementedError
+
+    SHARING_TEXT = None
+
+    def _test_sharing_information(self, obj, expected_text):
+        browser = self.getViewBrowser(
+            obj, no_login=True, rootsite="translations")
+        sharing_info = find_tag_by_id(browser.contents, 'sharing-information')
+        self.assertIsNot(None, sharing_info)
+        self.assertTextMatchesExpressionIgnoreWhitespace(
+            expected_text, extract_text(sharing_info))
+
+    def test_not_sharing(self):
+        self._test_sharing_information(
+            self.makeNotSharingObject(), self.NOT_SHARING_TEXT)
+
+    def test_sharing(self):
+        self._test_sharing_information(
+            self.makeSharingObject(), self.SHARING_TEXT)
+
+
+class TestUpstreamPOTemplateSharingInfo(BrowserTestCase,
+                                        TestSharingInfoMixin):
+    """Test display of template sharing info."""
+
+    layer = DatabaseFunctionalLayer
+
+    def makeNotSharingObject(self):
+        return self.factory.makePOTemplate()
+
+    NOT_SHARING_TEXT = """
+        This template is not sharing translations with a template in an
+        Ubuntu source package."""
+
+    def makeSharingObject(self):
+        template = self.factory.makePOTemplate()
+        packaging = self.factory.makePackagingLink(
+            productseries=template.productseries, in_ubuntu=True)
+        self.factory.makePOTemplate(
+            distroseries=packaging.distroseries,
+            sourcepackagename=packaging.sourcepackagename,
+            name=template.name)
+        return template
+
+    SHARING_TEXT = """
+        This template is sharing translations with .*"""
+
+
+class TestUpstreamSharingInfo(BrowserTestCase, TestSharingInfoMixin):
+    """Test display of product series sharing info."""
+
+    layer = DatabaseFunctionalLayer
+
+    def makeNotSharingObject(self):
+        productseries = self.factory.makeProductSeries()
+        set_translations_usage(productseries.product)
+        return productseries
+
+    NOT_SHARING_TEXT = """
+        This project series is not sharing translations with an Ubuntu source
+        package."""
+
+    def makeSharingObject(self):
+        template = self.factory.makePOTemplate()
+        packaging = self.factory.makePackagingLink(
+            productseries=template.productseries, in_ubuntu=True)
+        self.factory.makePOTemplate(
+            distroseries=packaging.distroseries,
+            sourcepackagename=packaging.sourcepackagename,
+            name=template.name)
+        return template.productseries
+
+    SHARING_TEXT = """
+        This project series is sharing translations with .*"""
+
+
+class TestUbuntuPOTemplateSharingInfo(BrowserTestCase, TestSharingInfoMixin):
+    """Test display of template sharing info in an Ubuntu source package."""
+
+    layer = DatabaseFunctionalLayer
+
+    def makeNotSharingObject(self):
+        template = self.factory.makePOTemplate(side=TranslationSide.UBUNTU)
+        enable_translations_on_distroseries(template.distroseries)
+        return template
+
+    NOT_SHARING_TEXT = """
+        This template is not sharing translations with a template in an
+        upstream project."""
+
+    def makeSharingObject(self):
+        upstream_template = self.factory.makePOTemplate()
+        packaging = self.factory.makePackagingLink(
+            productseries=upstream_template.productseries, in_ubuntu=True)
+        template = self.factory.makePOTemplate(
+            distroseries=packaging.distroseries,
+            sourcepackagename=packaging.sourcepackagename,
+            name=upstream_template.name)
+        enable_translations_on_distroseries(packaging.distroseries)
+        return template
+
+    SHARING_TEXT = """
+        This template is sharing translations with .*"""
+
+
+class TestUbuntuSharingInfo(BrowserTestCase, TestSharingInfoMixin):
+    """Test display of source package sharing info."""
+
+    layer = DatabaseFunctionalLayer
+
+    def makeNotSharingObject(self):
+        sourcepackage = self.factory.makeSourcePackage(
+            distroseries=self.factory.makeUbuntuDistroSeries())
+        enable_translations_on_distroseries(sourcepackage.distroseries)
+        return sourcepackage
+
+    NOT_SHARING_TEXT = """
+        This source package is not sharing translations with an upstream
+        project."""
+
+    def makeSharingObject(self):
+        upstream_template = self.factory.makePOTemplate()
+        packaging = self.factory.makePackagingLink(
+            productseries=upstream_template.productseries, in_ubuntu=True)
+        self.factory.makePOTemplate(
+            distroseries=packaging.distroseries,
+            sourcepackagename=packaging.sourcepackagename,
+            name=upstream_template.name)
+        enable_translations_on_distroseries(packaging.distroseries)
+        return packaging.sourcepackage
+
+    SHARING_TEXT = """
+        This source package is sharing translations with .*"""

=== modified file 'lib/lp/translations/templates/potemplate-index.pt'
--- lib/lp/translations/templates/potemplate-index.pt	2010-10-10 21:54:16 +0000
+++ lib/lp/translations/templates/potemplate-index.pt	2011-02-25 12:10:00 +0000
@@ -84,6 +84,24 @@
 
   <div class="yui-g">
     <div class="yui-u first">
+      <div class="portlet" id="sharing-information">
+        <h3>Sharing Information</h3>
+        <p tal:condition="not:view/is_sharing">
+          This template is not sharing translations with
+          a template in an
+          <span tal:condition="view/is_upstream_template">
+              Ubuntu source package</span>
+          <span tal:condition="not:view/is_upstream_template">
+              upstream project</span>.
+        </p>
+        <p tal:condition="view/is_sharing"
+           tal:define="template view/sharing_template">
+          This template is sharing translations with
+          <a tal:content="template/title"
+             tal:attributes="href template/fmt:url"
+             >template</a>.
+        </p>
+      </div>
       <div class="portlet">
         <h3>Permissions</h3>
         <p>

=== modified file 'lib/lp/translations/templates/productseries-translations.pt'
--- lib/lp/translations/templates/productseries-translations.pt	2010-11-03 13:04:59 +0000
+++ lib/lp/translations/templates/productseries-translations.pt	2011-02-25 12:10:00 +0000
@@ -79,6 +79,19 @@
         </div>
 
         <div class="yui-u">
+          <div class="portlet" id="sharing-information">
+            <h3>Sharing Information</h3>
+            <p tal:condition="not:view/is_sharing">
+              This project series is not sharing translations with
+              an Ubuntu source package.
+            </p>
+            <p tal:condition="view/is_sharing">
+              This project series is sharing translations with
+              <a tal:replace="structure view/sharing_sourcepackage/fmt:link">
+                package name
+              </a>.
+            </p>
+          </div>
           <div class="portlet">
             <h3>Administration</h3>
             <p>Translation files that are waiting to be imported are shown in

=== modified file 'lib/lp/translations/templates/sourcepackage-translations.pt'
--- lib/lp/translations/templates/sourcepackage-translations.pt	2010-12-21 15:13:17 +0000
+++ lib/lp/translations/templates/sourcepackage-translations.pt	2011-02-25 12:10:00 +0000
@@ -26,6 +26,20 @@
           </div>
         </div>
         <div class="yui-u">
+          <div class="portlet" id="sharing-information">
+            <h3>Sharing Information</h3>
+            <p tal:condition="not:view/is_sharing">
+              This source package is not sharing translations with
+              an upstream project.
+            </p>
+            <p tal:condition="view/is_sharing">
+              This source package is sharing translations with
+              <a tal:replace="structure view/sharing_productseries/fmt:link">
+                project series name
+              </a>.
+            </p>
+          </div>
+
           <div class="portlet">
             <h3>Administration</h3>
             <p>Translation files that are waiting to be imported are shown in

=== modified file 'lib/lp/translations/utilities/translationsharinginfo.py'
--- lib/lp/translations/utilities/translationsharinginfo.py	2011-02-23 11:53:06 +0000
+++ lib/lp/translations/utilities/translationsharinginfo.py	2011-02-25 12:10:00 +0000
@@ -152,9 +152,10 @@
 
 def get_ubuntu_sharing_info(productseries, templatename=None):
     """Return a list of sharing information for the given target."""
-    for result in find_ubuntu_sharing_info(productseries, templatename):
-        distroseries, sourcepackagename, templatename = result
-        yield (SourcePackage(sourcepackagename, distroseries), templatename)
+    return [
+        (SourcePackage(packagename, series), name)
+        for series, packagename, name in find_ubuntu_sharing_info(
+            productseries, templatename)]
 
 
 def get_upstream_sharing_info(sourcepackage, templatename=None):


Follow ups