Code review comment for lp:~henninge/launchpad/bug-488765-oops-translations

Revision history for this message
Henning Eggers (henninge) wrote :

Am 15.01.2010 13:06, Guilherme Salgado schrieb:
> Review: Needs Fixing
> Hi Henning,
>
> I have just a few suggestions to improve this branch a bit.

Cool, thanks for doing the review.

>> === modified file 'lib/lp/translations/browser/product.py'
>> + if not isinstance(removeSecurityProxy(translatable), ProductSeries):
>
> You can use zope.security.proxy.isinstance here to avoid having to
> remove the security proxy.

Cool, I didn't know about this.

>
> Actually, you should use IProductSeries.providedBy(translatable), which
> would allow you to not import ProductSeries here, as that must not be
> done. I wonder why the import fascist doesn't emit a warning about this
> import...

Yes, you are right on both accounts. I changed it to use providedBy.

>> === modified file 'lib/lp/translations/stories/standalone/xx-product-translations.txt'
>> +A series is not translatable if all templates are disabled. We need to jump
>> +through some hoops to create that situation.
>> +
>> + >>> login('<email address hidden>')
>> + >>> from zope.component import getUtility
>> + >>> from lp.registry.interfaces.product import IProductSet
>> + >>> evotrunk = getUtility(IProductSet).getByName(
>> + ... 'evolution').getSeries('trunk')
>> + >>> from lp.translations.interfaces.potemplate import IPOTemplateSet
>> + >>> potemplates = getUtility(IPOTemplateSet).getSubset(
>> + ... productseries=evotrunk, iscurrent=True)
>> + >>> for potemplate in potemplates:
>> + ... potemplate.iscurrent = False
>> + >>> logout()
>> + >>> admin_browser.open(product_url)
>> + >>> print find_translation_recommendation(admin_browser)
>> + None
>
> I think it'd be nice to show here that the product has a translatable
> source package and explain that is only in that case that we don't show
> recommendations. It's also important to do that because the test
> assumes there's a translatable source package associated to evolution
> (as you described in the cover letter), but the test itself doesn't make
> it clear nor does it assert that.

Ah, that is not quite right. We don't show the recommendation even if
there is source package because atm we cannot treat a source package
like a product series in this respect. That will have to be fixed in
another branch (bug 507534).

I added a test that shows that the series has translatable source
package. This situation is what triggered the oops that this branch is
fixing but the display of recommendations is independent of a
translatable source package.

>
>> +
>> +Instead a notice is displayed that the product has no translations.
>> +
>> + >>> notice = first_tag_by_class(admin_browser.contents, 'notice')
>> + >>> print extract_text(notice)
>> + There are no translations for this project.
>>
>
>> === modified file 'lib/lp/translations/templates/product-translations.pt'
>> --- lib/lp/translations/templates/product-translations.pt 2009-12-16 15:21:36 +0000
>> +++ lib/lp/translations/templates/product-translations.pt 2010-01-15 07:41:14 +0000
>> @@ -14,7 +14,7 @@
>> </div>
>>
>> <div metal:fill-slot="main"
>> - tal:define="uses_translations view/uses_translations;
>> + tal:define="official_rosetta context/official_rosetta;
>> admin_user context/required:launchpad.TranslationsAdmin">
>> <div class="translation-help-links">
>> <a href="https://help.launchpad.net/Translations"
>> @@ -23,26 +23,28 @@
>> </a>
>> <div></div><!-- to clear-up all floats -->
>> </div>
>> - <div class="top-portlet">
>> + <div class="top-portlet notice">
>> <tal:official_use replace="
>> structure
>> context/@@+portlet-not-using-launchpad"/>
>> + <div tal:condition="python:not view.uses_translations and official_rosetta">
>
> Using python: in tal is strongly discouraged, and in this case we can
> easily use a view property.

Yes, I don't like that either. I was tempted by the easiness of the
way... ;-)

>
>
>> + There are no translations for this project.
>> + </div>
>> </div>
>>
>> <tal:uses-translations
>> - condition="python:uses_translations or admin_user">
>> - <tal:translatable define="target context/primary_translatable">
>> + condition="python:official_rosetta or admin_user">
>
> This could also be moved into a view property, for bonus points. :)

I want bonus points!!!

All done, thanks for helping me improve this branch! The incremental
diff is attached.

Henning

1=== modified file 'lib/lp/translations/browser/product.py'
2--- lib/lp/translations/browser/product.py 2010-01-15 07:39:43 +0000
3+++ lib/lp/translations/browser/product.py 2010-01-15 14:37:06 +0000
4@@ -11,14 +11,12 @@
5 'ProductView',
6 ]
7
8-from zope.security.proxy import removeSecurityProxy
9-
10 from canonical.cachedproperty import cachedproperty
11 from canonical.launchpad.webapp import (
12 LaunchpadView, Link, canonical_url, enabled_with_permission)
13+from canonical.launchpad.webapp.authorization import check_permission
14 from canonical.launchpad.webapp.menu import NavigationMenu
15-from lp.registry.interfaces.product import IProduct
16-from lp.registry.model.productseries import ProductSeries
17+from lp.registry.interfaces.product import IProduct, IProductSeries
18 from lp.registry.browser.product import ProductEditView
19 from lp.translations.browser.translations import TranslationsMixin
20
21@@ -85,7 +83,20 @@
22 @cachedproperty
23 def uses_translations(self):
24 """Whether this product has translatable templates."""
25- return (self.context.official_rosetta and self.primary_translatable)
26+ return (self.context.official_rosetta and
27+ self.primary_translatable is not None)
28+
29+ @cachedproperty
30+ def no_translations_available(self):
31+ """Has no translation templates but does support translations."""
32+ return (self.context.official_rosetta and
33+ self.primary_translatable is None)
34+
35+ @cachedproperty
36+ def show_page_content(self):
37+ """Whether the main content of the page should be shown."""
38+ return (self.context.official_rosetta or
39+ check_permission("launchpad.TranslationsAdmin", self.context))
40
41 @cachedproperty
42 def primary_translatable(self):
43@@ -93,7 +104,7 @@
44 """
45 translatable = self.context.primary_translatable
46
47- if not isinstance(removeSecurityProxy(translatable), ProductSeries):
48+ if not IProductSeries.providedBy(translatable):
49 return None
50
51 return translatable
52
53=== modified file 'lib/lp/translations/stories/standalone/xx-product-translations.txt'
54--- lib/lp/translations/stories/standalone/xx-product-translations.txt 2010-01-14 17:03:56 +0000
55+++ lib/lp/translations/stories/standalone/xx-product-translations.txt 2010-01-15 13:56:37 +0000
56@@ -222,6 +222,15 @@
57 >>> print find_translation_recommendation(admin_browser)
58 None
59
60+At the moment, translatable source packages are not recommended, although
61+the product is linked to one.
62+
63+ >>> source_package = find_tag_by_id(
64+ ... admin_browser.contents, 'portlet-translatable-packages')
65+ >>> print extract_text(source_package)
66+ All translatable distribution packages
67+ “evolution” source package in Hoary
68+
69 Instead a notice is displayed that the product has no translations.
70
71 >>> notice = first_tag_by_class(admin_browser.contents, 'notice')
72
73=== modified file 'lib/lp/translations/templates/product-translations.pt'
74--- lib/lp/translations/templates/product-translations.pt 2010-01-15 07:39:43 +0000
75+++ lib/lp/translations/templates/product-translations.pt 2010-01-15 14:39:59 +0000
76@@ -14,8 +14,7 @@
77 </div>
78
79 <div metal:fill-slot="main"
80- tal:define="official_rosetta context/official_rosetta;
81- admin_user context/required:launchpad.TranslationsAdmin">
82+ tal:define="admin_user context/required:launchpad.TranslationsAdmin">
83 <div class="translation-help-links">
84 <a href="https://help.launchpad.net/Translations"
85 id="link-to-translations-help"
86@@ -27,13 +26,12 @@
87 <tal:official_use replace="
88 structure
89 context/@@+portlet-not-using-launchpad"/>
90- <div tal:condition="python:not view.uses_translations and official_rosetta">
91+ <div tal:condition="view/no_translations_available">
92 There are no translations for this project.
93 </div>
94 </div>
95
96- <tal:uses-translations
97- condition="python:official_rosetta or admin_user">
98+ <tal:page_content condition="view/show_page_content">
99 <tal:translatable define="target view/primary_translatable">
100
101 <div class="yui-g">
102@@ -100,7 +98,7 @@
103 <div tal:replace="structure context/@@+rosetta-status-legend" />
104 </div>
105 </tal:translatable>
106- </tal:uses-translations>
107+ </tal:page_content>
108 </div>
109 </body>
110 </html>

« Back to merge proposal