From 79f865b380ad172292653871a31086f7afa2a0ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 28 Feb 2012 15:16:02 +0100 Subject: [PATCH] Work with positions instead of offset --- html/translate.html | 1 + trans/views.py | 23 ++++++----------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/html/translate.html b/html/translate.html index d9e9ed5c3..8c3a640bd 100644 --- a/html/translate.html +++ b/html/translate.html @@ -7,6 +7,7 @@

{% trans "Translate" %}

+

{% blocktrans %}Showing string {{ unit.position }} out of {{ total }}.{% endblocktrans %}

{% endblock %} diff --git a/trans/views.py b/trans/views.py index a6f050681..94761bfb8 100644 --- a/trans/views.py +++ b/trans/views.py @@ -31,28 +31,17 @@ def translate(request, project, subproject, lang): obj = get_object_or_404(Translation, language__code = lang, subproject__slug = subproject, subproject__project__slug = project) rqtype = request.REQUEST.get('type', 'all') - offset = request.REQUEST.get('offset', '0') + pos = request.REQUEST.get('oldpos', '-1') try: - offset = int(offset) + pos = int(pos) except: - offset = 0 - units = obj.unit_set.filter_type(rqtype) - total = units.count() - if offset >= total: - offset = total - 1 - nextoffset = offset + 1 - if nextoffset >= total: - nextoffset = None - prevoffset = offset - 1 - if prevoffset < 0: - prevoffset = None + pos = -1 + unit = obj.unit_set.filter_type(rqtype).filter(position__gt = pos)[0] + total = obj.unit_set.all().count() return render_to_response('translate.html', RequestContext(request, { 'object': obj, 'title': '%s @ Weblate' % (obj.__unicode__()), - 'unit': units[offset], + 'unit': unit, 'total': total, - 'offset': offset, - 'prevoffset': prevoffset, - 'nextoffset': nextoffset, }))