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_trans = models.TextField(blank=True, null=True)
|
||||
looked_at = models.NullBooleanField(default=False)
|
||||
# user = models.ForeignKey(User)
|
||||
|
||||
def __unicode__(self):
|
||||
return "%s: %s" % (self.string, self.string_trans,)
|
||||
|
|
|
@ -8,8 +8,9 @@ from django.db.models import Q
|
|||
from django.template import RequestContext
|
||||
from ox.django.shortcuts import render_to_json_response
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
|
||||
@login_required
|
||||
def googletranslate(request, model, field):
|
||||
start = request.GET.get("start", False)
|
||||
end = request.GET.get("end", False)
|
||||
|
@ -56,6 +57,7 @@ def googletranslate(request, model, field):
|
|||
return render_to_response("translate.html", context)
|
||||
|
||||
@csrf_exempt
|
||||
@login_required
|
||||
def dotranslate(request, model, field):
|
||||
data = json.loads(request.POST.get('data', '{}'))
|
||||
m = models.__getattribute__(model)
|
||||
|
@ -75,7 +77,7 @@ def dotranslate(request, model, field):
|
|||
# return render_to_json_response(data)
|
||||
|
||||
|
||||
|
||||
@login_required
|
||||
def translate(request, model, field):
|
||||
start = request.GET.get("start", 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():
|
||||
return HttpResponse("no such field")
|
||||
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 not start:
|
||||
start = 0
|
||||
|
@ -114,6 +117,7 @@ def translate(request, model, field):
|
|||
return render_to_response("trans.html", context)
|
||||
|
||||
|
||||
@login_required
|
||||
def stringtranslate(request):
|
||||
model = request.POST.get("model", "")
|
||||
field = request.POST.get("field", "")
|
||||
|
@ -123,7 +127,7 @@ def stringtranslate(request):
|
|||
if not model == 'Translation':
|
||||
return render_to_json_response({'error': 'this only works for the translation model'})
|
||||
obj = Translation.objects.get(pk=id)
|
||||
obj.translation = translation
|
||||
obj.string_trans = translation
|
||||
obj.save()
|
||||
return render_to_json_response({'ok': 'ok'})
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user