i18n support
authorAlex Kamedov <alex@kamedov.ru>
Thu, 7 Apr 2011 06:07:18 +0000 (12:07 +0600)
committerAlex Kamedov <alex@kamedov.ru>
Thu, 7 Apr 2011 06:07:18 +0000 (12:07 +0600)
cas_provider/forms.py
cas_provider/models.py
cas_provider/views.py

index f270c37..8a8226b 100644 (file)
@@ -1,12 +1,13 @@
 from django import forms
 from django.contrib.auth.forms import AuthenticationForm
 from django.contrib.auth import authenticate
+from django.utils.translation import ugettext_lazy as _
 
 from utils import create_login_ticket
 
 class LoginForm(forms.Form):
-    username = forms.CharField(max_length=30)
-    password = forms.CharField(widget=forms.PasswordInput)
+    username = forms.CharField(max_length=30, label=_('username'))
+    password = forms.CharField(widget=forms.PasswordInput, label=_('password'))
     #warn = forms.BooleanField(required=False)  # TODO: Implement
     lt = forms.CharField(widget=forms.HiddenInput, initial=create_login_ticket)
     def __init__(self, service=None, renew=None, gateway=None, request=None, *args, **kwargs):
index 94023b7..5566313 100644 (file)
@@ -1,18 +1,27 @@
 from django.db import models
 from django.contrib.auth.models import User
+from django.utils.translation import ugettext_lazy as _
 
 class ServiceTicket(models.Model):
-    user = models.ForeignKey(User)
-    service = models.URLField(verify_exists=False)
-    ticket = models.CharField(max_length=256)
-    created = models.DateTimeField(auto_now=True)
-    
+    user = models.ForeignKey(User, verbose_name=_('user'))
+    service = models.URLField(_('service'), verify_exists=False)
+    ticket = models.CharField(_('ticket'), max_length=256)
+    created = models.DateTimeField(_('created'), auto_now=True)
+
+    class Meta:
+        verbose_name = _('Service Ticket')
+        verbose_name_plural = _('Service Tickets')
+
     def __unicode__(self):
         return "%s (%s) - %s" % (self.user.username, self.service, self.created)
-        
+
 class LoginTicket(models.Model):
-    ticket = models.CharField(max_length=32)
-    created = models.DateTimeField(auto_now=True)
-    
+    ticket = models.CharField(_('ticket'), max_length=32)
+    created = models.DateTimeField(_('created'), auto_now=True)
+
+    class Meta:
+        verbose_name = _('Login Ticket')
+        verbose_name_plural = _('Login Tickets')
+
     def __unicode__(self):
-        return "%s - %s" % (self.ticket, self.created)
\ No newline at end of file
+        return "%s - %s" % (self.ticket, self.created)
index 9c820ce..50e075e 100644 (file)
@@ -4,6 +4,7 @@ from django.template import RequestContext
 from django.contrib.auth.models import User
 from django.contrib.auth import authenticate
 from django.contrib.auth import login as auth_login, logout as auth_logout
+from django.utils.translation import ugettext_lazy as _
 
 from forms import LoginForm
 from models import ServiceTicket, LoginTicket
@@ -32,7 +33,7 @@ def login(request, template_name='cas/login.html', success_redirect='/accounts/'
         try:
             login_ticket = LoginTicket.objects.get(ticket=lt)
         except:
-            errors.append('Login ticket expired. Please try again.')
+            errors.append(_('Login ticket expired. Please try again.'))
         else:
             login_ticket.delete()
             user = authenticate(username=username, password=password)
@@ -45,9 +46,9 @@ def login(request, template_name='cas/login.html', success_redirect='/accounts/'
                     else:
                         return HttpResponseRedirect(success_redirect)
                 else:
-                    errors.append('This account is disabled.')
+                    errors.append(_('This account is disabled.'))
             else:
-                    errors.append('Incorrect username and/or password.')
+                    errors.append(_('Incorrect username and/or password.'))
     form = LoginForm(service)
     return render_to_response(template_name, {'form': form, 'errors': errors}, context_instance=RequestContext(request))