Fix network tests, add form help and validator.

This commit is contained in:
James Valleroy authored and Sunil Mohan Adapa committed 2015-04-06 22:21:29 +05:30
1 parent 45086ff003
commit 8d9b388375
5 files changed
+67 -26

No files matched your search

+18 -3
View File
@@ -16,6 +16,7 @@
#
from django import forms
from django.core import validators
from gettext import gettext as _
from plinth import network
@@ -33,11 +34,16 @@ class AddEthernetForm(forms.Form):
name = forms.CharField(label=_('Connection Name'))
zone = forms.ChoiceField(
label=_('Firewall Zone'),
help_text=_('The firewall zone will control which services are \
available over this interfaces. Select Internal only for trusted networks.'),
choices=[('external', 'External'), ('internal', 'Internal')])
ipv4_method = forms.ChoiceField(
label=_('IPv4 Addressing Method'),
choices=[('auto', 'Automatic (DHCP)'), ('manual', 'Manual')])
ipv4_address = forms.CharField(label=_('Address'), required=False)
ipv4_address = forms.CharField(
label=_('Address'),
validators=[validators.validate_ipv4_address],
required=False)
class AddWifiForm(forms.Form):
@@ -45,13 +51,22 @@ class AddWifiForm(forms.Form):
name = forms.CharField(label=_('Connection Name'))
zone = forms.ChoiceField(
label=_('Firewall Zone'),
help_text=_('The firewall zone will control which services are \
available over this interfaces. Select Internal only for trusted networks.'),
choices=[('external', 'External'), ('internal', 'Internal')])
ssid = forms.CharField(label=_('SSID'))
ssid = forms.CharField(
label=_('SSID'),
help_text=_('The visible name of the network.'))
auth_mode = forms.ChoiceField(
label=_('Authentication Mode'),
help_text=_('Select WPA if the wireless network is secured and \
requires clients to have the password to connect.'),
choices=[('wpa', 'WPA'), ('open', 'Open')])
passphrase = forms.CharField(label=_('Passphrase'), required=False)
ipv4_method = forms.ChoiceField(
label=_('IPv4 Addressing Method'),
choices=[('auto', 'Automatic (DHCP)'), ('manual', 'Manual')])
ipv4_address = forms.CharField(label=_('Address'), required=False)
ipv4_address = forms.CharField(
label=_('Address'),
validators=[validators.validate_ipv4_address],
required=False)
+5 -1
View File
@@ -15,7 +15,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from dbus.exceptions import DBusException
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.core.urlresolvers import reverse_lazy
@@ -100,6 +99,11 @@ def edit(request, conn_id):
_('Cannot edit connection %s: '
'Connection type not supported.') % name)
return redirect(reverse_lazy('networks:index'))
else:
return TemplateResponse(request, 'connections_edit.html',
{'title': _('Edit Connection'),
'subsubmenu': subsubmenu,
'form': form})
else:
try:
form_data['zone'] = settings['connection']['zone']
@@ -42,16 +42,19 @@
<script type="text/javascript">
(function($) {
$('#id_ipv4_address').prop("readOnly", true);
$('#id_name').focus();
if ($("#id_ipv4_method").prop("value") != "manual") {
$("#id_ipv4_address").prop("readOnly", true);
}
$("#id_name").focus();
$('#id_ipv4_method').change(function() {
if ($('#id_ipv4_method').prop('value') == 'manual') {
$('#id_ipv4_address').prop("readOnly", false);
$('#id_ipv4_address').prop("required", true);
$("#id_ipv4_method").change(function() {
if ($("#id_ipv4_method").prop("value") == 'manual') {
$("#id_ipv4_address").prop("readOnly", false);
$("#id_ipv4_address").prop("required", true);
} else {
$('#id_ipv4_address').prop("readOnly", true);
$('#id_ipv4_address').prop("required", false);
$("#id_ipv4_address").val("");
$("#id_ipv4_address").prop("readOnly", true);
$("#id_ipv4_address").prop("required", false);
}
});
@@ -42,18 +42,19 @@
<script type="text/javascript">
(function($) {
if ($('#id_ipv4_method').prop('value') != 'manual') {
$('#id_ipv4_address').prop("readOnly", true);
if ($("#id_ipv4_method").prop("value") != "manual") {
$("#id_ipv4_address").prop("readOnly", true);
}
$('#id_name').focus();
$("#id_name").focus();
$('#id_ipv4_method').change(function() {
if ($('#id_ipv4_method').prop('value') == 'manual') {
$('#id_ipv4_address').prop("readOnly", false);
$('#id_ipv4_address').prop("required", true);
$("#id_ipv4_method").change(function() {
if ($("#id_ipv4_method").prop("value") == "manual") {
$("#id_ipv4_address").prop("readOnly", false);
$("#id_ipv4_address").prop("required", true);
} else {
$('#id_ipv4_address').prop("readOnly", true);
$('#id_ipv4_address').prop("required", false);
$("#id_ipv4_address").val("");
$("#id_ipv4_address").prop("readOnly", true);
$("#id_ipv4_address").prop("required", false);
}
});