Indicate if someone else was viewing the page first (bug 436407)
This commit is contained in:
Родитель
240e8da50a
Коммит
97da9ab052
|
@ -207,3 +207,6 @@ FOUNDATION_ORG = 1 # The charities.id of the Mozilla Foundation.
|
|||
VERSION_BETA = re.compile('(a|alpha|b|beta|pre|rc)\d*$')
|
||||
VERSION_SEARCH = re.compile('\.(\d+)$')
|
||||
|
||||
# Editor Tools
|
||||
EDITOR_VIEWING_INTERVAL = 8
|
||||
|
||||
|
|
|
@ -136,6 +136,10 @@
|
|||
</div>
|
||||
{% endfor %}
|
||||
|
||||
<div class="currently_viewing_warning">
|
||||
{{ _("You can still submit this form, however only do so if you know it won't conflict.") }}
|
||||
</div>
|
||||
|
||||
<label for="id_comments">{{ form.comments.label }}</label>
|
||||
{{ form.comments }}
|
||||
{{ form.comments.errors }}
|
||||
|
@ -188,6 +192,11 @@
|
|||
{{ form.notify.errors }}
|
||||
</div>
|
||||
<div class="review-actions-section review-actions-save">
|
||||
<span class="currently_viewing_warning">
|
||||
{% trans %}
|
||||
<strong>Warning!</strong> Another user was viewing this page before you.
|
||||
{% endtrans %}
|
||||
</span>
|
||||
<input type="submit" value="{{ _('Save') }}" />
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1317,6 +1317,23 @@ class TestReview(ReviewBase):
|
|||
doc = pq(self.client.get(self.url).content)
|
||||
eq_(doc('ol.breadcrumbs li:eq(1)').text(), text)
|
||||
|
||||
def test_viewing(self):
|
||||
r = self.client.post(reverse('editors.review_viewing'),
|
||||
{'addon_id': self.addon.id })
|
||||
data = json.loads(r.content)
|
||||
eq_(data['current'], self.editor.id)
|
||||
eq_(data['current_name'], self.editor.name)
|
||||
eq_(data['is_user'], 1)
|
||||
|
||||
# Now, login as someone else and test.
|
||||
self.login_as_admin()
|
||||
r = self.client.post(reverse('editors.review_viewing'),
|
||||
{'addon_id': self.addon.id })
|
||||
data = json.loads(r.content)
|
||||
eq_(data['current'], self.editor.id)
|
||||
eq_(data['current_name'], self.editor.name)
|
||||
eq_(data['is_user'], 0)
|
||||
|
||||
def test_no_compare_link(self):
|
||||
r = self.client.get(self.url)
|
||||
doc = pq(r.content)
|
||||
|
|
|
@ -19,6 +19,8 @@ urlpatterns = patterns('',
|
|||
url(r'^logs$', views.eventlog, name='editors.eventlog'),
|
||||
url(r'^log/(\d+)$', views.eventlog_detail, name='editors.eventlog.detail'),
|
||||
url(r'^reviewlog$', views.reviewlog, name='editors.reviewlog'),
|
||||
url(r'^review_viewing$', views.review_viewing,
|
||||
name='editors.review_viewing'),
|
||||
url(r'^review/(?P<version_id>\d+)$', views.review, name='editors.review'),
|
||||
url(r'^performance$', views.performance, name='editors.performance'),
|
||||
url(r'^motd$', views.motd, name='editors.motd'),
|
||||
|
|
|
@ -5,8 +5,10 @@ import time
|
|||
|
||||
from django import http
|
||||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.shortcuts import redirect, get_object_or_404
|
||||
from django.utils.datastructures import SortedDict
|
||||
from django.views.decorators.cache import never_cache
|
||||
|
||||
import jingo
|
||||
from tower import ugettext as _
|
||||
|
@ -27,6 +29,7 @@ from editors.helpers import (ViewPendingQueueTable, ViewFullReviewQueueTable,
|
|||
from files.models import Approval
|
||||
from reviews.forms import ReviewFlagFormSet
|
||||
from reviews.models import Review, ReviewFlag
|
||||
from users.models import UserProfile
|
||||
from zadmin.models import get_config, set_config
|
||||
|
||||
|
||||
|
@ -417,6 +420,37 @@ def review(request, version_id):
|
|||
return jingo.render(request, 'editors/review.html', ctx)
|
||||
|
||||
|
||||
@never_cache
|
||||
@json_view
|
||||
@editor_required
|
||||
def review_viewing(request):
|
||||
if 'addon_id' not in request.POST:
|
||||
return {}
|
||||
|
||||
addon_id = request.POST['addon_id']
|
||||
user_id = request.amo_user.id
|
||||
current_name = ''
|
||||
is_user = 0
|
||||
key = '%s:review_viewing:%s' % (settings.CACHE_PREFIX, addon_id)
|
||||
|
||||
# Check who is viewing.
|
||||
currently_viewing = cache.get(key)
|
||||
|
||||
# If nobody is viewing or current user is, set current user as viewing
|
||||
if not currently_viewing or currently_viewing == user_id:
|
||||
# We want to save it for twice as long as the ping interval,
|
||||
# just to account for latency and the like.
|
||||
cache.set(key, user_id, amo.EDITOR_VIEWING_INTERVAL * 2)
|
||||
currently_viewing = user_id
|
||||
current_name = request.amo_user.name
|
||||
is_user = 1
|
||||
else:
|
||||
current_name = UserProfile.objects.get(pk=currently_viewing).name
|
||||
|
||||
return {'current': currently_viewing, 'current_name': current_name,
|
||||
'is_user': is_user}
|
||||
|
||||
|
||||
@editor_required
|
||||
def reviewlog(request):
|
||||
data = request.GET.copy()
|
||||
|
|
|
@ -643,6 +643,26 @@ div.editor-stats-table > div.editor-stats-dark {
|
|||
text-align: right;
|
||||
}
|
||||
|
||||
.currently_viewing_warning {
|
||||
display: none;
|
||||
}
|
||||
|
||||
div.currently_viewing_warning {
|
||||
background-color: #FFE4E4;
|
||||
margin: 1em 0;
|
||||
border: 1px dashed #FE7272;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
div.currently_viewing_warning strong {
|
||||
display: block;
|
||||
}
|
||||
|
||||
span.currently_viewing_warning {
|
||||
color: red;
|
||||
padding-right: 15px;
|
||||
}
|
||||
|
||||
.article ul {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
|
|
@ -109,6 +109,21 @@ function initReviewActions() {
|
|||
installer($this.text(), $this.attr('href'), "")
|
||||
}));
|
||||
|
||||
|
||||
/* Who's currently on this page? */
|
||||
function check_currently_viewing() {
|
||||
$.post('/en-US/editors/review_viewing', {'addon_id':1}, function(d){
|
||||
$current = $('.currently_viewing_warning');
|
||||
$current.toggle(d.is_user != 1);
|
||||
|
||||
var title = format(gettext('{name} was viewing this page first.'), {name: d.current_name})
|
||||
$current_div = $current.filter('div');
|
||||
$current_div.find('strong').remove();
|
||||
$current_div.prepend($('<strong>', {'text': title}));
|
||||
});
|
||||
}
|
||||
check_currently_viewing();
|
||||
setInterval(check_currently_viewing, 8000);
|
||||
}
|
||||
|
||||
function insertAtCursor(textarea, text) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче