From 4c56e363b7739111c82bb401dca0f986b0f5f084 Mon Sep 17 00:00:00 2001 From: Sanj Date: Thu, 22 Dec 2011 21:09:18 +0530 Subject: [PATCH] translation framework --- manifests/settings.py | 1 + manifests/ships/models.py | 7 ++++-- manifests/ships/views.py | 34 ++++++++++++++++++++++++++++++ manifests/templates/translate.html | 18 ++++++++++++++++ manifests/urls.py | 1 + 5 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 manifests/templates/translate.html diff --git a/manifests/settings.py b/manifests/settings.py index 0a8baf7..0ec12ed 100644 --- a/manifests/settings.py +++ b/manifests/settings.py @@ -116,6 +116,7 @@ INSTALLED_APPS = ( 'django.contrib.admin', # Uncomment the next line to enable admin documentation: 'django.contrib.admindocs', + 'django_extensions' ) try: diff --git a/manifests/ships/models.py b/manifests/ships/models.py index 379f88f..f989804 100644 --- a/manifests/ships/models.py +++ b/manifests/ships/models.py @@ -21,17 +21,20 @@ class Ship(models.Model): number = models.IntegerField(max_length=20) date = models.DateField() ship_name = models.CharField(max_length=255) + ship_name_trans = models.CharField(max_length=255, blank=True) captain = models.CharField(max_length=255) + captain_trans = models.CharField(max_length=255, blank=True) flag = models.CharField(max_length=255) owner = models.CharField(max_length=255) + owner_trans = models.CharField(max_length=255, blank=True) port = models.CharField(max_length=255) country = models.CharField(max_length=255) def __unicode__(self): return "%d: %s" % (self.number, self.ship_name,) - class Meta: - ordering = ['number'] +# class Meta: +# ordering = ['number'] def no_of_goods(self): return Good.objects.filter(ship=self).count() diff --git a/manifests/ships/views.py b/manifests/ships/views.py index 60f00ef..a9a87af 100644 --- a/manifests/ships/views.py +++ b/manifests/ships/views.py @@ -1 +1,35 @@ # Create your views here. +from models import * +from django.http import HttpResponse +from ships import models +import json +from django.shortcuts import render_to_response + +def translate(request, model, field): + start = request.GET.get("start", False) + end = request.GET.get("end", False) + if not start and not end: + limit = False + else: + limit = True + try: + m = models.__getattribute__(model) + except AttributeError: + return HttpResponse("no such model") + response = '' + if field not in m._meta.get_all_field_names(): + return HttpResponse("no such field") + qset = m.objects.values(field).distinct() + if limit: + if not start: + start = 0 + if not end: + end = qset.count() + qset = qset[start:end] + for obj in qset: + val = obj[field] + ordArr = [] + for char in val: + ordArr.append(str(ord(char))) + response += "%s|%s
" % (",".join(ordArr), val,) + return render_to_response("translate.html", {'txt': response}) diff --git a/manifests/templates/translate.html b/manifests/templates/translate.html new file mode 100644 index 0000000..f5b152f --- /dev/null +++ b/manifests/templates/translate.html @@ -0,0 +1,18 @@ + + + + + + +
+ {{ txt|safe }} + + + diff --git a/manifests/urls.py b/manifests/urls.py index 4256c7d..03f3839 100644 --- a/manifests/urls.py +++ b/manifests/urls.py @@ -12,5 +12,6 @@ urlpatterns = patterns('', # (r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: + (r'translate/(?P[A-Za-z].*?)/(?P[A-Za-z].*?)/', 'ships.views.translate'), (r'^admin/', include(admin.site.urls)), )