Skip to content

Commit

Permalink
[bug 773017] Tweak the l10n dashboard queries.
Browse files Browse the repository at this point in the history
* Exclude redirects in the overview section
* Include translations without approved revisions in the Untranslated section
  • Loading branch information
rlr committed Mar 27, 2013
1 parent 4a5fc2f commit 7762caa
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
12 changes: 10 additions & 2 deletions apps/dashboards/readouts.py
Expand Up @@ -21,7 +21,7 @@
from sumo.redis_utils import redis_client, RedisError
from wiki.models import Document
from wiki.config import (MEDIUM_SIGNIFICANCE, MAJOR_SIGNIFICANCE,
TYPO_SIGNIFICANCE)
TYPO_SIGNIFICANCE, REDIRECT_HTML)


log = logging.getLogger('k.dashboards.readouts')
Expand Down Expand Up @@ -169,6 +169,8 @@ def single_result(sql, params):
current_revision__isnull=False,
is_localizable=True,
latest_localizable_revision__isnull=False)
total = total.exclude(
html__startswith=REDIRECT_HTML)

if product:
total = total.filter(products=product)
Expand Down Expand Up @@ -202,6 +204,7 @@ def single_result(sql, params):
'AND NOT transdoc.is_archived '
'AND engdoc.latest_localizable_revision_id IS NOT NULL '
'AND engdoc.is_localizable '
'AND engdoc.html NOT LIKE "<p>REDIRECT <a%%" '
'AND NOT EXISTS ' +
ANY_SIGNIFICANT_UPDATES)
translated_docs = single_result(
Expand Down Expand Up @@ -611,6 +614,10 @@ def _format_row(self, (eng_slug, eng_title, slug, title, significance,

class UntranslatedReadout(Readout):
title = _lazy(u'Untranslated')
description = _lazy(
u'This indicates there are no approved translations of these articles. '
'Some of the articles may have proposed translations waiting to be '
'reviewed and will appear in the Unreviewed Changes section as well.')
short_title = _lazy(u'Untranslated')
details_link_text = _lazy(u'All untranslated articles...')
slug = 'untranslated'
Expand Down Expand Up @@ -646,7 +653,8 @@ def _query_and_params(self, max):
'dashboards_wikidocumentvisits.period=%s '
+ extra_joins +
'WHERE '
'translated.id IS NULL AND engdoc.is_localizable AND '
'(translated.id IS NULL OR translated.current_revision_id IS NULL) '
'AND engdoc.is_localizable AND '
'engdoc.category in (10, 20, 60) AND '
'engdoc.locale=%s AND NOT engdoc.is_archived '
'AND wiki_revision.content NOT LIKE "REDIRECT%%" '
Expand Down
46 changes: 46 additions & 0 deletions apps/dashboards/tests/test_readouts.py
Expand Up @@ -43,6 +43,7 @@ def titles(self, locale=None, product=None):

class OverviewTests(TestCase):
"""Tests for Overview readout"""

def test_counting_unready_templates(self):
"""Templates without a ready-for-l10n rev shouldn't count in total."""
# Make a template with an approved but not-ready-for-l10n rev:
Expand Down Expand Up @@ -220,6 +221,25 @@ def test_by_product(self):
eq_(1, overview_rows('de', product=p)['all']['numerator'])
eq_(1, overview_rows('de', product=p)['all']['denominator'])

def test_redirects_are_ignored(self):
"""Verify that redirects aren't counted in the overview."""
t = translated_revision(is_approved=True, save=True)

eq_(1, overview_rows('de')['all']['numerator'])

# A redirect shouldn't affect any of the tests.
revision(document=document(title='A redirect',
is_localizable=True,
is_template=True,
save=True),
is_ready_for_localization=True,
is_approved=True,
content='REDIRECT [[An article]]',
save=True)

eq_(1, overview_rows('de')['all']['numerator'])



class UnreviewedChangesTests(ReadoutTestCase):
"""Tests for the Unreviewed Changes readout
Expand Down Expand Up @@ -703,3 +723,29 @@ def test_by_product(self):
# Add the product to the document, and verify it shows up.
d.products.add(p)
eq_(self.row(product=p)['title'], d.title)

def test_deferred_translation(self):
"""Verify a translation with only a deferred revision appears."""
d = document(title='Foo', save=True)
untranslated = revision(is_approved=True,
is_ready_for_localization=True,
document=d,
save=True)

# There should be 1.
eq_(1, len(self.titles(locale='es')))

translation = document(
parent=untranslated.document, locale='es', save=True)
deferred = revision(is_approved=False,
reviewed=datetime.now(),
document=translation,
save=True)

# There should still be 1.
eq_(1, len(self.titles(locale='es')))

# Mark that rev as approved and there should then be 0.
deferred.is_approved = True
deferred.save()
eq_(0, len(self.titles(locale='es')))

0 comments on commit 7762caa

Please sign in to comment.