Commit 82471fc3 authored by Michal Čihař's avatar Michal Čihař

Move last changes to separate page

This is not frequently used tab and causes about half of loading time
of translation page. So loading this using AJAX will make it faster for
most users.
parent 9d381c45
......@@ -86,6 +86,13 @@ class JSViewsTest(ViewTestCase):
)
self.assertContains(response, unit.checksum)
def test_get_unit_changes(self):
unit = self.get_unit()
response = self.client.get(
reverse('js-unit-changes', kwargs={'unit_id': unit.id}),
)
self.assertContains(response, 'href="/exports/rss/')
def test_get_dictionary(self):
unit = self.get_unit()
response = self.client.get(
......
......@@ -24,11 +24,9 @@ from django.template import RequestContext
from django.http import HttpResponseRedirect, HttpResponse
from django.contrib import messages
from django.contrib.auth.decorators import login_required, permission_required
from django.core.urlresolvers import reverse
from django.utils import formats
import uuid
import time
from urllib import urlencode
from trans.models import SubProject, Unit, Change
from trans.models.unitdata import Comment, Suggestion
......@@ -587,12 +585,6 @@ def translate(request, project, subproject, lang):
'prev_unit_url': base_unit_url + str(offset - 1),
'object': obj,
'unit': unit,
'last_changes': unit.change_set.all()[:10],
'last_changes_rss': reverse(
'rss-translation',
kwargs=obj.get_kwargs(),
),
'last_changes_url': urlencode(obj.get_kwargs()),
'total': obj.unit_set.all().count(),
'search_id': search_result['search_id'],
'search_query': search_result['query'],
......
......@@ -23,6 +23,7 @@ from django.template import RequestContext
from django.http import HttpResponse, HttpResponseBadRequest
from django.contrib.auth.decorators import permission_required, login_required
from django.db.models import Q
from django.core.urlresolvers import reverse
from trans.models import Unit, Check, Dictionary
from trans.machine import MACHINE_TRANSLATION_SERVICES
......@@ -30,6 +31,7 @@ from trans.decorators import any_permission_required
from trans.views.helper import get_project, get_subproject, get_translation
from whoosh.analysis import StandardAnalyzer, StemmingAnalyzer
from urllib import urlencode
import json
......@@ -105,6 +107,23 @@ def get_other(request, unit_id):
}))
def get_unit_changes(request, unit_id):
'''
Returns unit's recent changes.
'''
unit = get_object_or_404(Unit, pk=int(unit_id))
unit.check_acl(request)
return render_to_response('last-changes.html', RequestContext(request, {
'last_changes': unit.change_set.all()[:10],
'last_changes_rss': reverse(
'rss-translation',
kwargs=unit.translation.get_kwargs(),
),
'last_changes_url': urlencode(unit.translation.get_kwargs()),
}))
def get_dictionary(request, unit_id):
'''
Lists words from dictionary for current translation.
......
......@@ -190,7 +190,7 @@
{% trans "Comments" %}
{% endif %}
</a></li>
<li><a href="#tab-changes" title="{% trans "List of recent changes done in Weblate" %}">{% trans "History" %}</a></li>
<li><a href="{% url 'js-unit-changes' unit_id=unit.id %}" title="{% trans "List of recent changes done in Weblate" %}">{% trans "History" %}</a></li>
<li><a href="#tab-source" title="{% trans "Source string details and feedback" %}">
{% if source_comments.exists %}
{% blocktrans with source_comments.count as count %}Source ({{ count }}){% endblocktrans %}
......@@ -236,9 +236,6 @@
</ul>
</div>
{% endif %}
<div id="tab-changes">
{% include "last-changes.html" %}
</div>
<div id="tab-comments">
<p>{% trans "You can share comments about this translation with other translators." %}</p>
<table>
......
......@@ -547,6 +547,11 @@ urlpatterns = patterns(
'trans.views.js.translate',
name='js-translate',
),
url(
r'^js/changes/(?P<unit_id>[0-9]+)/$',
'trans.views.js.get_unit_changes',
name='js-unit-changes',
),
url(
r'^js/other/(?P<unit_id>[0-9]+)/$',
'trans.views.js.get_other',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment