Work with positions instead of offset

This commit is contained in:
Michal Čihař 2012-02-28 15:16:02 +01:00
parent 4a1eb36027
commit 79f865b380
2 changed files with 7 additions and 17 deletions

View File

@ -7,6 +7,7 @@
<h2>{% trans "Translate" %}</h2>
<p>{% blocktrans %}Showing string {{ unit.position }} out of {{ total }}.{% endblocktrans %}</p>
{% endblock %}

View File

@ -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,
}))