diff --git a/plinth/modules/avahi/__init__.py b/plinth/modules/avahi/__init__.py
index c4c0970bc..f53ce9566 100644
--- a/plinth/modules/avahi/__init__.py
+++ b/plinth/modules/avahi/__init__.py
@@ -21,6 +21,7 @@ Plinth module for service discovery.
from django.utils.translation import ugettext_lazy as _
+from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import service as service_module
@@ -65,6 +66,12 @@ def setup(helper, old_version=False):
helper.install(['avahi-daemon'])
+def get_status():
+ """Get the current settings from server."""
+ return {'enabled': is_enabled(),
+ 'is_running': is_running()}
+
+
def is_enabled():
"""Return whether the module is enabled."""
return action_utils.service_is_enabled('avahi-daemon')
@@ -73,3 +80,10 @@ def is_enabled():
def is_running():
"""Return whether the service is running."""
return action_utils.service_is_running('avahi-daemon')
+
+
+def enable(should_enable):
+ """Enable/disable the module."""
+ sub_command = 'enable' if should_enable else 'disable'
+ actions.superuser_run('avahi', [sub_command])
+ service.notify_enabled(None, should_enable)
diff --git a/plinth/modules/avahi/forms.py b/plinth/modules/avahi/forms.py
deleted file mode 100644
index 66776d0c0..000000000
--- a/plinth/modules/avahi/forms.py
+++ /dev/null
@@ -1,30 +0,0 @@
-#
-# This file is part of Plinth.
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see .
-#
-
-"""
-Plinth module for service discovery forms.
-"""
-
-from django import forms
-from django.utils.translation import ugettext_lazy as _
-
-
-class ServiceDiscoveryForm(forms.Form):
- """Service discovery form."""
- enabled = forms.BooleanField(
- label=_('Enable service discovery'),
- required=False)
diff --git a/plinth/modules/avahi/urls.py b/plinth/modules/avahi/urls.py
index d9f84d89d..9a86c45f6 100644
--- a/plinth/modules/avahi/urls.py
+++ b/plinth/modules/avahi/urls.py
@@ -21,9 +21,10 @@ URLs for the service discovery module.
from django.conf.urls import url
-from . import views
+from plinth.views import ConfigurationView
urlpatterns = [
- url(r'^sys/avahi/$', views.index, name='index'),
+ url(r'^sys/avahi/$', ConfigurationView.as_view(module_name='avahi'),
+ name='index'),
]
diff --git a/plinth/modules/avahi/views.py b/plinth/modules/avahi/views.py
deleted file mode 100644
index 77751abca..000000000
--- a/plinth/modules/avahi/views.py
+++ /dev/null
@@ -1,75 +0,0 @@
-#
-# This file is part of Plinth.
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see .
-#
-
-"""
-Plinth module for service discovery views.
-"""
-
-from django.contrib import messages
-from django.template.response import TemplateResponse
-from django.utils.translation import ugettext as _
-import logging
-
-from .forms import ServiceDiscoveryForm
-from plinth import actions
-from plinth.modules import avahi
-
-
-logger = logging.getLogger(__name__) # pylint: disable=C0103
-
-
-def index(request):
- """Serve configuration page."""
- status = get_status()
-
- form = None
-
- if request.method == 'POST':
- form = ServiceDiscoveryForm(request.POST, prefix='avahi')
- if form.is_valid():
- _apply_changes(request, status, form.cleaned_data)
- status = get_status()
- form = ServiceDiscoveryForm(initial=status, prefix='avahi')
- else:
- form = ServiceDiscoveryForm(initial=status, prefix='avahi')
-
- return TemplateResponse(request, 'avahi.html',
- {'title': avahi.title,
- 'description': avahi.description,
- 'status': status,
- 'form': form})
-
-
-def get_status():
- """Get the current settings from server."""
- return {'enabled': avahi.is_enabled(),
- 'is_running': avahi.is_running()}
-
-
-def _apply_changes(request, old_status, new_status):
- """Apply the changes."""
- modified = False
-
- if old_status['enabled'] != new_status['enabled']:
- sub_command = 'enable' if new_status['enabled'] else 'disable'
- modified = True
- actions.superuser_run('avahi', [sub_command])
- avahi.service.notify_enabled(None, new_status['enabled'])
- messages.success(request, _('Configuration updated'))
-
- if not modified:
- messages.info(request, _('Setting unchanged'))