зеркало из https://github.com/mozilla/kitsune.git
[Bug 858575] Readout for canned responses L10n.
This commit is contained in:
Родитель
d87fb331a3
Коммит
38502c336a
|
@ -22,7 +22,8 @@ from sumo.redis_utils import redis_client, RedisError
|
|||
from wiki.models import Document
|
||||
from wiki.config import (MEDIUM_SIGNIFICANCE, MAJOR_SIGNIFICANCE,
|
||||
TYPO_SIGNIFICANCE, REDIRECT_HTML,
|
||||
HOW_TO_CONTRIBUTE_CATEGORY, ADMINISTRATION_CATEGORY)
|
||||
HOW_TO_CONTRIBUTE_CATEGORY, ADMINISTRATION_CATEGORY,
|
||||
CANNED_RESPONSES_CATEGORY)
|
||||
|
||||
|
||||
log = logging.getLogger('k.dashboards.readouts')
|
||||
|
@ -31,7 +32,6 @@ log = logging.getLogger('k.dashboards.readouts')
|
|||
MOST_VIEWED = 1
|
||||
MOST_RECENT = 2
|
||||
|
||||
|
||||
# FROM clause for selecting most-visited translations:
|
||||
#
|
||||
# The "... EXISTS" bit in the transdoc left join prevents transdocs
|
||||
|
@ -377,9 +377,9 @@ class Readout(object):
|
|||
{'rows': rows, 'column3_label': self.column3_label,
|
||||
'column4_label': self.column4_label})
|
||||
|
||||
@staticmethod
|
||||
def should_show_to(user):
|
||||
"""Whether this readout should be shown to the user"""
|
||||
@classmethod
|
||||
def should_show_to(cls, request):
|
||||
"""Whether this readout should be shown on the request."""
|
||||
return True
|
||||
|
||||
# To override:
|
||||
|
@ -1143,11 +1143,60 @@ class NeedsChangesReadout(Readout):
|
|||
column4_data=comment)
|
||||
|
||||
|
||||
class CannedResponsesReadout(Readout):
|
||||
title = _lazy(u'Canned Responses')
|
||||
description = _lazy(u'Localization status of all canned responses')
|
||||
slug = 'canned-responses'
|
||||
details_link_text = _lazy(u'All canned responses articles...')
|
||||
|
||||
@classmethod
|
||||
def should_show_to(cls, request):
|
||||
return request.LANGUAGE_CODE in settings.AAQ_LANGUAGES
|
||||
|
||||
def _query_and_params(self, max):
|
||||
|
||||
if self.product:
|
||||
params = [self.locale, LAST_30_DAYS, self.product.id,
|
||||
CANNED_RESPONSES_CATEGORY,
|
||||
settings.WIKI_DEFAULT_LANGUAGE]
|
||||
extra_joins = PRODUCT_FILTER
|
||||
else:
|
||||
params = [self.locale, LAST_30_DAYS, CANNED_RESPONSES_CATEGORY,
|
||||
settings.WIKI_DEFAULT_LANGUAGE]
|
||||
extra_joins = ''
|
||||
|
||||
query = (
|
||||
'SELECT engdoc.slug, engdoc.title, '
|
||||
'transdoc.slug, transdoc.title, '
|
||||
'engvisits.visits, ' +
|
||||
MOST_SIGNIFICANT_CHANGE_READY_TO_TRANSLATE + ', ' +
|
||||
NEEDS_REVIEW +
|
||||
'FROM wiki_document engdoc '
|
||||
'LEFT JOIN wiki_document transdoc ON '
|
||||
'transdoc.parent_id=engdoc.id '
|
||||
'AND transdoc.locale=%s '
|
||||
'LEFT JOIN dashboards_wikidocumentvisits engvisits ON '
|
||||
'engdoc.id=engvisits.document_id '
|
||||
'AND engvisits.period=%s '
|
||||
+ extra_joins +
|
||||
'WHERE engdoc.category = %s '
|
||||
'AND engdoc.locale = %s '
|
||||
'AND NOT engdoc.is_archived '
|
||||
'ORDER BY engvisits.visits DESC '
|
||||
+ self._limit_clause(max)
|
||||
)
|
||||
|
||||
return query, params
|
||||
|
||||
def _format_row(self, row):
|
||||
return _format_row_with_out_of_dateness(self.locale, *row)
|
||||
|
||||
|
||||
# L10n Dashboard tables that have their own whole-page views:
|
||||
L10N_READOUTS = SortedDict((t.slug, t) for t in
|
||||
[MostVisitedTranslationsReadout, NavigationTranslationsReadout,
|
||||
TemplateTranslationsReadout, UntranslatedReadout,
|
||||
OutOfDateReadout, NeedingUpdatesReadout, UnreviewedReadout])
|
||||
TemplateTranslationsReadout, UntranslatedReadout, OutOfDateReadout,
|
||||
NeedingUpdatesReadout, UnreviewedReadout, CannedResponsesReadout])
|
||||
|
||||
# Contributors ones:
|
||||
CONTRIBUTOR_READOUTS = SortedDict((t.slug, t) for t in
|
||||
|
|
|
@ -14,12 +14,12 @@ from dashboards.readouts import (UnreviewedReadout, OutOfDateReadout,
|
|||
UntranslatedReadout,
|
||||
TemplateReadout,
|
||||
HowToContributeReadout,
|
||||
AdministrationReadout)
|
||||
AdministrationReadout, CannedResponsesReadout)
|
||||
from sumo.tests import TestCase
|
||||
from products.tests import product
|
||||
from wiki.config import (MAJOR_SIGNIFICANCE, MEDIUM_SIGNIFICANCE,
|
||||
TYPO_SIGNIFICANCE, HOW_TO_CONTRIBUTE_CATEGORY,
|
||||
ADMINISTRATION_CATEGORY)
|
||||
ADMINISTRATION_CATEGORY, CANNED_RESPONSES_CATEGORY)
|
||||
from wiki.tests import revision, translated_revision, document
|
||||
|
||||
|
||||
|
@ -42,7 +42,7 @@ class ReadoutTestCase(TestCase):
|
|||
def titles(self, locale=None, product=None):
|
||||
"""Return the titles shown by the Unreviewed Changes readout."""
|
||||
return [row['title'] for row in self.readout(
|
||||
MockRequest(), locale=locale, product=product).rows()]
|
||||
MockRequest(), locale=locale, product=product).rows()]
|
||||
|
||||
|
||||
class OverviewTests(TestCase):
|
||||
|
@ -244,7 +244,6 @@ class OverviewTests(TestCase):
|
|||
eq_(1, overview_rows('de')['all']['numerator'])
|
||||
|
||||
|
||||
|
||||
class UnreviewedChangesTests(ReadoutTestCase):
|
||||
"""Tests for the Unreviewed Changes readout
|
||||
|
||||
|
@ -856,3 +855,73 @@ class UntranslatedTests(ReadoutTestCase):
|
|||
deferred.is_approved = True
|
||||
deferred.save()
|
||||
eq_(0, len(self.titles(locale='es')))
|
||||
|
||||
|
||||
class CannedResponsesTests(ReadoutTestCase):
|
||||
readout = CannedResponsesReadout
|
||||
|
||||
def test_canned(self):
|
||||
"""Test the readout."""
|
||||
d = document(title='Foo', category=CANNED_RESPONSES_CATEGORY,
|
||||
save=True)
|
||||
revision(is_approved=True,
|
||||
is_ready_for_localization=True,
|
||||
document=d,
|
||||
save=True)
|
||||
|
||||
eq_(1, len(self.rows()))
|
||||
|
||||
def test_translation_state(self):
|
||||
eng_doc = document(category=CANNED_RESPONSES_CATEGORY, save=True)
|
||||
eng_rev = revision(is_approved=True, is_ready_for_localization=True,
|
||||
document=eng_doc, save=True)
|
||||
|
||||
eq_('untranslated', self.row()['status_class'])
|
||||
|
||||
# Now translate it, but don't approve
|
||||
de_doc = document(category=CANNED_RESPONSES_CATEGORY, parent=eng_doc,
|
||||
locale='de', save=True)
|
||||
de_rev = revision(is_approved=False, document=de_doc, based_on=eng_rev,
|
||||
save=True)
|
||||
|
||||
eq_('review', self.row()['status_class'])
|
||||
|
||||
# Approve it, so now every this is ok.
|
||||
de_rev.is_approved = True
|
||||
de_rev.save()
|
||||
|
||||
eq_('ok', self.row()['status_class'])
|
||||
|
||||
# Now update the parent, so it becomes minorly out of date
|
||||
revision(is_approved=True, is_ready_for_localization=True,
|
||||
document=eng_doc, significance=MEDIUM_SIGNIFICANCE,
|
||||
save=True)
|
||||
|
||||
eq_('update', self.row()['status_class'])
|
||||
|
||||
# Now update the parent, so it becomes majorly out of date
|
||||
revision(is_approved=True, is_ready_for_localization=True,
|
||||
document=eng_doc, significance=MAJOR_SIGNIFICANCE,
|
||||
save=True)
|
||||
|
||||
eq_('out-of-date', self.row()['status_class'])
|
||||
|
||||
|
||||
|
||||
def test_by_product(self):
|
||||
"""Test the product filtering of the readout."""
|
||||
p = product(title='Firefox', slug='firefox', save=True)
|
||||
d = document(title='Foo', category=CANNED_RESPONSES_CATEGORY,
|
||||
save=True)
|
||||
revision(is_approved=True,
|
||||
is_ready_for_localization=True,
|
||||
document=d,
|
||||
save=True)
|
||||
|
||||
# There shouldn't be any rows yet.
|
||||
eq_(0, len(self.rows(product=p)))
|
||||
|
||||
# Add the product to the document, and verify it shows up.
|
||||
d.products.add(p)
|
||||
eq_(1, len(self.rows(product=p)))
|
||||
eq_(self.row(product=p)['title'], d.title)
|
||||
|
|
|
@ -34,7 +34,7 @@ def render_readouts(request, readouts, template, locale=None, extra_data=None,
|
|||
data = {'readouts': SortedDict((slug, class_(request, locale=locale,
|
||||
product=product))
|
||||
for slug, class_ in readouts.iteritems()
|
||||
if class_.should_show_to(request.user)),
|
||||
if class_.should_show_to(request)),
|
||||
'default_locale': settings.WIKI_DEFAULT_LANGUAGE,
|
||||
'default_locale_name':
|
||||
LOCALES[settings.WIKI_DEFAULT_LANGUAGE].native,
|
||||
|
|
|
@ -99,28 +99,34 @@
|
|||
}
|
||||
|
||||
.update:after {
|
||||
content: '\25C6';
|
||||
content: '\25C6'; /* Diamond */
|
||||
color: #f8e687;
|
||||
font-size: 130%; /* Compromise between looking huge on Windows and tiny on the Mac. Using an explicit font-family avails not. */
|
||||
}
|
||||
|
||||
.out-of-date:after {
|
||||
content: '\25C6';
|
||||
content: '\25C6'; /* Diamond */
|
||||
color: orange;
|
||||
font-size: 130%;
|
||||
}
|
||||
|
||||
.untranslated:after {
|
||||
content: '\25B2';
|
||||
color: red;
|
||||
content: '\25B2'; /* Triangle */
|
||||
color: #f00;
|
||||
font-size: 120%;
|
||||
}
|
||||
|
||||
.ok:after {
|
||||
content: '\25CF';
|
||||
content: '\25CF'; /* Circle */
|
||||
color: #add575;
|
||||
font-size: 200%;
|
||||
}
|
||||
|
||||
.review:after {
|
||||
content: '\25A0'; /* Square */
|
||||
color: #7580d5;
|
||||
font-size: 200%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче