config: Use AppView and cleanup custom code

- Follow common code so that extending becomes easier.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2019-10-23 10:56:36 -07:00 committed by James Valleroy
parent 62115dcd1e
commit dd1884e8ab
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
4 changed files with 16 additions and 80 deletions

View File

@ -22,7 +22,7 @@ import os
import socket
import augeas
from django.utils.translation import ugettext_lazy
from django.utils.translation import ugettext_lazy as _
from plinth import actions
from plinth import app as app_module
@ -34,6 +34,8 @@ version = 2
is_essential = True
name = _('General Configuration')
depends = ['firewall', 'names']
manual_page = 'Configure'
@ -57,14 +59,12 @@ class ConfigApp(app_module.App):
def __init__(self):
"""Create components for the app."""
super().__init__()
menu_item = menu.Menu('menu-config', ugettext_lazy('Configure'), None,
'fa-cog', 'config:index',
parent_url_name='system')
menu_item = menu.Menu('menu-config', _('Configure'), None, 'fa-cog',
'config:index', parent_url_name='system')
self.add(menu_item)
domain_type = DomainType('domain-type-static',
ugettext_lazy('Domain Name'), 'config:index',
can_have_certificate=True)
domain_type = DomainType('domain-type-static', _('Domain Name'),
'config:index', can_have_certificate=True)
self.add(domain_type)

View File

@ -1,48 +0,0 @@
{% extends "base.html" %}
{% comment %}
#
# This file is part of FreedomBox.
#
# 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 <http://www.gnu.org/licenses/>.
#
{% endcomment %}
{% load bootstrap %}
{% load i18n %}
{% load static %}
{% block content %}
{% block pagetitle %}
<h2>{{ title }}</h2>
{% endblock %}
{% if manual_page %}
<p class="manual-page">
<a href="{% url 'help:manual-page' manual_page %}">
{% trans 'Learn more...' %}
</a>
</p>
{% endif %}
<form class="form" method="post">
{% csrf_token %}
{{ form|bootstrap }}
<input type="submit" class="btn btn-primary"
value="{% trans "Submit" %}"/>
</form>
{% endblock %}

View File

@ -14,7 +14,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
URLs for the Configuration module
"""
@ -24,5 +23,5 @@ from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^sys/config/$', views.index, name='index'),
url(r'^sys/config/$', views.ConfigAppView.as_view(), name='index'),
]

View File

@ -21,10 +21,9 @@ FreedomBox views for basic system configuration.
import logging
from django.contrib import messages
from django.template.response import TemplateResponse
from django.utils.translation import ugettext as _
from plinth import actions
from plinth import actions, views
from plinth.modules import config
from plinth.signals import (domain_added, domain_removed, post_hostname_change,
pre_hostname_change)
@ -34,27 +33,13 @@ from .forms import ConfigurationForm
LOGGER = logging.getLogger(__name__)
def index(request):
"""Serve the configuration form"""
status = get_status()
if request.method == 'POST':
form = ConfigurationForm(request.POST, initial=status,
prefix='configuration')
# pylint: disable-msg=E1101
if form.is_valid():
_apply_changes(request, status, form.cleaned_data)
status = get_status()
form = ConfigurationForm(initial=status, prefix='configuration')
else:
form = ConfigurationForm(initial=status, prefix='configuration')
return TemplateResponse(
request, 'config.html', {
'title': _('General Configuration'),
'form': form,
'manual_page': config.manual_page
})
class ConfigAppView(views.AppView):
"""Serve configuration page."""
name = config.name
form_class = ConfigurationForm
app_id = 'config'
manual_page = config.manual_page
show_status_block = False
def get_status():