Work with positions instead of offset
This commit is contained in:
parent
4a1eb36027
commit
79f865b380
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
<h2>{% trans "Translate" %}</h2>
|
<h2>{% trans "Translate" %}</h2>
|
||||||
|
|
||||||
|
<p>{% blocktrans %}Showing string {{ unit.position }} out of {{ total }}.{% endblocktrans %}</p>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
obj = get_object_or_404(Translation, language__code = lang, subproject__slug = subproject, subproject__project__slug = project)
|
||||||
|
|
||||||
rqtype = request.REQUEST.get('type', 'all')
|
rqtype = request.REQUEST.get('type', 'all')
|
||||||
offset = request.REQUEST.get('offset', '0')
|
pos = request.REQUEST.get('oldpos', '-1')
|
||||||
try:
|
try:
|
||||||
offset = int(offset)
|
pos = int(pos)
|
||||||
except:
|
except:
|
||||||
offset = 0
|
pos = -1
|
||||||
units = obj.unit_set.filter_type(rqtype)
|
unit = obj.unit_set.filter_type(rqtype).filter(position__gt = pos)[0]
|
||||||
total = units.count()
|
total = obj.unit_set.all().count()
|
||||||
if offset >= total:
|
|
||||||
offset = total - 1
|
|
||||||
nextoffset = offset + 1
|
|
||||||
if nextoffset >= total:
|
|
||||||
nextoffset = None
|
|
||||||
prevoffset = offset - 1
|
|
||||||
if prevoffset < 0:
|
|
||||||
prevoffset = None
|
|
||||||
|
|
||||||
return render_to_response('translate.html', RequestContext(request, {
|
return render_to_response('translate.html', RequestContext(request, {
|
||||||
'object': obj,
|
'object': obj,
|
||||||
'title': '%s @ Weblate' % (obj.__unicode__()),
|
'title': '%s @ Weblate' % (obj.__unicode__()),
|
||||||
'unit': units[offset],
|
'unit': unit,
|
||||||
'total': total,
|
'total': total,
|
||||||
'offset': offset,
|
|
||||||
'prevoffset': prevoffset,
|
|
||||||
'nextoffset': nextoffset,
|
|
||||||
}))
|
}))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user