Permalink
Browse files

Translate forgotten strings

While I'm here do a PEP8 cleanup
  • Loading branch information...
1 parent fe89e89 commit 6d8e144020bb169dae1c6f485ba53e08cf2f1193 @william-gr william-gr committed Jun 28, 2013
Showing with 187 additions and 117 deletions.
  1. +187 −117 gui/system/forms.py
View
304 gui/system/forms.py
@@ -45,7 +45,7 @@
from dojango import forms
from freenasUI import choices
from freenasUI.common.forms import ModelForm, Form
-from freenasUI.freeadmin.forms import CronMultiple, DirectoryBrowser
+from freenasUI.freeadmin.forms import CronMultiple
from freenasUI.middleware.exceptions import MiddlewareError
from freenasUI.middleware.notifier import notifier
from freenasUI.storage.models import MountPoint
@@ -98,38 +98,44 @@ def done(self, form_list, **kwargs):
'retval': getattr(self, 'retval', None),
})
if not self.request.is_ajax():
- response.content = ("<html><body><textarea>"
- + response.content +
- "</textarea></boby></html>")
+ response.content = (
+ "<html><body><textarea>"
+ + response.content +
+ "</textarea></boby></html>"
+ )
return response
def get_template_names(self):
return [
'system/wizard_%s.html' % self.get_step_index(),
'system/wizard.html',
- ]
+ ]
def process_step(self, form):
proc = super(FileWizard, self).process_step(form)
"""
We execute the form done method if there is one, for each step
"""
if hasattr(form, 'done'):
- retval = form.done(request=self.request,
+ retval = form.done(
+ request=self.request,
form_list=self.form_list,
wizard=self)
if self.get_step_index() == self.steps.count - 1:
self.retval = retval
return proc
def render_to_response(self, context, **kwargs):
- response = super(FileWizard, self).render_to_response(context,
+ response = super(FileWizard, self).render_to_response(
+ context,
**kwargs)
# This is required for the workaround dojo.io.frame for file upload
if not self.request.is_ajax():
- return HttpResponse("<html><body><textarea>"
- + response.rendered_content +
- "</textarea></boby></html>")
+ return HttpResponse(
+ "<html><body><textarea>"
+ + response.rendered_content +
+ "</textarea></boby></html>"
+ )
return response
@@ -174,9 +180,11 @@ def done(self, form_list, **kwargs):
'retval': getattr(self, 'retval', None),
})
if not self.request.is_ajax():
- response.content = ("<html><body><textarea>"
- + response.content +
- "</textarea></boby></html>")
+ response.content = (
+ "<html><body><textarea>"
+ + response.content +
+ "</textarea></boby></html>"
+ )
return response
@@ -195,19 +203,27 @@ def __init__(self, *args, **kwargs):
self.instance._original_stg_guiprotocol = self.instance.stg_guiprotocol
self.instance._original_stg_guiaddress = self.instance.stg_guiaddress
self.instance._original_stg_guiport = self.instance.stg_guiport
- self.instance._original_stg_syslogserver = self.instance.stg_syslogserver
- self.instance._original_stg_directoryservice = self.instance.stg_directoryservice
+ self.instance._original_stg_syslogserver = (
+ self.instance.stg_syslogserver
+ )
+ self.instance._original_stg_directoryservice = (
+ self.instance.stg_directoryservice
+ )
self.fields['stg_language'].choices = settings.LANGUAGES
self.fields['stg_language'].label = _("Language (Require UI reload)")
self.fields['stg_guiaddress'] = forms.ChoiceField(
label=self.fields['stg_guiaddress'].label
- )
- self.fields['stg_guiaddress'].choices = [['0.0.0.0', '0.0.0.0']] + list(choices.IPChoices(ipv6=False))
+ )
+ self.fields['stg_guiaddress'].choices = [
+ ['0.0.0.0', '0.0.0.0']
+ ] + list(choices.IPChoices(ipv6=False))
self.fields['stg_guiv6address'] = forms.ChoiceField(
label=self.fields['stg_guiv6address'].label
- )
- self.fields['stg_guiv6address'].choices = [['::', '::']] + list(choices.IPChoices(ipv4=False))
+ )
+ self.fields['stg_guiv6address'].choices = [
+ ['::', '::']
+ ] + list(choices.IPChoices(ipv4=False))
def clean_stg_guiport(self):
val = self.cleaned_data.get("stg_guiport")
@@ -216,7 +232,9 @@ def clean_stg_guiport(self):
try:
val = int(val)
if val < 1 or val > 65535:
- raise forms.ValidationError(_("You must specify a number between 1 and 65535, inclusive."))
+ raise forms.ValidationError(_(
+ "You must specify a number between 1 and 65535, inclusive."
+ ))
except ValueError:
raise forms.ValidationError(_("Number is required."))
return val
@@ -226,24 +244,28 @@ def save(self):
if self.instance._original_stg_syslogserver != self.instance.stg_syslogserver:
notifier().restart("syslogd")
notifier().reload("timeservices")
- if self.instance._original_stg_directoryservice != self.instance.stg_directoryservice \
- and self.instance._original_stg_directoryservice:
- method = getattr(notifier(), "_stop_%s" % \
- self.instance._original_stg_directoryservice)
- method()
-
+ if (
+ self.instance._original_stg_directoryservice != self.instance.stg_directoryservice
+ and self.instance._original_stg_directoryservice
+ ):
+ getattr(notifier(), "_stop_%s" % (
+ self.instance._original_stg_directoryservice
+ ))()
def done(self, request, events):
- if self.instance._original_stg_guiprotocol != self.instance.stg_guiprotocol or \
- self.instance._original_stg_guiaddress != self.instance.stg_guiaddress or \
- self.instance._original_stg_guiport != self.instance.stg_guiport:
+ if (
+ self.instance._original_stg_guiprotocol != self.instance.stg_guiprotocol or
+ self.instance._original_stg_guiaddress != self.instance.stg_guiaddress or
+ self.instance._original_stg_guiport != self.instance.stg_guiport
+ ):
if self.instance.stg_guiaddress == "0.0.0.0":
address = request.META['HTTP_HOST'].split(':')[0]
else:
address = self.instance.stg_guiaddress
- newurl = "%s://%s" % (self.instance.stg_guiprotocol,
- address
- )
+ newurl = "%s://%s" % (
+ self.instance.stg_guiprotocol,
+ address
+ )
if self.instance.stg_guiport != '':
newurl += ":" + self.instance.stg_guiport
if self.instance._original_stg_guiprotocol == 'http':
@@ -264,8 +286,11 @@ def __init__(self, *args, **kwargs):
def clean_ntp_address(self):
addr = self.cleaned_data.get("ntp_address")
- p1 = subprocess.Popen(["ntpq", "-c", "rv", addr],
- stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ p1 = subprocess.Popen(
+ ["ntpq", "-c", "rv", addr],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE
+ )
data = p1.communicate()[0]
#TODO: ntpq does not return error code in case of errors
if not re.search(r'version=', data):
@@ -276,13 +301,18 @@ def clean_ntp_maxpoll(self):
maxp = self.cleaned_data.get("ntp_maxpoll")
minp = self.cleaned_data.get("ntp_minpoll")
if not maxp > minp:
- raise forms.ValidationError(_("Max Poll should be higher than Min Poll"))
+ raise forms.ValidationError(_(
+ "Max Poll should be higher than Min Poll"
+ ))
return maxp
def clean(self):
cdata = self.cleaned_data
if not cdata.get("force", False) and not self.usable:
- self._errors['ntp_address'] = self.error_class([_("Server could not be reached. Check \"Force\" to continue regardless.")])
+ self._errors['ntp_address'] = self.error_class([_(
+ "Server could not be reached. Check \"Force\" to continue "
+ "regardless."
+ )])
del cdata['ntp_address']
return cdata
@@ -295,18 +325,29 @@ def save(self):
class AdvancedForm(ModelForm):
class Meta:
- exclude = ('adv_zeroconfbonjour', 'adv_tuning', 'adv_firmwarevc', 'adv_systembeep')
+ exclude = (
+ 'adv_zeroconfbonjour',
+ 'adv_tuning',
+ 'adv_firmwarevc',
+ 'adv_systembeep',
+ )
model = models.Advanced
def __init__(self, *args, **kwargs):
super(AdvancedForm, self).__init__(*args, **kwargs)
self.instance._original_adv_motd = self.instance.adv_motd
self.instance._original_adv_consolemenu = self.instance.adv_consolemenu
self.instance._original_adv_powerdaemon = self.instance.adv_powerdaemon
- self.instance._original_adv_serialconsole = self.instance.adv_serialconsole
- self.instance._original_adv_consolescreensaver = self.instance.adv_consolescreensaver
+ self.instance._original_adv_serialconsole = (
+ self.instance.adv_serialconsole
+ )
+ self.instance._original_adv_consolescreensaver = (
+ self.instance.adv_consolescreensaver
+ )
self.instance._original_adv_consolemsg = self.instance.adv_consolemsg
- self.instance._original_adv_advancedmode = self.instance.adv_advancedmode
+ self.instance._original_adv_advancedmode = (
+ self.instance.adv_advancedmode
+ )
self.instance._original_adv_autotune = self.instance.adv_autotune
self.instance._original_adv_debugkernel = self.instance.adv_debugkernel
@@ -380,46 +421,55 @@ def __init__(self, *args, **kwargs):
self.fields['em_pass2'].initial = self.instance.em_pass
except:
pass
- self.fields['em_smtp'].widget.attrs['onChange'] = ('javascript:'
+ self.fields['em_smtp'].widget.attrs['onChange'] = (
'toggleGeneric("id_em_smtp", ["id_em_pass1", "id_em_pass2", '
- '"id_em_user"], true);')
+ '"id_em_user"], true);'
+ )
ro = True
if len(self.data) > 0:
if self.data.get("em_smtp", None) == "on":
ro = False
else:
- if self.instance.em_smtp == True:
+ if self.instance.em_smtp is True:
ro = False
if ro:
self.fields['em_user'].widget.attrs['disabled'] = 'disabled'
self.fields['em_pass1'].widget.attrs['disabled'] = 'disabled'
self.fields['em_pass2'].widget.attrs['disabled'] = 'disabled'
def clean_em_user(self):
- if self.cleaned_data['em_smtp'] == True and \
- self.cleaned_data['em_user'] == "":
+ if (
+ self.cleaned_data['em_smtp'] is True and
+ self.cleaned_data['em_user'] == ""
+ ):
raise forms.ValidationError(_("This field is required"))
return self.cleaned_data['em_user']
def clean_em_pass1(self):
- if self.cleaned_data['em_smtp'] == True and \
- self.cleaned_data['em_pass1'] == "":
+ if (
+ self.cleaned_data['em_smtp'] is True and
+ self.cleaned_data['em_pass1'] == ""
+ ):
if self.instance.em_pass:
return self.instance.em_pass
raise forms.ValidationError(_("This field is required"))
return self.cleaned_data['em_pass1']
def clean_em_pass2(self):
- if self.cleaned_data['em_smtp'] == True and \
- self.cleaned_data.get('em_pass2', "") == "":
+ if (
+ self.cleaned_data['em_smtp'] is True and
+ self.cleaned_data.get('em_pass2', "") == ""
+ ):
if self.instance.em_pass:
return self.instance.em_pass
raise forms.ValidationError(_("This field is required"))
pass1 = self.cleaned_data.get("em_pass1", "")
pass2 = self.cleaned_data.get("em_pass2", "")
if pass1 != pass2:
- raise forms.ValidationError(_("The two password fields didn't match."))
+ raise forms.ValidationError(
+ _("The two password fields didn't match.")
+ )
return pass2
def save(self, commit=True):
@@ -431,17 +481,18 @@ def save(self, commit=True):
class SSLForm(ModelForm):
- ssl_passphrase2 = forms.CharField(max_length=120,
- label=_("Confirm Passphrase"),
- widget=forms.widgets.PasswordInput(),
- required=False,
- )
+ ssl_passphrase2 = forms.CharField(
+ max_length=120,
+ label=_("Confirm Passphrase"),
+ widget=forms.widgets.PasswordInput(),
+ required=False,
+ )
class Meta:
model = models.SSL
widgets = {
'ssl_passphrase': forms.widgets.PasswordInput(render_value=False),
- }
+ }
def __init__(self, *args, **kwargs):
super(SSLForm, self).__init__(*args, **kwargs)
@@ -456,15 +507,17 @@ def __init__(self, *args, **kwargs):
'ssl_passphrase',
'ssl_passphrase2',
'ssl_certfile',
- ]
+ ]
if self.instance.ssl_passphrase:
self.fields['ssl_passphrase'].required = False
def clean_ssl_passphrase2(self):
passphrase1 = self.cleaned_data.get("ssl_passphrase")
passphrase2 = self.cleaned_data.get("ssl_passphrase2")
if passphrase1 != passphrase2:
- raise forms.ValidationError(_("The two passphrase fields didn't match."))
+ raise forms.ValidationError(
+ _("The two passphrase fields didn't match.")
+ )
return passphrase2
def get_x509_modulus(self, x509_file_path):
@@ -477,10 +530,7 @@ def get_x509_modulus(self, x509_file_path):
"-noout",
"-modulus",
"-in", x509_file_path,
- ],
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- )
+ ], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
modulus, err = proc.communicate()
if proc.returncode != 0:
@@ -498,10 +548,7 @@ def get_key_modulus(self, key_file_path, type='rsa'):
"-noout",
"-modulus",
"-in", key_file_path,
- ],
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- )
+ ], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
modulus, err = proc.communicate()
if proc.returncode != 0:
@@ -517,11 +564,12 @@ def clean_ssl_certfile(self):
r'(-----BEGIN ([DR]SA) PRIVATE KEY-----.*?'
r'-----END \2 PRIVATE KEY-----)',
certfile,
- re.M|re.S)
+ re.M | re.S
+ )
if not reg:
raise forms.ValidationError(
_("RSA or DSA private key not found")
- )
+ )
priv = reg.group()
priv_file = tempfile.mktemp(dir='/tmp/')
@@ -543,7 +591,8 @@ def clean_ssl_certfile(self):
r'(-----BEGIN CERTIFICATE-----.*?'
r'-----END CERTIFICATE-----)',
certfile,
- re.M|re.S)
+ re.M | re.S
+ )
verified = False
for cert in reg:
@@ -560,7 +609,7 @@ def clean_ssl_certfile(self):
if not verified:
raise forms.ValidationError(
_("The modulus of certificate and key must match")
- )
+ )
return certfile
@@ -582,16 +631,18 @@ class Meta:
widgets = {
'smarttest_hour': CronMultiple(
attrs={'numChoices': 24, 'label': _("hour")}
- ),
+ ),
'smarttest_daymonth': CronMultiple(
- attrs={'numChoices': 31, 'start': 1, 'label': _("day of month")}
- ),
+ attrs={
+ 'numChoices': 31, 'start': 1, 'label': _("day of month"),
+ }
+ ),
'smarttest_dayweek': forms.CheckboxSelectMultiple(
choices=choices.WEEKDAYS_CHOICES
- ),
+ ),
'smarttest_month': forms.CheckboxSelectMultiple(
choices=choices.MONTHS_CHOICES
- ),
+ ),
}
def __init__(self, *args, **kwargs):
@@ -657,30 +708,30 @@ def clean(self):
qs = models.SMARTTest.objects.filter(
smarttest_disks__in=[disk],
smarttest_type=test,
- )
+ )
if self.instance.id:
qs = qs.exclude(id=self.instance.id)
if qs.count() > 0:
used_disks.append(disk.disk_name)
if used_disks:
- self._errors['smarttest_disks'] = self.error_class([
- _("The following disks already have tests for this type: "
- "%s" % (
- ', '.join(used_disks),
- )),
- ])
+ self._errors['smarttest_disks'] = self.error_class([_(
+ "The following disks already have tests for this type: %s" % (
+ ', '.join(used_disks),
+ )),
+ ])
self.cleaned_data.pop("smarttest_disks", None)
return self.cleaned_data
class FirmwareTemporaryLocationForm(Form):
mountpoint = forms.ChoiceField(
label=_("Place to temporarily place firmware file"),
- help_text=_("The system will use this place to temporarily store the "
+ help_text=_(
+ "The system will use this place to temporarily store the "
"firmware file before it's being applied."),
choices=(),
widget=forms.Select(attrs={'class': 'required'}),
- )
+ )
def clean_mountpoint(self):
mp = self.cleaned_data.get("mountpoint")
@@ -691,7 +742,10 @@ def clean_mountpoint(self):
def __init__(self, *args, **kwargs):
super(FirmwareTemporaryLocationForm, self).__init__(*args, **kwargs)
- self.fields['mountpoint'].choices = [(x.mp_path, x.mp_path) for x in MountPoint.objects.exclude(mp_volume__vol_fstype='iscsi')]
+ self.fields['mountpoint'].choices = [
+ (x.mp_path, x.mp_path)
+ for x in MountPoint.objects.exclude(mp_volume__vol_fstype='iscsi')
+ ]
self.fields['mountpoint'].choices.append(
(':temp:', _('Memory device'))
)
@@ -706,7 +760,10 @@ def done(self, *args, **kwargs):
class FirmwareUploadForm(Form):
firmware = FileField(label=_("New image to be installed"), required=True)
- sha256 = forms.CharField(label=_("SHA256 sum for the image"), required=True)
+ sha256 = forms.CharField(
+ label=_("SHA256 sum for the image"),
+ required=True
+ )
class ConfigUploadForm(Form):
@@ -721,19 +778,21 @@ class Meta:
'cron_command': forms.widgets.TextInput(),
'cron_minute': CronMultiple(
attrs={'numChoices': 60, 'label': _("minute")}
- ),
+ ),
'cron_hour': CronMultiple(
attrs={'numChoices': 24, 'label': _("hour")}
- ),
+ ),
'cron_daymonth': CronMultiple(
- attrs={'numChoices': 31, 'start': 1, 'label': _("day of month")}
- ),
+ attrs={
+ 'numChoices': 31, 'start': 1, 'label': _("day of month"),
+ }
+ ),
'cron_dayweek': forms.CheckboxSelectMultiple(
choices=choices.WEEKDAYS_CHOICES
- ),
+ ),
'cron_month': forms.CheckboxSelectMultiple(
choices=choices.MONTHS_CHOICES
- ),
+ ),
}
def __init__(self, *args, **kwargs):
@@ -751,7 +810,9 @@ def clean_cron_user(self):
user = self.cleaned_data.get("cron_user")
# See #1061 or FreeBSD PR 162976
if len(user) > 17:
- raise forms.ValidationError("Usernames cannot exceed 17 characters for cronjobs")
+ raise forms.ValidationError(_(
+ "Usernames cannot exceed 17 characters for cronjobs"
+ ))
# Windows users can have spaces in their usernames
# http://www.freebsd.org/cgi/query-pr.cgi?pr=164808
if ' ' in user:
@@ -785,19 +846,21 @@ class Meta:
widgets = {
'rsync_minute': CronMultiple(
attrs={'numChoices': 60, 'label': _("minute")}
- ),
+ ),
'rsync_hour': CronMultiple(
attrs={'numChoices': 24, 'label': _("hour")}
- ),
+ ),
'rsync_daymonth': CronMultiple(
- attrs={'numChoices': 31, 'start': 1, 'label': _("day of month")}
- ),
+ attrs={
+ 'numChoices': 31, 'start': 1, 'label': _("day of month"),
+ }
+ ),
'rsync_dayweek': forms.CheckboxSelectMultiple(
choices=choices.WEEKDAYS_CHOICES
- ),
+ ),
'rsync_month': forms.CheckboxSelectMultiple(
choices=choices.MONTHS_CHOICES
- ),
+ ),
}
def __init__(self, *args, **kwargs):
@@ -810,18 +873,21 @@ def __init__(self, *args, **kwargs):
if ins.rsync_dayweek == '*':
ins.rsync_dayweek = "1,2,3,4,5,6,7"
super(RsyncForm, self).__init__(*args, **kwargs)
- self.fields['rsync_mode'].widget.attrs['onChange'] = "rsyncModeToggle();"
+ self.fields['rsync_mode'].widget.attrs['onChange'] = (
+ "rsyncModeToggle();"
+ )
def clean_rsync_user(self):
user = self.cleaned_data.get("rsync_user")
# See #1061 or FreeBSD PR 162976
if len(user) > 17:
- raise forms.ValidationError("Usernames cannot exceed 17 "
- "characters for rsync tasks")
+ raise forms.ValidationError(_(
+ "Usernames cannot exceed 17 characters for rsync tasks"
+ ))
# Windows users can have spaces in their usernames
# http://www.freebsd.org/cgi/query-pr.cgi?pr=164808
if ' ' in user:
- raise forms.ValidationError("Usernames cannot have spaces")
+ raise forms.ValidationError(_("Usernames cannot have spaces"))
return user
def clean_rsync_remotemodule(self):
@@ -873,7 +939,7 @@ def clean(self):
self._errors['rsync_user'] = self.error_class([
_("In order to use rsync over SSH you need a user<br />"
"with a public key (DSA/ECDSA/RSA) set up in home dir."),
- ])
+ ])
cdata.pop('rsync_user', None)
return cdata
@@ -907,7 +973,9 @@ def save(self):
]
assert len(filter(SYSCTL_VARNAME_FORMAT_RE.match, invalid_sysctls)) == 0
-assert len(filter(SYSCTL_VARNAME_FORMAT_RE.match, valid_sysctls)) == len(valid_sysctls)
+assert len(
+ filter(SYSCTL_VARNAME_FORMAT_RE.match, valid_sysctls)) == len(valid_sysctls
+)
"""
# NOTE:
@@ -982,57 +1050,57 @@ class DebugForm(Form):
label=_("Dump Active Directory Configuration"),
initial=True,
required=False,
- )
+ )
adcache = forms.BooleanField(
label=_("Dump (AD|LDAP) Cache"),
initial=False,
required=False,
- )
+ )
geom = forms.BooleanField(
label=_("Dump GEOM configuration"),
initial=True,
required=False,
- )
+ )
hardware = forms.BooleanField(
label=_("Dump Hardware Configuration"),
initial=True,
required=False,
- )
+ )
ldap = forms.BooleanField(
label=_("Dump LDAP Configuration"),
initial=True,
required=False,
- )
+ )
loader = forms.BooleanField(
label=_("Loader Configuration Information"),
initial=True,
required=False,
- )
+ )
network = forms.BooleanField(
label=_("Dump Network Configuration"),
initial=True,
required=False,
- )
+ )
ssl = forms.BooleanField(
label=_("Dump SSL Configuration"),
initial=True,
required=False,
- )
+ )
sysctl = forms.BooleanField(
label=_("Dump Sysctl Configuration"),
initial=True,
required=False,
- )
+ )
system = forms.BooleanField(
label=_("Dump System Information"),
initial=True,
required=False,
- )
+ )
zfs = forms.BooleanField(
label=_("Dump ZFS configuration"),
initial=True,
required=False,
- )
+ )
def get_options(self):
opts = []
@@ -1068,7 +1136,9 @@ class Meta:
def __init__(self, *args, **kwargs):
super(InitShutdownForm, self).__init__(*args, **kwargs)
- self.fields['ini_type'].widget.attrs['onChange'] = "initshutdownModeToggle();"
+ self.fields['ini_type'].widget.attrs['onChange'] = (
+ "initshutdownModeToggle();"
+ )
def clean_ini_command(self):
_type = self.cleaned_data.get("ini_type")

0 comments on commit 6d8e144

Please sign in to comment.