Merge lp:~jcsackett/launchpad/broken-links-person-translations into lp:launchpad

Proposed by j.c.sackett
Status: Merged
Approved by: Curtis Hovey
Approved revision: no longer in the source branch.
Merged at revision: 16217
Proposed branch: lp:~jcsackett/launchpad/broken-links-person-translations
Merge into: lp:launchpad
Diff against target: 63 lines (+15/-2)
3 files modified
lib/lp/translations/browser/person.py (+6/-1)
lib/lp/translations/browser/tests/test_persontranslationview.py (+7/-0)
lib/lp/translations/model/translationsperson.py (+2/-1)
To merge this branch: bzr merge lp:~jcsackett/launchpad/broken-links-person-translations
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+131199@code.launchpad.net

Commit message

Filters products not using translations out of the recent history in Person:+translations to prevent 404 links.

Description of the change

Summary
=======
Products which have translations but are no longer setup to use translations
create 404 links in Person+translations in the recent activity display.

The initial assumption was that the translation_history query on
TranslationPerson was bad, and should do the filtering. However, this query is
used in places where the absolute history is necessary (e.g. showing if a
person has *ever* done a translation) and the number of joins necessary to
filter at the level poses a performance risk with large histories.

The view for Person+translations has a method, `recent_history` which already
filters the translation_history to weed out inactive projects. This method
should also filter out projects no longer using translations.

Preimp
======
Spoke with Curtis Hovey.

Implementation
==============
`recent_activity`'s filtering method, `is_active`, now checks for
`product.translations_usage == ServiceUsage.LAUNCHPAD` as well as
`product.active`.

The test for recent_activity now includes a pofile, which should be excluded,
that is linked to a product where translations_usage is
ServiceUsage.NOT_APPLICABLE.

Tests
=====
bin/test -vvct test_recent_translation_activity

QA
==
Ensure that the page linked in the bug no longer has 404ing links.

LoC
===
I have ~400 LoC in credit.

Lint
====

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/translations/browser/tests/test_persontranslationview.py
  lib/lp/translations/model/translationsperson.py
  lib/lp/translations/browser/person.py

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

Thank you.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/translations/browser/person.py'
2--- lib/lp/translations/browser/person.py 2012-10-29 06:13:44 +0000
3+++ lib/lp/translations/browser/person.py 2012-10-30 15:57:24 +0000
4@@ -33,6 +33,7 @@
5 custom_widget,
6 LaunchpadFormView,
7 )
8+from lp.app.enums import ServiceUsage
9 from lp.app.widgets.itemswidgets import LaunchpadRadioWidget
10 from lp.registry.interfaces.sourcepackage import ISourcePackage
11 from lp.services.propertycache import cachedproperty
12@@ -231,7 +232,11 @@
13 if potemplate is None:
14 return True
15 product = potemplate.product
16- return product is None or product.active
17+ product_is_active = (
18+ product is None or (
19+ product.active and
20+ product.translations_usage == ServiceUsage.LAUNCHPAD))
21+ return product_is_active
22
23 active_entries = (entry for entry in all_entries if is_active(entry))
24 return [ActivityDescriptor(self.context, entry)
25
26=== modified file 'lib/lp/translations/browser/tests/test_persontranslationview.py'
27--- lib/lp/translations/browser/tests/test_persontranslationview.py 2012-10-29 06:13:44 +0000
28+++ lib/lp/translations/browser/tests/test_persontranslationview.py 2012-10-30 15:57:24 +0000
29@@ -7,6 +7,7 @@
30
31 from zope.security.proxy import removeSecurityProxy
32
33+from lp.app.enums import ServiceUsage
34 from lp.services.webapp import canonical_url
35 from lp.services.webapp.servers import LaunchpadTestRequest
36 from lp.testing import (
37@@ -189,6 +190,12 @@
38 # and make one which has not been worked on (will be excluded)
39 self._makePOFiles(1, previously_worked_on=False)
40
41+ # and make one which has a product no longer using translations (will
42+ # be excluded)
43+ [pofile] = self._makePOFiles(1, previously_worked_on=True)
44+ naked_product = removeSecurityProxy(pofile.potemplate.product)
45+ naked_product.translations_usage = ServiceUsage.NOT_APPLICABLE
46+
47 pofiles_worked_on = self._makePOFiles(11, previously_worked_on=True)
48
49 # the expected results
50
51=== modified file 'lib/lp/translations/model/translationsperson.py'
52--- lib/lp/translations/model/translationsperson.py 2012-10-29 06:13:44 +0000
53+++ lib/lp/translations/model/translationsperson.py 2012-10-30 15:57:24 +0000
54@@ -74,7 +74,8 @@
55
56 def getTranslationHistory(self, no_older_than=None):
57 """See `ITranslationsPerson`."""
58- conditions = (POFileTranslator.person == self.person)
59+ conditions = And(
60+ POFileTranslator.person == self.person)
61 if no_older_than is not None:
62 conditions = And(
63 conditions,