diff --git a/apps/editors/helpers.py b/apps/editors/helpers.py index e4ccc43a40..dcde4623d7 100644 --- a/apps/editors/helpers.py +++ b/apps/editors/helpers.py @@ -42,8 +42,10 @@ class ViewEditorQueueTable(tables.ModelTable): 'version_max', 'version_min', 'version_apps'] def render_addon_name(self, row): - return u'%s' % (reverse('editors.review', - args=[row.version_id]), + url = '%s?num=%s' % (reverse('editors.review', args=[row.version_id]), + self.item_number) + self.item_number += 1 + return u'%s' % (url, jinja2.escape(row.addon_name)) def render_addon_type_id(self, row): @@ -88,6 +90,9 @@ class ViewEditorQueueTable(tables.ModelTable): else: return '' + def set_page(self, page): + self.item_number = page.start_index() + def _explode_concat(self, value): """Returns list of IDs in a MySQL GROUP_CONCAT(field) result.""" return [int(i) for i in value.split(',')] diff --git a/apps/editors/tests/test_helpers.py b/apps/editors/tests/test_helpers.py index 864f53d1a4..de57f41bf9 100644 --- a/apps/editors/tests/test_helpers.py +++ b/apps/editors/tests/test_helpers.py @@ -20,11 +20,15 @@ class TestViewEditorQueueTable(test_utils.TestCase): def test_addon_name(self): row = Mock() + page = Mock() + page.start_index = Mock() + page.start_index.return_value = 1 row.addon_name = 'フォクすけといっしょ 0.12'.decode('utf8') row.version_id = 1234 + self.table.set_page(page) a = pq(self.table.render_addon_name(row)) eq_(a.attr('href'), - reverse('editors.review', args=[row.version_id])) + reverse('editors.review', args=[row.version_id]) + '?num=1') eq_(a.text(), row.addon_name) def test_addon_type_id(self): diff --git a/apps/editors/tests/test_views.py b/apps/editors/tests/test_views.py index 9b8addc529..7ae9790e2c 100644 --- a/apps/editors/tests/test_views.py +++ b/apps/editors/tests/test_views.py @@ -29,6 +29,12 @@ class TestPendingQueue(EditorTest): r = self.client.get(reverse('editors.queue_pending')) eq_(r.status_code, 403) + def test_invalid_page(self): + r = self.client.get(reverse('editors.queue_pending'), + data={'page':999}) + eq_(r.status_code, 200) + eq_(r.context['page'].number, 1) + def test_grid(self): r = self.client.get(reverse('editors.queue_pending')) eq_(r.status_code, 200) @@ -41,6 +47,25 @@ class TestPendingQueue(EditorTest): eq_(doc('div.section table tr th:eq(5)').text(), u'Additional Information') # Smoke test the grid. More tests in test_helpers.py - eq_(doc('div.section table tr td:eq(0)').text(), u'Converter 1.0.0') - eq_(doc('div.section table tr td a:eq(0)').attr('href'), - reverse('editors.review', args=['118409'])) + row = doc('div.section table tr:eq(1)') + eq_(doc('td:eq(0)', row).text(), u'Converter 1.0.0') + eq_(doc('td a:eq(0)', row).attr('href'), + reverse('editors.review', args=['118409']) + '?num=1') + row = doc('div.section table tr:eq(2)') + eq_(doc('td:eq(0)', row).text(), u'Better Facebook! 4.105') + eq_(doc('a:eq(0)', row).attr('href'), + reverse('editors.review', args=['118467']) + '?num=2') + + def test_redirect_to_review(self): + r = self.client.get(reverse('editors.queue_pending'), data={'num': 2}) + self.assertRedirects(r, reverse('editors.review', + args=['118467']) + '?num=2') + + def test_invalid_review_ignored(self): + r = self.client.get(reverse('editors.queue_pending'), data={'num': 9}) + eq_(r.status_code, 200) + + def test_garbage_review_num_ignored(self): + r = self.client.get(reverse('editors.queue_pending'), + data={'num': 'not-a-number'}) + eq_(r.status_code, 200) diff --git a/apps/editors/views.py b/apps/editors/views.py index c602fa58e2..0f31411196 100644 --- a/apps/editors/views.py +++ b/apps/editors/views.py @@ -38,13 +38,28 @@ def queue(request): @editor_required def queue_pending(request): qs = ViewEditorQueue.objects.all() + review_num = request.GET.get('num', None) + if review_num: + try: + review_num = int(review_num) + except ValueError: + pass + else: + try: + row = qs[review_num - 1] + return redirect('%s?num=%s' % (reverse('editors.review', + args=[row.version_id]), + review_num)) + except IndexError: + pass order_by = request.GET.get('sort', '-days_since_created') table = ViewEditorQueueTable(qs, order_by=order_by) page = paginate(request, table.rows, per_page=100) + table.set_page(page) return jingo.render(request, 'editors/queue/pending.html', {'table': table, 'page': page}) @editor_required def review(request, version_id): - raise NotImplementedError + return http.HttpResponse('Not implemented yet')