diff --git a/admin/forms.py b/admin/forms.py index 2fe3c5cfa..ece5c66f2 100644 --- a/admin/forms.py +++ b/admin/forms.py @@ -2,7 +2,7 @@ from django import forms from modoboa.admin.models import * from modoboa.admin.lib import is_domain_admin -from django.utils.translation import ugettext as _ +from django.utils.translation import ugettext as _, ugettext_noop from django.contrib.auth.models import User from modoboa.admin.templatetags.admin_extras import gender from modoboa.lib import tables @@ -48,17 +48,17 @@ class DomainAliasForm(ProxyForm): self.fields["target"].queryset = Domain.objects.filter(pk=self._domain.id) class MailboxForm(ProxyForm): - quota = forms.IntegerField(label=_("Quota"), required=False, - help_text=_("Mailbox quota in MB (default to domain quota if blank)")) - password1 = forms.CharField(label=_("Password"), + quota = forms.IntegerField(label=ugettext_noop("Quota"), required=False, + help_text=ugettext_noop("Mailbox quota in MB (default to domain quota if blank)")) + password1 = forms.CharField(label=ugettext_noop("Password"), widget=forms.PasswordInput(render_value=True), - help_text=_("Password used to log in")) - password2 = forms.CharField(label=_("Confirmation"), + help_text=ugettext_noop("Password used to log in")) + password2 = forms.CharField(label=ugettext_noop("Confirmation"), widget=forms.PasswordInput(render_value=True), - help_text=_("Password confirmation")) + help_text=ugettext_noop("Password confirmation")) enabled = forms.BooleanField(label=gender("Enabled", "f"), required=False, initial=True, - help_text=_("Check to activate this mailbox")) + help_text=ugettext_noop("Check to activate this mailbox")) class Meta: model = Mailbox @@ -100,8 +100,8 @@ class MailboxForm(ProxyForm): return m class AliasForm(ProxyForm): - targets = forms.CharField(label=_("Target(s)"), required=False, - help_text=_("Mailbox(es) this alias will point to")) + targets = forms.CharField(label=ugettext_noop("Target(s)"), required=False, + help_text=ugettext_noop("Mailbox(es) this alias will point to")) def __init__(self, *args, **kwargs): super(AliasForm, self).__init__(*args, **kwargs) @@ -176,36 +176,26 @@ class AliasForm(ProxyForm): return a class SuperAdminForm(forms.Form): - user = forms.ModelChoiceField([], label=_("User"), required=True, - empty_label=_("Select a user"), - help_text=_("Select a user in the list")) - def __init__(self, user, *args, **kwargs): super(SuperAdminForm, self).__init__(*args, **kwargs) + + self.fields["user"] = \ + forms.ModelChoiceField([], label=_("User"), required=True, + empty_label=_("Select a user"), + help_text=_("Select a user in the list")) self.fields["user"].queryset = User.objects.exclude(pk__in=[1, user.id]) class DomainAdminForm(forms.Form): - domain = forms.ModelChoiceField(queryset=Domain.objects.all(), label=_("Domain"), - required=True, - empty_label=_("Select a domain"), - help_text=_("Select a domain in the list")) - user = forms.ChoiceField(label=_("User"), required=True, - choices=[("", _("Empty"))], - help_text=_("Select a user in the list")) + def __init__(self, *args, **kwargs): + super(DomainAdminForm, self).__init__(*args, **kwargs) -class SuperAdminsTable(tables.Table): - idkey = "id" - selection = tables.SelectionColumn("selection", width="4%", first=True) - _1_user_name = tables.Column("user_name", label=_("User name")) - _2_full_name = tables.Column("full_name", label=_("Full name")) - _3_date_joined = tables.Column("date_joined", label=_("Defined")) - _4_enabled = tables.Column("enabled", label=gender("Enabled", "m"), width="10%") - -class DomainAdminsTable(tables.Table): - idkey = "id" - selection = tables.SelectionColumn("selection", width="4%", first=True) - _1_domain = tables.Column("domain", label=_("Domain")) - _2_full_name = tables.Column("full_name", label=_("Full name")) - _3_date_joined = tables.Column("date_joined", label=_("Defined")) - _4_enabled = tables.Column("enabled", label=gender("Enabled", "m"), width="10%") - + self.fields["domain"] = \ + forms.ModelChoiceField(queryset=Domain.objects.all(), + label=_("Domain"), + required=True, + empty_label=_("Select a domain"), + help_text=_("Select a domain in the list")) + self.fields["user"] = \ + forms.ChoiceField(label=_("User"), required=True, + choices=[("", _("Empty"))], + help_text=_("Select a user in the list")) diff --git a/admin/models.py b/admin/models.py index 8a1fb1802..0f1686694 100644 --- a/admin/models.py +++ b/admin/models.py @@ -1,7 +1,7 @@ # coding: utf-8 from django.db import models, IntegrityError from django.contrib.auth.models import User -from django.utils.translation import ugettext as _ +from django.utils.translation import ugettext as _, ugettext_noop from django.conf import settings from modoboa.lib import parameters from modoboa.lib.sysutils import exec_cmd, exec_as_vuser @@ -74,11 +74,11 @@ class DatesAware(models.Model): last_modification = property(__last_modification) class Domain(DatesAware): - name = models.CharField(_('name'), max_length=100, unique=True, - help_text=_("The domain name")) - quota = models.IntegerField(help_text=_("Default quota in MB applied to mailboxes")) - enabled = models.BooleanField(_('enabled'), - help_text=_("Check to activate this domain")) + name = models.CharField(ugettext_noop('name'), max_length=100, unique=True, + help_text=ugettext_noop("The domain name")) + quota = models.IntegerField(help_text=ugettext_noop("Default quota in MB applied to mailboxes")) + enabled = models.BooleanField(ugettext_noop('enabled'), + help_text=ugettext_noop("Check to activate this domain")) class Meta: permissions = ( @@ -131,12 +131,12 @@ class Domain(DatesAware): return self.name class DomainAlias(DatesAware): - name = models.CharField(_("name"), max_length=100, unique=True, - help_text=_("The alias name")) - target = models.ForeignKey(Domain, verbose_name=_('target'), - help_text=_("The domain this alias points to")) - enabled = models.BooleanField(_('enabled'), - help_text=_("Check to activate this alias")) + name = models.CharField(ugettext_noop("name"), max_length=100, unique=True, + help_text=ugettext_noop("The alias name")) + target = models.ForeignKey(Domain, verbose_name=ugettext_noop('target'), + help_text=ugettext_noop("The domain this alias points to")) + enabled = models.BooleanField(ugettext_noop('enabled'), + help_text=ugettext_noop("Check to activate this alias")) class Meta: permissions = ( @@ -144,11 +144,11 @@ class DomainAlias(DatesAware): ) class Mailbox(DatesAware): - name = models.CharField(_('name'), max_length=100, - help_text=_("First name and last name of mailbox owner")) - address = models.CharField(_('address'), max_length=100, - help_text=_("Mailbox address (without the @domain.tld part)")) - password = models.CharField(_('password'), max_length=100) + name = models.CharField(ugettext_noop('name'), max_length=100, + help_text=ugettext_noop("First name and last name of mailbox owner")) + address = models.CharField(ugettext_noop('address'), max_length=100, + help_text=ugettext_noop("Mailbox address (without the @domain.tld part)")) + password = models.CharField(ugettext_noop('password'), max_length=100) quota = models.IntegerField() uid = models.IntegerField() gid = models.IntegerField() @@ -303,14 +303,14 @@ class Mailbox(DatesAware): } class Alias(DatesAware): - address = models.CharField(_('address'), max_length=254, - help_text=_("The alias address (without the domain part). For a 'catch-all' address, just enter an * character.")) + address = models.CharField(ugettext_noop('address'), max_length=254, + help_text=ugettext_noop("The alias address (without the domain part). For a 'catch-all' address, just enter an * character.")) domain = models.ForeignKey(Domain) - mboxes = models.ManyToManyField(Mailbox, verbose_name=_('mailboxes'), - help_text=_("The mailboxes this alias points to")) + mboxes = models.ManyToManyField(Mailbox, verbose_name=ugettext_noop('mailboxes'), + help_text=ugettext_noop("The mailboxes this alias points to")) extmboxes = models.TextField(blank=True) - enabled = models.BooleanField(_('enabled'), - help_text=_("Check to activate this alias")) + enabled = models.BooleanField(ugettext_noop('enabled'), + help_text=ugettext_noop("Check to activate this alias")) class Meta: permissions = ( @@ -385,8 +385,8 @@ class Alias(DatesAware): class Extension(models.Model): name = models.CharField(max_length=150) - enabled = models.BooleanField(_('enabled'), - help_text=_("Check to enable this extension")) + enabled = models.BooleanField(ugettext_noop('enabled'), + help_text=ugettext_noop("Check to enable this extension")) def __getmodule(self): extname = "modoboa.extensions.%s" % self.name diff --git a/admin/permissions.py b/admin/permissions.py index 01c4e2902..12dcff7aa 100644 --- a/admin/permissions.py +++ b/admin/permissions.py @@ -1,10 +1,11 @@ # coding: utf-8 import datetime -from django.utils.translation import ugettext as _ +from django.utils.translation import ugettext as _, ugettext_noop from django.contrib.auth.models import User, Group from modoboa.lib.webutils import _render, getctx, _render_to_string from forms import * +from tables import SuperAdminsTable, DomainAdminsTable class Permissions(object): @staticmethod @@ -24,7 +25,7 @@ class Permissions(object): raise NotImplementedError class SuperAdminsPerms(Permissions): - title = _("Add super administrator") + title = ugettext_noop("Add super administrator") role = "super_admins" @staticmethod @@ -35,7 +36,7 @@ class SuperAdminsPerms(Permissions): form = SuperAdminForm(request.user) return _render(request, 'admin/add_permission.html', { "form" : form, - "title" : self.title, + "title" : _(self.title), "role": self.role }) @@ -51,7 +52,7 @@ class SuperAdminsPerms(Permissions): content = _render_to_string(request, "admin/add_permission.html", { "form" : form, - "title" : self.title, + "title" : _(self.title), "role" : self.role }) return False, getctx("ko", content=content) @@ -77,7 +78,7 @@ class SuperAdminsPerms(Permissions): class DomainAdminsPerms(Permissions): - title = _("Add domain administrator") + title = ugettext_noop("Add domain administrator") role = "domain_admins" @staticmethod @@ -88,7 +89,7 @@ class DomainAdminsPerms(Permissions): form = DomainAdminForm() return _render(request, 'admin/add_domain_admin.html', { "form" : form, - "title" : self.title, + "title" : _(self.title), "role" : self.role }) @@ -106,7 +107,7 @@ class DomainAdminsPerms(Permissions): return True, None content = _render_to_string(request, "admin/add_domain_admin.html", { "form" : form, - "title" : self.title, + "title" : _(self.title), "role" : self.role }) return False, getctx("ko", content=content) diff --git a/admin/tables.py b/admin/tables.py index 0226c3330..3617cadb9 100644 --- a/admin/tables.py +++ b/admin/tables.py @@ -1,5 +1,5 @@ # coding: utf-8 -from django.utils.translation import ugettext as _ +from django.utils.translation import ugettext as _, ugettext_noop from modoboa.lib import tables from templatetags.admin_extras import * @@ -7,20 +7,21 @@ class DomainsTable(tables.Table): tableid = "objects_table" idkey = "id" - name = tables.Column("name", label=_("Name")) - creation = tables.Column("creation", label=_("Created"), width="160px") - modified = tables.Column("last_modification", label=_("Last modified"), + name = tables.Column("name", label=ugettext_noop("Name")) + creation = tables.Column("creation", label=ugettext_noop("Created"), width="160px") + modified = tables.Column("last_modification", label=ugettext_noop("Last modified"), width="160px") - domaliases = tables.Column("domainalias_count", label=_("Domain aliases"), + domaliases = tables.Column("domainalias_count", label=ugettext_noop("Domain aliases"), width="100px", align="center") - mboxes = tables.Column("mailbox_count", label=_("Mailboxes"), + mboxes = tables.Column("mailbox_count", label=ugettext_noop("Mailboxes"), width="100px", align="center") - mbaliases = tables.Column("mbalias_counter", label=_("Mailbox aliases"), + mbaliases = tables.Column("mbalias_counter", label=ugettext_noop("Mailbox aliases"), width="100px", align="center") - quota = tables.Column("quota", label=_("Quota"), width="50px", align="center") - enabled = tables.Column("enabled", label=_("Enabled"), width="50px", + quota = tables.Column("quota", label=ugettext_noop("Quota"), + width="50px", align="center") + enabled = tables.Column("enabled", label=gender("Enabled", "m"), width="50px", align="center") - actions = tables.ActionColumn("actions", label=_("Actions"), width="50px", + actions = tables.ActionColumn("actions", label=ugettext_noop("Actions"), width="50px", align="center", defvalue=domain_actions) cols_order = ["name", "creation", "modified", @@ -41,15 +42,16 @@ class DomaliasesTable(tables.Table): tableid = "objects_table" idkey = "id" - name = tables.Column("name", label=_("Name")) - target = tables.Column("target", label=_("Targeted domain")) - creation = tables.Column("creation", label=_("Created"), width="170px") - modified = tables.Column("last_modification", label=_("Last modified"), + name = tables.Column("name", label=ugettext_noop("Name")) + target = tables.Column("target", label=ugettext_noop("Targeted domain")) + creation = tables.Column("creation", label=ugettext_noop("Created"), width="170px") + modified = tables.Column("last_modification", label=ugettext_noop("Last modified"), width="170px") - enabled = tables.Column("enabled", label=_("Enabled"), width="50px", + enabled = tables.Column("enabled", label=gender("Enabled", "m"), width="50px", align="center") - actions = tables.ActionColumn("actions", label=_("Actions"), width="50px", - align="center", defvalue=domalias_actions) + actions = tables.ActionColumn("actions", label=ugettext_noop("Actions"), + width="50px", align="center", + defvalue=domalias_actions) cols_order = ["name", "target", "creation", "modified", "enabled", "actions"] @@ -65,18 +67,20 @@ class MailboxesTable(tables.Table): tableid = "objects_table" idkey = "id" - address = tables.Column("address", label=_("Address")) - name = tables.Column("name", label=_("Name")) - creation = tables.Column("creation", label=_("Created"), width="160px") - modified = tables.Column("last_modification", label=_("Last modified"), + address = tables.Column("address", label=ugettext_noop("Address")) + name = tables.Column("name", label=ugettext_noop("Name")) + creation = tables.Column("creation", label=ugettext_noop("Created"), width="160px") - aliases = tables.Column("alias_count", label=_("Aliases"), width="70px", + modified = tables.Column("last_modification", label=ugettext_noop("Last modified"), + width="160px") + aliases = tables.Column("alias_count", label=ugettext_noop("Aliases"), width="70px", align="center") - quota = tables.Column("quota", label=_("Quota"), width="50px", align="center") + quota = tables.Column("quota", label=ugettext_noop("Quota"), + width="50px", align="center") enabled = tables.Column("enabled", label=gender("Enabled", "f"), width="50px", align="center") - actions = tables.ActionColumn("actions", label=_("Actions"), width="70px", - align="center", defvalue=mailbox_actions) + actions = tables.ActionColumn("actions", label=ugettext_noop("Actions"), + width="70px", align="center", defvalue=mailbox_actions) cols_order = ["address", "name", "creation", "modified", "aliases", "quota", "enabled", "actions"] @@ -95,14 +99,14 @@ class MbaliasesTable(tables.Table): tableid = "objects_table" idkey = "id" - address = tables.Column("full_address", label=_("Address")) - targets = tables.Column("targets", label=_("Target(s)"), safe=True) - creation = tables.Column("creation", label=_("Created"), width="170px") - modified = tables.Column("last_modification", label=_("Last modified"), + address = tables.Column("full_address", label=ugettext_noop("Address")) + targets = tables.Column("targets", label=ugettext_noop("Target(s)"), safe=True) + creation = tables.Column("creation", label=ugettext_noop("Created"), width="170px") + modified = tables.Column("last_modification", label=ugettext_noop("Last modified"), width="170px") enabled = tables.Column("enabled", label=gender("Enabled", "m"), width="50px", align="center") - actions = tables.ActionColumn("actions", label=_("Actions"), width="50px", + actions = tables.ActionColumn("actions", label=ugettext_noop("Actions"), width="50px", align="center", defvalue=mbalias_actions) cols_order = ["address", "targets", "creation", "modified", "enabled", "actions"] @@ -120,8 +124,29 @@ class MbaliasesTable(tables.Table): class ExtensionsTable(tables.Table): idkey = "id" selection = tables.SelectionColumn("selection", width="4%", first=True) - name = tables.Column("name", label=_("Name"), width="15%") - version = tables.Column("version", label=_("Version"), width="6%") - descr = tables.Column("description", label=_("Description")) + name = tables.Column("name", label=ugettext_noop("Name"), width="15%") + version = tables.Column("version", label=ugettext_noop("Version"), width="6%") + descr = tables.Column("description", label=ugettext_noop("Description")) cols_order = ["selection", "name", "version", "descr"] + +class SuperAdminsTable(tables.Table): + idkey = "id" + selection = tables.SelectionColumn("selection", width="4%", first=True) + user_name = tables.Column("user_name", label=ugettext_noop("User name")) + full_name = tables.Column("full_name", label=ugettext_noop("Full name")) + date_joined = tables.Column("date_joined", label=ugettext_noop("Defined")) + enabled = tables.Column("enabled", label=gender("Enabled", "m"), width="10%") + + cols_order = ["selection", "user_name", "full_name", "date_joined", "enabled"] + +class DomainAdminsTable(tables.Table): + idkey = "id" + selection = tables.SelectionColumn("selection", width="4%", first=True) + domain = tables.Column("domain", label=ugettext_noop("Domain")) + full_name = tables.Column("full_name", label=ugettext_noop("Full name")) + date_joined = tables.Column("date_joined", label=ugettext_noop("Defined")) + enabled = tables.Column("enabled", label=gender("Enabled", "m"), width="10%") + + cols_order = ["selection", "domain", "full_name", "date_joined", "enabled"] + diff --git a/admin/templatetags/admin_extras.py b/admin/templatetags/admin_extras.py index e795d99f2..296ae16b1 100644 --- a/admin/templatetags/admin_extras.py +++ b/admin/templatetags/admin_extras.py @@ -1,6 +1,6 @@ from django import template from django.template.loader import render_to_string -from django.utils.translation import ugettext as _ +from django.utils.translation import ugettext as _, ugettext_noop from django.core.urlresolvers import reverse from modoboa import admin from modoboa.lib import events @@ -9,7 +9,7 @@ from modoboa.lib.webutils import static_url, render_actions register = template.Library() genders = { - "Enabled" : (_("enabled_m"), _("enabled_f")) + "Enabled" : (ugettext_noop("enabled_m"), ugettext_noop("enabled_f")) } @register.simple_tag @@ -214,7 +214,7 @@ def loadadminextmenu(user): def param(app, definition): result = """