translation pages for captain, ship_names / error message for invalid page

This commit is contained in:
Sanj 2012-03-06 18:47:43 +05:30
parent 5835d99c7b
commit 8e8b356524

View File

@ -102,8 +102,9 @@ def translate(request, model, field, page_no=1):
try:
results = paginator.page(page_no)
except (EmptyPage, InvalidPage):
results = paginator.page(paginator.num_pages)
page_no = paginator.num_pages
return HttpResponse("invalid page no / end of list")
# results = paginator.page(paginator.num_pages)
# page_no = paginator.num_pages
# if limit:
@ -139,13 +140,26 @@ def stringtranslate(request):
id = request.POST.get("id", 0)
string = request.POST.get("string", "")
translation = request.POST.get("translation", "")
if not model == 'Translation':
return render_to_json_response({'error': 'this only works for the translation model'})
if model == 'Translation':
obj = Translation.objects.get(pk=id)
obj.string_trans = translation
obj.looked_at = True
obj.save()
return render_to_json_response({'ok': 'ok'})
try:
m = models.__getattribute__(model)
except AttributeError:
return HttpResponse("no such model")
q = Q(**{"%s__exact" % field: string})
trans_field = field + "_trans"
matches = m.objects.filter(q)
savedObjects = 0
for match in matches:
match.__setattr__(trans_field, translation)
match.save()
savedObjects += 1
return render_to_json_response({'ok': savedObjects})
'''
def dotrans(request, model, field):