Sunil Mohan Adapa 74214c18ae
*: Use Django gettext functions instead of ugettext
- ugettext functions will be removed in Django 4.0. Each use emits a warning
when running with Django 3.2. Since we have warnings enabled in developer mode,
we see quite a few messages because of this.

- ugettext is already a simple alias of gettext. So, no regressions are
expected.

Tests:

- Accessing an affected app in UI with Django 3.2 and Django 2.2 works fine.

- Using Django 3.2 there are no warnings related to removal of ugettext
functions.

- Ran regular unit tests.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-09-20 16:50:16 -04:00

51 lines
1.9 KiB
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""
FreedomBox app for configuring Shadowsocks.
"""
from django import forms
from django.utils.translation import gettext_lazy as _
from plinth.utils import format_lazy
METHODS = [('chacha20-ietf-poly1305',
format_lazy('chacha20-ietf-poly1305 ({})', _('Recommended'))),
('aes-256-gcm', format_lazy('aes-256-gcm ({})', _('Recommended'))),
('aes-192-gcm', 'aes-192-gcm'), ('aes-128-gcm', 'aes-128-gcm'),
('aes-128-ctr', 'aes-128-ctr'), ('aes-192-ctr', 'aes-192-ctr'),
('aes-256-ctr', 'aes-256-ctr'), ('aes-128-cfb', 'aes-128-cfb'),
('aes-192-cfb', 'aes-192-cfb'), ('aes-256-cfb', 'aes-256-cfb'),
('camellia-128-cfb', 'camellia-128-cfb'),
('camellia-192-cfb', 'camellia-192-cfb'),
('camellia-256-cfb', 'camellia-256-cfb'),
('chacha20-ietf', 'chacha20-ietf')]
class TrimmedCharField(forms.CharField):
"""Trim the contents of a CharField"""
def clean(self, value):
"""Clean and validate the field value"""
if value:
value = value.strip()
return super(TrimmedCharField, self).clean(value)
class ShadowsocksForm(forms.Form):
"""Shadowsocks configuration form"""
server = TrimmedCharField(label=_('Server'),
help_text=_('Server hostname or IP address'))
server_port = forms.IntegerField(label=_('Server port'), min_value=0,
max_value=65535,
help_text=_('Server port number'))
password = forms.CharField(
label=_('Password'), help_text=_('Password used to encrypt data. '
'Must match server password.'))
method = forms.ChoiceField(
label=_('Method'), choices=METHODS,
help_text=_('Encryption method. Must match setting on server.'))