Code review comment for lp:~henninge/launchpad/bug-488765-oops-translations
- bug-488765-oops-translations
- Merge into devel
Revision history for this message
Henning Eggers (henninge) wrote : | # |
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> |
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' removeSecurityP roxy(translatab le), ProductSeries): proxy.isinstanc e here to avoid having to
>> + if not isinstance(
>
> You can use zope.security.
> remove the security proxy.
Cool, I didn't know about this.
> providedBy( translatable) , which
> Actually, you should use IProductSeries.
> 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' interfaces. product import IProductSet IProductSet) .getByName( ).getSeries( 'trunk' ) .interfaces. potemplate import IPOTemplateSet IPOTemplateSet) .getSubset( evotrunk, iscurrent=True) iscurrent = False open(product_ url) n_recommendatio n(admin_ browser)
>> +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.
>> + >>> evotrunk = getUtility(
>> + ... 'evolution'
>> + >>> from lp.translations
>> + >>> potemplates = getUtility(
>> + ... productseries=
>> + >>> for potemplate in potemplates:
>> + ... potemplate.
>> + >>> logout()
>> + >>> admin_browser.
>> + >>> print find_translatio
>> + 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.
> by_class( admin_browser. contents, 'notice') text(notice) translations/ templates/ product- translations. pt' translations/ templates/ product- translations. pt 2009-12-16 15:21:36 +0000 translations/ templates/ product- translations. pt 2010-01-15 07:41:14 +0000 slot="main" "uses_translati ons view/uses_ translations; "official_ rosetta context/ official_ rosetta; required: launchpad. TranslationsAdm in"> translation- help-links" > /help.launchpad .net/Translatio ns" top-portlet" > @@+portlet- not-using- launchpad" /> "python: not view.uses_ translations and official_rosetta">
>> +
>> +Instead a notice is displayed that the product has no translations.
>> +
>> + >>> notice = first_tag_
>> + >>> print extract_
>> + There are no translations for this project.
>>
>
>> === modified file 'lib/lp/
>> --- lib/lp/
>> +++ lib/lp/
>> @@ -14,7 +14,7 @@
>> </div>
>>
>> <div metal:fill-
>> - tal:define=
>> + tal:define=
>> admin_user context/
>> <div class="
>> <a href="https:/
>> @@ -23,26 +23,28 @@
>> </a>
>> <div></div><!-- to clear-up all floats -->
>> </div>
>> - <div class="
>> + <div class="top-portlet notice">
>> <tal:official_use replace="
>> structure
>> context/
>> + <div tal:condition=
>
> 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... ;-)
> translations "python: uses_translatio ns or admin_user"> primary_ translatable" > "python: official_ rosetta or admin_user">
>
>> + There are no translations for this project.
>> + </div>
>> </div>
>>
>> <tal:uses-
>> - condition=
>> - <tal:translatable define="target context/
>> + condition=
>
> 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