Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #701 from groovecoder/dash-filter-backend-810051
Browse files Browse the repository at this point in the history
fix bug 810051 - locale and user filters
  • Loading branch information
darkwing committed Nov 15, 2012
2 parents fc080b9 + fd861ef commit 43fbded
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 25 deletions.
3 changes: 2 additions & 1 deletion apps/dashboards/templates/dashboards/revisions.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ <h2>{{ _('Revision Diff') }}</h2>
// Create the autocomplete for user
$('#revision-dashboard-user').mozillaAutocomplete({
minLength: 3,
autocompleteUrl: '', // UPDATE WHEN THE SERVER SIDE IS COMPLETE
labelField: 'label',
autocompleteUrl: '{{ url('dashboards.user_lookup') }}',
onSelect: function(item, isSilent) {
// Do something upon selection
if(!isSilent) loadRecords();
Expand Down
6 changes: 3 additions & 3 deletions apps/dashboards/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

from dashboards.models import (WikiDocumentVisits, StatsException, THIS_WEEK,
StatsIOError)
from sumo.tests import TestCase
from devmo.tests import SkippedTestCase
from wiki.tests import document, revision


class DocumentVisitsTests(TestCase):
class DocumentVisitsTests(SkippedTestCase):
"""Tests for the WebTrends statistics gathering"""
fixtures = ['users.json']
fixtures = ['test_users.json']

@raises(StatsException)
def test_bad_json(self):
Expand Down
6 changes: 3 additions & 3 deletions apps/dashboards/tests/test_readouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from functools import partial

from dashboards.readouts import UnreviewedReadout
from sumo.tests import TestCase
from devmo.tests import SkippedTestCase
from wiki.tests import revision, translated_revision


Expand All @@ -14,15 +14,15 @@ class MockRequest(object):
locale = NON_DEFAULT_LOCALE


class UnreviewedChangesTests(TestCase):
class UnreviewedChangesTests(SkippedTestCase):
"""Tests for the Unreviewed Changes readout
I'm not trying to cover every slice of the Venn diagram--just the tricky
bits.
"""

fixtures = ['users.json']
fixtures = ['test_users.json']

@staticmethod
def titles():
Expand Down
8 changes: 4 additions & 4 deletions apps/dashboards/tests/test_templates.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from nose.tools import eq_
from pyquery import PyQuery as pq

from sumo.tests import TestCase
from devmo.tests import SkippedTestCase
from sumo.urlresolvers import reverse
from wiki.models import MAJOR_SIGNIFICANCE, MEDIUM_SIGNIFICANCE
from wiki.tests import revision, translated_revision


class LocalizationDashTests(TestCase):
class LocalizationDashTests(SkippedTestCase):
"""Tests for the Localization Dashboard.
The L10n Dash shares a lot of code with the Contributor Dash, so this also
Expand All @@ -16,7 +16,7 @@ class LocalizationDashTests(TestCase):
"""

fixtures = ['users.json']
fixtures = ['test_users.json']

@staticmethod
def _assert_readout_contains(doc, slug, contents):
Expand Down Expand Up @@ -82,7 +82,7 @@ def test_untranslated_detail(self):
self.assertContains(response, untranslated.document.title)


class MobileHomeTestCase(TestCase):
class MobileHomeTestCase(SkippedTestCase):
def test_top_text(self):
response = self.client.get(reverse('home.mobile'), follow=True)
self.assertContains(response, 'Firefox Help for Mobile')
Expand Down
55 changes: 54 additions & 1 deletion apps/dashboards/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from nose.tools import eq_
import json

from nose.plugins.attrib import attr
from nose.tools import eq_, ok_

from waffle.models import Flag

from dashboards.readouts import CONTRIBUTOR_READOUTS
from sumo.tests import TestCase
Expand Down Expand Up @@ -28,3 +33,51 @@ def test_detail_view(self):
args=[CONTRIBUTOR_READOUTS[CONTRIBUTOR_READOUTS.keys()[0]].slug],
locale='en-US'))
eq_(200, response.status_code)


class RevisionsDashTest(TestCase):
fixtures = ['test_users.json', 'wiki/documents.json']

def setUp(self):
super(RevisionsDashTest, self).setUp()
self.dashboard_flag = Flag.objects.create(name='revisions_dashboard',
everyone=True)

@attr('dashboards')
def test_main_view(self):
response = self.client.get(reverse('dashboards.revisions',
locale='en-US'))
eq_(200, response.status_code)
ok_('text/html' in response['Content-Type'])
ok_('dashboards/revisions.html' in
[template.name for template in response.template])

@attr('dashboards')
def test_ajax_context_and_template(self):
response = self.client.get(reverse('dashboards.revisions',
locale='en-US'),
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
eq_(200, response.status_code)
ok_('revisions' in response.context)
ok_('total_records' in response.context)
eq_('dashboards/revisions.json', response.template.name)
eq_('json', response['Content-Type'])

@attr('dashboards')
def test_locale_filter(self):
url = reverse('dashboards.revisions', locale='fr')
response = self.client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
eq_(200, response.status_code)
revisions = json.loads(response.content)
ok_(['fr' in rev['doc_url'] for rev in revisions['aaData']])
ok_(['en-US' not in rev['doc_url'] for rev in revisions['aaData']])

@attr('dashboards')
def test_creator_filter(self):
url = reverse('dashboards.revisions',
locale='en-US') + '?user=testuser'
response = self.client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
eq_(200, response.status_code)
revisions = json.loads(response.content)
ok_(['testuser' == rev['creator'] for rev in revisions['aaData']])
ok_(['testuser2' != rev['creator'] for rev in revisions['aaData']])
1 change: 1 addition & 0 deletions apps/dashboards/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# url(r'^home$', 'home', name='home'),
url(r'^mobile$', 'mobile', name='home.mobile'),
url(r'^dashboards/revisions$', 'revisions', name='dashboards.revisions'),
url(r'^dashboards/user_lookup$', 'user_lookup', name='dashboards.user_lookup'),
url(r'^localization$', 'localization', name='dashboards.localization'),
url(r'^contributors$', 'contributors', name='dashboards.contributors'),
url(r'^wiki-rows/(?P<readout_slug>[^/]+)', 'wiki_rows',
Expand Down
42 changes: 39 additions & 3 deletions apps/dashboards/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import json
import logging

from functools import partial

from django.conf import settings
from django.contrib.auth.models import User
from django.http import Http404, HttpResponseRedirect, HttpResponse
from django.utils.datastructures import SortedDict
from django.views.decorators.http import require_GET
Expand Down Expand Up @@ -133,15 +137,47 @@ def contributors(request):
def revisions(request):
"""Dashboard for reviewing revisions"""
if request.is_ajax():
username = request.GET.get('user', None)
locale = request.GET.get('locale', None)

display_start = int(request.GET.get('iDisplayStart', 0))
revisions = Revision.objects.select_related('creator').all().order_by('-created')[display_start:display_start+PAGE_SIZE]

revisions = (Revision.objects.select_related('creator').all()
.order_by('-created'))
# apply filters, limits, and pages
if username:
revisions = (revisions
.filter(creator__username__startswith=username))
if locale:
revisions = revisions.filter(document__locale=locale)

total = revisions.count()
revisions = revisions[display_start:display_start + PAGE_SIZE]

context = {'revisions': revisions,
'total_records': Revision.objects.count()}
'total_records': total}
return jingo.render(request, 'dashboards/revisions.json',
context, mimetype="json")
context, content_type="application/json; charset=utf-8")
return jingo.render(request, 'dashboards/revisions.html')


@require_GET
@waffle_flag('revisions_dashboard')
def user_lookup(request):
"""Returns partial username matches"""
if request.is_ajax():
user = request.GET.get('user', '')
matches = User.objects.filter(username__startswith=user)

userlist = []
for u in matches:
userlist.append({'label': u.username})

data = json.dumps(userlist)
return HttpResponse(data,
content_type="application/json; charset=utf-8")


@require_GET
def wiki_rows(request, readout_slug):
"""Return the table contents HTML for the given readout and mode."""
Expand Down
16 changes: 8 additions & 8 deletions apps/wiki/fixtures/wiki/documents.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@
"content": "ceci n'est pas une pipe\r\n\r\nmon dieu!",
"significance": 30,
"keywords": "boulot",
"reviewer": 118533,
"reviewer": 10,
"document": 4,
"creator": 118533
"creator": 7
}
},
{
Expand All @@ -94,9 +94,9 @@
"content": "the keyword video only appears in the body of this article",
"significance": 10,
"keywords": "barfoo",
"reviewer": 118533,
"reviewer": 10,
"document": 1,
"creator": 118533
"creator": 8
}
},
{
Expand All @@ -111,9 +111,9 @@
"content": "audio is in this <strong>but the word for tough things</strong> will be ignored",
"significance": 30,
"keywords": "ghosts",
"reviewer": 118533,
"reviewer": 10,
"document": 5,
"creator": 118533
"creator": 7
}
},
{
Expand All @@ -128,9 +128,9 @@
"content": "audio is in this <strong>but the word for tough things</strong> will be ignored",
"significance": 30,
"keywords": "ghosts",
"reviewer": 118533,
"reviewer": 10,
"document": 2,
"creator": 118533
"creator": 7
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ export FORCE_DB='yes sir'
# with-coverage excludes sphinx so it doesn't conflict with real builds.
if [[ $2 = 'with-coverage' ]]; then
# Add 'search' app back in, someday
coverage run manage.py test actioncounters contentflagging dekicompat demos devmo landing users wiki -v 2 --noinput
coverage run manage.py test actioncounters contentflagging dashboards demos devmo landing users wiki -v 2 --noinput
coverage xml $(find apps lib -name '*.py')
else
# Add 'search' app back in, someday
python manage.py test actioncounters contentflagging dekicompat demos devmo landing users wiki -v 2 --noinput
python manage.py test actioncounters contentflagging dashboards demos devmo landing users wiki -v 2 --noinput
fi

echo 'shazam!'

0 comments on commit 43fbded

Please sign in to comment.