From: Alex Kamedov Date: Thu, 7 Apr 2011 06:07:18 +0000 (+0600) Subject: i18n support X-Git-Tag: 22.4~32^2~25 X-Git-Url: https://git.mdrn.pl/django-cas-provider.git/commitdiff_plain/23f180a9809cbeed655e82359f7c7e6cfc16fb68?ds=sidebyside;hp=-c i18n support --- 23f180a9809cbeed655e82359f7c7e6cfc16fb68 diff --git a/cas_provider/forms.py b/cas_provider/forms.py index f270c37..8a8226b 100644 --- a/cas_provider/forms.py +++ b/cas_provider/forms.py @@ -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): diff --git a/cas_provider/models.py b/cas_provider/models.py index 94023b7..5566313 100644 --- a/cas_provider/models.py +++ b/cas_provider/models.py @@ -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) diff --git a/cas_provider/views.py b/cas_provider/views.py index 9c820ce..50e075e 100644 --- a/cas_provider/views.py +++ b/cas_provider/views.py @@ -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))