xmpp.chapril.org-conversejs/trans/views.py

49 lines
1.7 KiB
Python
Raw Normal View History

2012-02-27 11:18:49 +01:00
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from trans.models import Project, SubProject, Translation, Unit
def show_project(request, project):
obj = get_object_or_404(Project, slug = project)
2012-02-27 11:58:55 +01:00
return render_to_response('project.html', RequestContext(request, {
2012-02-27 11:18:49 +01:00
'object': obj,
2012-02-28 09:26:31 +01:00
'title': '%s @ Weblate' % (obj.__unicode__()),
2012-02-27 11:47:34 +01:00
}))
2012-02-27 11:18:49 +01:00
def show_subproject(request, project, subproject):
obj = get_object_or_404(SubProject, slug = subproject, project__slug = project)
2012-02-27 11:58:55 +01:00
return render_to_response('subproject.html', RequestContext(request, {
2012-02-27 11:18:49 +01:00
'object': obj,
2012-02-28 09:26:31 +01:00
'title': '%s @ Weblate' % (obj.__unicode__()),
2012-02-27 11:47:34 +01:00
}))
2012-02-27 11:18:49 +01:00
def show_translation(request, project, subproject, lang):
2012-02-28 10:31:10 +01:00
obj = get_object_or_404(Translation, language__code = lang, subproject__slug = subproject, subproject__project__slug = project)
2012-02-27 11:18:49 +01:00
2012-02-27 11:58:55 +01:00
return render_to_response('translation.html', RequestContext(request, {
2012-02-27 11:18:49 +01:00
'object': obj,
2012-02-28 09:26:31 +01:00
'title': '%s @ Weblate' % (obj.__unicode__()),
2012-02-27 11:47:34 +01:00
}))
2012-02-27 11:18:49 +01:00
2012-02-28 14:55:34 +01:00
def translate(request, project, subproject, lang):
obj = get_object_or_404(Translation, language__code = lang, subproject__slug = subproject, subproject__project__slug = project)
2012-02-28 15:00:23 +01:00
rqtype = request.REQUEST.get('type', 'all')
2012-02-28 15:16:02 +01:00
pos = request.REQUEST.get('oldpos', '-1')
2012-02-28 15:00:23 +01:00
try:
2012-02-28 15:16:02 +01:00
pos = int(pos)
2012-02-28 15:00:23 +01:00
except:
2012-02-28 15:16:02 +01:00
pos = -1
unit = obj.unit_set.filter_type(rqtype).filter(position__gt = pos)[0]
total = obj.unit_set.all().count()
2012-02-28 14:55:34 +01:00
return render_to_response('translate.html', RequestContext(request, {
'object': obj,
'title': '%s @ Weblate' % (obj.__unicode__()),
2012-02-28 15:16:02 +01:00
'unit': unit,
2012-02-28 15:09:03 +01:00
'total': total,
2012-02-28 15:40:08 +01:00
'type': rqtype,
2012-02-28 14:55:34 +01:00
}))