basic translation works
This commit is contained in:
parent
2da45a59fc
commit
a9339e5cdf
|
@ -58,6 +58,7 @@ class Translation(models.Model):
|
||||||
string = models.TextField(unique=True)
|
string = models.TextField(unique=True)
|
||||||
string_trans = models.TextField(blank=True, null=True)
|
string_trans = models.TextField(blank=True, null=True)
|
||||||
looked_at = models.NullBooleanField(default=False)
|
looked_at = models.NullBooleanField(default=False)
|
||||||
|
# user = models.ForeignKey(User)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return "%s: %s" % (self.string, self.string_trans,)
|
return "%s: %s" % (self.string, self.string_trans,)
|
||||||
|
|
|
@ -8,8 +8,9 @@ from django.db.models import Q
|
||||||
from django.template import RequestContext
|
from django.template import RequestContext
|
||||||
from ox.django.shortcuts import render_to_json_response
|
from ox.django.shortcuts import render_to_json_response
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
|
|
||||||
|
@login_required
|
||||||
def googletranslate(request, model, field):
|
def googletranslate(request, model, field):
|
||||||
start = request.GET.get("start", False)
|
start = request.GET.get("start", False)
|
||||||
end = request.GET.get("end", False)
|
end = request.GET.get("end", False)
|
||||||
|
@ -56,6 +57,7 @@ def googletranslate(request, model, field):
|
||||||
return render_to_response("translate.html", context)
|
return render_to_response("translate.html", context)
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
|
@login_required
|
||||||
def dotranslate(request, model, field):
|
def dotranslate(request, model, field):
|
||||||
data = json.loads(request.POST.get('data', '{}'))
|
data = json.loads(request.POST.get('data', '{}'))
|
||||||
m = models.__getattribute__(model)
|
m = models.__getattribute__(model)
|
||||||
|
@ -75,7 +77,7 @@ def dotranslate(request, model, field):
|
||||||
# return render_to_json_response(data)
|
# return render_to_json_response(data)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
def translate(request, model, field):
|
def translate(request, model, field):
|
||||||
start = request.GET.get("start", False)
|
start = request.GET.get("start", False)
|
||||||
end = request.GET.get("end", False)
|
end = request.GET.get("end", False)
|
||||||
|
@ -91,7 +93,8 @@ def translate(request, model, field):
|
||||||
if field not in m._meta.get_all_field_names():
|
if field not in m._meta.get_all_field_names():
|
||||||
return HttpResponse("no such field")
|
return HttpResponse("no such field")
|
||||||
trans_field = field + "_trans"
|
trans_field = field + "_trans"
|
||||||
qset = m.objects.values('id', field, trans_field).order_by(field).distinct(field)
|
q = Q(**{"%s__exact" % trans_field: ''})
|
||||||
|
qset = m.objects.values('id', field, trans_field).exclude(q).order_by(field).distinct(field)
|
||||||
if limit:
|
if limit:
|
||||||
if not start:
|
if not start:
|
||||||
start = 0
|
start = 0
|
||||||
|
@ -114,6 +117,7 @@ def translate(request, model, field):
|
||||||
return render_to_response("trans.html", context)
|
return render_to_response("trans.html", context)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
def stringtranslate(request):
|
def stringtranslate(request):
|
||||||
model = request.POST.get("model", "")
|
model = request.POST.get("model", "")
|
||||||
field = request.POST.get("field", "")
|
field = request.POST.get("field", "")
|
||||||
|
@ -123,7 +127,7 @@ def stringtranslate(request):
|
||||||
if not model == 'Translation':
|
if not model == 'Translation':
|
||||||
return render_to_json_response({'error': 'this only works for the translation model'})
|
return render_to_json_response({'error': 'this only works for the translation model'})
|
||||||
obj = Translation.objects.get(pk=id)
|
obj = Translation.objects.get(pk=id)
|
||||||
obj.translation = translation
|
obj.string_trans = translation
|
||||||
obj.save()
|
obj.save()
|
||||||
return render_to_json_response({'ok': 'ok'})
|
return render_to_json_response({'ok': 'ok'})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user