From 8e8b356524466e98c832a598fa993dba1ba066c0 Mon Sep 17 00:00:00 2001 From: Sanj Date: Tue, 6 Mar 2012 18:47:43 +0530 Subject: [PATCH] translation pages for captain, ship_names / error message for invalid page --- manifests/ships/views.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/manifests/ships/views.py b/manifests/ships/views.py index 164007d..ec4b9f0 100644 --- a/manifests/ships/views.py +++ b/manifests/ships/views.py @@ -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'}) - obj = Translation.objects.get(pk=id) - obj.string_trans = translation - obj.looked_at = True - obj.save() - return render_to_json_response({'ok': 'ok'}) + 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):