Skip to content

Commit

Permalink
Show position in review queue (bug 546339)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkoberger committed Jun 23, 2011
1 parent 5c56dec commit 591e493
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 0 deletions.
8 changes: 8 additions & 0 deletions apps/devhub/templates/devhub/versions/list.html
Expand Up @@ -50,6 +50,14 @@ <h3>{{ _('Current Status') }}</h3>
{% endif %}

<div class="version-status-actions item-actions">
{% if position %}
<span class="dark" title="{{ _('Queues are not reviewed strictly in order.') }}">
{% trans pos=position['pos'], total=position['total'] %}
Queue Position: {{ pos }} of {{ total }}
{% endtrans %}
&middot;
</span>
{% endif %}
{% if check_addon_ownership(request, addon, dev=True) %}
{% set req = {amo.STATUS_PUBLIC: _('Request Full Review'),
amo.STATUS_LITE: _('Request Preliminary Review')} %}
Expand Down
44 changes: 44 additions & 0 deletions apps/devhub/tests/test_views.py
Expand Up @@ -2702,6 +2702,50 @@ def setUp(self):
assert self.client.login(username='del@icio.us', password='password')


class TestQueuePosition(UploadTest):
fixtures = ['base/apps', 'base/users',
'base/addon_3615', 'base/platforms']

def setUp(self):
super(TestQueuePosition, self).setUp()

self.url = reverse('devhub.versions.add_file',
args=[self.addon.slug, self.version.id])
self.edit_url = reverse('devhub.versions.edit',
args=[self.addon.slug, self.version.id])
files = self.version.files.all()[0]
files.platform_id = amo.PLATFORM_LINUX.id
files.save()

def test_not_in_queue(self):
r = self.client.get(reverse('devhub.versions', args=[self.addon.slug]))

eq_(self.addon.status, amo.STATUS_PUBLIC)
eq_(pq(r.content)('.version-status-actions .dark').length, 0)

def test_in_queue(self):
statuses = [(amo.STATUS_NOMINATED, amo.STATUS_NOMINATED),
(amo.STATUS_PUBLIC, amo.STATUS_UNREVIEWED),
(amo.STATUS_LITE, amo.STATUS_UNREVIEWED)]

for addon_status in statuses:
self.addon.status = addon_status[0]
self.addon.save()

file = self.addon.latest_version.files.all()[0]
file.status = addon_status[1]
file.save()

r = self.client.get(reverse('devhub.versions',
args=[self.addon.slug]))
doc = pq(r.content)

span = doc('.version-status-actions .dark')

eq_(span.length, 1)
assert "Queue Position: 1 of 1" in span.text()


class TestVersionAddFile(UploadTest):
fixtures = ['base/apps', 'base/users',
'base/addon_3615', 'base/platforms']
Expand Down
3 changes: 3 additions & 0 deletions apps/devhub/views.py
Expand Up @@ -40,6 +40,7 @@
from addons.models import Addon, AddonUser
from addons.views import BaseFilter
from devhub.models import ActivityLog, BlogPost, RssKey, SubmitStep
from editors.helpers import get_position
from files.models import File, FileUpload
from files.utils import parse_addon
from translations.models import delete_translation
Expand Down Expand Up @@ -913,9 +914,11 @@ def version_list(request, addon_id, addon):
qs = addon.versions.order_by('-created').transform(Version.transformer)
versions = amo.utils.paginate(request, qs)
new_file_form = forms.NewVersionForm(None, addon=addon)

data = {'addon': addon,
'versions': versions,
'new_file_form': new_file_form,
'position': get_position(addon),
'timestamp': int(time.time())}
return jingo.render(request, 'devhub/versions/list.html', data)

Expand Down
20 changes: 20 additions & 0 deletions apps/editors/helpers.py
Expand Up @@ -219,6 +219,26 @@ def send_mail(template, subject, emails, context):
use_blacklist=False)


def get_position(addon):
version = addon.latest_version

if not version:
return False

q = version.current_queue
if not q:
return False

mins_query = q.objects.filter(id=addon.id)
if mins_query.count() > 0:
mins = mins_query[0].waiting_time_min
pos = q.objects.having('waiting_time_min >=', mins).count()
total = q.objects.count()
return dict(mins=mins, pos=pos, total=total)

return False


class ReviewHelper:
"""
A class that builds enough to render the form back to the user and
Expand Down
18 changes: 18 additions & 0 deletions apps/editors/tests/test_views.py
Expand Up @@ -20,6 +20,7 @@
from applications.models import Application
from devhub.models import ActivityLog
from editors.models import EditorSubscription, EventLog
from editors.helpers import get_position
from files.models import Platform, File
import reviews
from reviews.models import Review, ReviewFlag
Expand Down Expand Up @@ -430,6 +431,11 @@ def addon_file(self, *args, **kw):
a = create_addon_file(*args, **kw)
self.versions[unicode(a['addon'].name)] = a['version']

def get_queue(self, version_name):
addon_id = self.versions[version_name].addon.id
version = Addon.objects.get(pk=addon_id).latest_version
eq_(version.current_queue.objects.filter(id=addon_id).count(), 1)


class TestQueueBasics(QueueTest):

Expand Down Expand Up @@ -688,6 +694,10 @@ def test_breadcrumbs(self):
eq_(list_items.eq(0).find('a').text(), "Editor Tools")
eq_(list_items.eq(1).text(), "Pending Updates")

def test_get_queue(self):
self.get_queue(u'Pending One')
self.get_queue(u'Pending Two')


class TestNominatedQueue(QueueTest):

Expand Down Expand Up @@ -743,6 +753,10 @@ def test_queue_count(self):
eq_(doc('.tabnav li a:eq(0)').attr('href'),
reverse('editors.queue_nominated'))

def test_get_queue(self):
self.get_queue(u'Nominated One')
self.get_queue(u'Nominated Two')


class TestPreliminaryQueue(QueueTest):

Expand Down Expand Up @@ -778,6 +792,10 @@ def test_breadcrumbs(self):
eq_(list_items.eq(0).find('a').text(), "Editor Tools")
eq_(list_items.eq(1).text(), "Preliminary Reviews")

def test_get_queue(self):
self.get_queue(u'Prelim One')
self.get_queue(u'Prelim Two')


class TestModeratedQueue(QueueTest):
fixtures = ['base/users', 'base/apps', 'reviews/dev-reply.json']
Expand Down
16 changes: 16 additions & 0 deletions apps/versions/models.py
Expand Up @@ -151,6 +151,22 @@ def delete(self):
amo.log(amo.LOG.DELETE_VERSION, self.addon, str(self.version))
super(Version, self).delete()

@property
def current_queue(self):
"""Return the current queue, or None if not in a queue."""
from editors.models import (ViewPendingQueue, ViewFullReviewQueue,
ViewPreliminaryQueue)

if self.addon.status in [amo.STATUS_NOMINATED,
amo.STATUS_LITE_AND_NOMINATED]:
return ViewFullReviewQueue
elif self.addon.status == amo.STATUS_PUBLIC:
return ViewPendingQueue
elif self.addon.status in [amo.STATUS_LITE, amo.STATUS_UNREVIEWED]:
return ViewPreliminaryQueue

return None

@amo.cached_property(writable=True)
def all_activity(self):
from devhub.models import VersionLog # yucky
Expand Down
3 changes: 3 additions & 0 deletions media/css/zamboni/developers.css
Expand Up @@ -705,6 +705,9 @@ form .char-count b {
.item-actions a {
color: #aaa;
}
.item-actions .dark {
color: #444;
}
#dashboard .item:hover .item-actions {
color: #555;
}
Expand Down

0 comments on commit 591e493

Please sign in to comment.