Skip to content

Commit

Permalink
[bug 624541] [bug 618808] Add Most-Visited Articles readout to L10n a…
Browse files Browse the repository at this point in the history
…nd Contributor Dashboards, and link row labels in Overview readout properly.

Chowse and I decided to forgo the All link since the original intent was to link to in-page anchors and there isn't an All readout. Most-Visited serves that purpose, and there's no point linking to it twice. (We considered linking "All" to the detail view but decided against it.)
  • Loading branch information
erikrose committed Jan 13, 2011
1 parent cc27939 commit 50f9ba7
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 17 deletions.
132 changes: 121 additions & 11 deletions apps/dashboards/readouts.py
Expand Up @@ -7,7 +7,7 @@
import jingo
from tower import ugettext as _, ugettext_lazy as _lazy

from dashboards.models import THIS_WEEK
from dashboards.models import THIS_WEEK, ALL_TIME, PERIODS
from sumo.urlresolvers import reverse
from wiki.models import Document, MEDIUM_SIGNIFICANCE, MAJOR_SIGNIFICANCE

Expand Down Expand Up @@ -55,7 +55,8 @@ def percent_or_100(num, denom):
(locale, THIS_WEEK, TOP_N))
popular_translated = cursor.fetchone()[0]

return [dict(title=_('Most-Viewed Articles'),
return [dict(title=_('Most-Visited Articles'),
url='#' + MostVisitedTranslationsReadout.slug,
numerator=popular_translated, denominator=TOP_N,
percent=percent_or_100(popular_translated, TOP_N),
description=_('These are the top %s most visited English '
Expand All @@ -76,10 +77,11 @@ class Readout(object):
Describing these as atoms gives us the whole-page details views for free.
"""
#title = _lazy(u'Title of Readout')
#short_title= = _lazy(u'Short Title of Readout for In-Page Links')
#slug = 'URL slug for detail page'
#details_link_text = _lazy(u'All articles from this readout...')
# title = _lazy(u'Title of Readout')
# short_title= = _lazy(u'Short Title of Readout for In-Page Links')
# slug = 'URL slug for detail page'
# details_link_text = _lazy(u'All articles from this readout...')
column3_label = _lazy(u'Visits this week')
column4_label = _lazy(u'Status')
modes = [(MOST_VIEWED, _lazy('Most Viewed')),
(MOST_RECENT, _lazy('Most Recent'))]
Expand Down Expand Up @@ -124,7 +126,8 @@ def render(self, max_rows=None):
return jingo.render_to_string(
self.request,
'dashboards/includes/kb_readout.html',
{'rows': rows, 'column4_label': self.column4_label})
{'rows': rows, 'column3_label': self.column3_label,
'column4_label': self.column4_label})

# To override:

Expand All @@ -148,6 +151,108 @@ def _limit_clause(max):
return ' LIMIT %i' % max if max else ''


class MostVisitedDefaultLanguageReadout(Readout):
title = _lazy(u'Most-Visited Articles')
# No short_title; the link to this one is hard-coded in Overview readout
details_link_text = _lazy(u'All knowledge base articles...')
slug = 'most-visited'
column3_label = _lazy(u'Visits')
modes = PERIODS
review_statuses = {
1: (_lazy(u'Review Needed'), 'wiki.document_revisions'),
0: (u'', '')}

def _query_and_params(self, max):
# Review Needed: link to /history.
return ('SELECT engdoc.slug, engdoc.title, '
'dashboards_wikidocumentvisits.visits, '
'count(engrev.document_id) '
'FROM wiki_document engdoc '
'LEFT JOIN dashboards_wikidocumentvisits ON '
'engdoc.id=dashboards_wikidocumentvisits.document_id '
'AND dashboards_wikidocumentvisits.period=%s '
'LEFT JOIN wiki_revision engrev ON '
'engrev.document_id=engdoc.id '
'AND engrev.reviewed IS NULL '
'AND engrev.id>engdoc.current_revision_id '
'WHERE engdoc.locale=%s '
'GROUP BY engdoc.id '
'ORDER BY dashboards_wikidocumentvisits.visits DESC, '
'engdoc.title ASC' + self._limit_clause(max),
(ALL_TIME if self.mode == ALL_TIME else THIS_WEEK, self.locale))

def _format_row(self, (slug, title, visits, num_unreviewed)):
needs_review = int(num_unreviewed > 0)
status, view_name = self.review_statuses[needs_review]
return (dict(title=title,
url=reverse('wiki.document', args=[slug],
locale=self.locale),
visits=visits,
status=status,
status_url=reverse(view_name, args=[slug],
locale=self.locale)
if view_name else ''))


class MostVisitedTranslationsReadout(MostVisitedDefaultLanguageReadout):
slug = 'most-visited-translations'

# L10n: Replace "English" with your language.
details_link_text = _lazy(u'All translations in English...')

significance_statuses = {
MEDIUM_SIGNIFICANCE: (_lazy(u'Update Needed'), 'wiki.edit_document'),
MAJOR_SIGNIFICANCE: (_lazy(u'Out of Date'), 'wiki.edit_document')}

def _query_and_params(self, max):
# Out of Date or Update Needed: link to /edit.
# Review Needed: link to /history.
# These match the behavior of the corresponding readouts.
return ('SELECT transdoc.slug, transdoc.title, '
'dashboards_wikidocumentvisits.visits, '
# The most significant approved change to the English article
# since the English revision the current translated revision is
# based on:
'(SELECT MAX(engrev.significance) '
'FROM wiki_revision engrev, wiki_revision transrev '
'WHERE engrev.is_approved '
'AND transrev.id=transdoc.current_revision_id '
'AND engrev.document_id=transdoc.parent_id '
'AND engrev.id>transrev.based_on_id '
'), '
# Whether there are any unreviewed revs of the translation made
# since the current one:
'(SELECT EXISTS '
'(SELECT * '
'FROM wiki_revision transrev '
'WHERE transrev.document_id=transdoc.id '
'AND transrev.reviewed IS NULL '
'AND transrev.id>transdoc.current_revision_id '
')'
') '
'FROM wiki_document transdoc '
'LEFT JOIN dashboards_wikidocumentvisits ON transdoc.parent_id='
'dashboards_wikidocumentvisits.document_id '
'AND dashboards_wikidocumentvisits.period=%s '
'WHERE transdoc.locale=%s '
'ORDER BY dashboards_wikidocumentvisits.visits DESC, '
'transdoc.title ASC' + self._limit_clause(max),
(ALL_TIME if self.mode == ALL_TIME else THIS_WEEK, self.locale))

def _format_row(self, (slug, title, visits, significance, needs_review)):
status, view_name = self.significance_statuses.get(
significance,
self.review_statuses[needs_review])
return (dict(title=title,
url=reverse('wiki.document', args=[slug],
locale=self.locale),
visits=visits,
status=status,
status_url=reverse(view_name, args=[slug],
locale=self.locale)
if view_name else ''))


class UntranslatedReadout(Readout):
title = _lazy(u'Untranslated Articles')
short_title = _lazy(u'Untranslated')
Expand Down Expand Up @@ -330,9 +435,14 @@ def _format_row(self, (slug, title, changed, users, visits)):


# L10n Dashboard tables that have their own whole-page views:
L10N_READOUTS = READOUTS = SortedDict((t.slug, t) for t in
[UntranslatedReadout, OutOfDateReadout, NeedingUpdatesReadout,
UnreviewedReadout])
L10N_READOUTS = SortedDict((t.slug, t) for t in
[MostVisitedTranslationsReadout, UntranslatedReadout, OutOfDateReadout,
NeedingUpdatesReadout, UnreviewedReadout])

# Contributors ones:
CONTRIBUTOR_READOUTS = dict((t.slug, t) for t in [UnreviewedReadout])
CONTRIBUTOR_READOUTS = SortedDict((t.slug, t) for t in
[MostVisitedDefaultLanguageReadout, UnreviewedReadout])

# All:
READOUTS = L10N_READOUTS.copy()
READOUTS.update(CONTRIBUTOR_READOUTS)
4 changes: 3 additions & 1 deletion apps/dashboards/templates/dashboards/contributors.html
Expand Up @@ -29,7 +29,9 @@ <h1>{{ title }}</h1>
</div>
{% endif %}

{{ print_readout(readouts['unreviewed'], 'dashboards.contributors_detail', locale=default_locale) }}
{% for readout in readouts.itervalues() %}
{{ print_readout(readout, 'dashboards.contributors_detail', locale=default_locale) }}
{% endfor %}
</article>
{% endblock %}

Expand Down
10 changes: 8 additions & 2 deletions apps/dashboards/templates/dashboards/includes/kb_readout.html
Expand Up @@ -3,7 +3,7 @@
<tr>
<th>{{ _('Article') }}</th>
<th></th>
<th>{{ _('Visits this week') }}</th>
<th>{{ column3_label }}</th>
<th>{{ column4_label }}</th>
</tr>
{% endif %}
Expand All @@ -23,7 +23,13 @@
<div class="absolute-graph" style="width: {{ row.percent }}%"></div>
</td>
<td>
{{ row.updated|timesince }}
{% if row.updated is defined %}
{{ row.updated|timesince }}
{% else %}
{% if row.status %}
<a href="{{ row.status_url }}">{{ row.status }}</a>
{% endif %}
{% endif %}
</td>
</tr>
{% endfor %}
2 changes: 1 addition & 1 deletion apps/dashboards/templates/dashboards/includes/macros.html
@@ -1,6 +1,6 @@
{% macro print_readout(readout, detail_view_name, locale=None) %}
<details class="h2" open="open">
<summary style="display: inline">
<summary class="with-mode-selectors">
<a id="{{ readout.slug }}">{{ readout.title }}</a>
</summary>
<ul class="readout-modes" data-slug="{{ readout.slug }}">
Expand Down
8 changes: 7 additions & 1 deletion apps/dashboards/templates/dashboards/localization.html
Expand Up @@ -32,7 +32,13 @@ <h1>{{ title }}</h1>
<table class="overview">
{% for row in overview_rows() %}
<tr>
<td><a href="#">{{ row.title }}</a></td>
<td>
{% if row.url %}
<a href="{{ row.url }}">{{ row.title }}</a>
{% else %}
{{ row.title }}
{% endif %}
</td>
<td>
{{ number(row.numerator) }}
<div class="denominator">of {{ number(row.denominator) }}</div>
Expand Down
7 changes: 6 additions & 1 deletion media/css/dashboards.css
Expand Up @@ -112,11 +112,12 @@
.dashboards ul.readout-modes li {
background: #cde6f5;
border-radius: 10px;
cursor: pointer;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
list-style: none;
padding: 3px 10px;
margin: 0 1px;
padding: 3px 10px;
vertical-align: -6px;
}

Expand All @@ -139,3 +140,7 @@
.dashboards-detail h1 {
display: inline-block;
}

.dashboards summary.with-mode-selectors {
display: inline;
}

0 comments on commit 50f9ba7

Please sign in to comment.