mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-02-04 08:13:38 +00:00
- Merge actions is-disabled, get-frontend, get-kite and get-services into get-config. This improves the initial startup time for FreedomBox service and also the page load time for pagekite app. This also significantly simplifies the code. - Only use the pagekite service enabled status determine if pagekite is enabled. Don't use the configuration setting. - For custom services, provide additional data such as display URL from get-config action. This removes the need for additional processing prepare_service_for_display() and template tag create_pagekite_service_url. - Also reduce the number of times configuration is retrieved to 1 when loading the app view page and during startup of FreedomBox service. - Ensure that all keys of the configuration always present and use that to simplify some code. - Remove ContextMixin from view DeleteServiceView that does not need it. Use AppView and drop ContextMixin. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Veiko Aasa <veiko17@disroot.org>
65 lines
2.1 KiB
Python
65 lines
2.1 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
from django.http import HttpResponseRedirect
|
|
from django.urls import reverse, reverse_lazy
|
|
from django.utils.translation import ugettext as _
|
|
from django.views.generic import View
|
|
from django.views.generic.edit import FormView
|
|
|
|
from plinth.views import AppView
|
|
|
|
from . import utils
|
|
from .forms import (AddCustomServiceForm, ConfigurationForm,
|
|
DeleteCustomServiceForm)
|
|
|
|
|
|
class DeleteServiceView(View):
|
|
def post(self, request):
|
|
form = DeleteCustomServiceForm(request.POST)
|
|
if form.is_valid():
|
|
form.delete(request)
|
|
return HttpResponseRedirect(reverse('pagekite:index'))
|
|
|
|
|
|
class AddCustomServiceView(FormView):
|
|
"""View to add a new custom PageKite service."""
|
|
form_class = AddCustomServiceForm
|
|
template_name = 'pagekite_custom_services.html'
|
|
success_url = reverse_lazy('pagekite:index')
|
|
|
|
def get_context_data(self, *args, **kwargs):
|
|
"""Return additional context for rendering the template."""
|
|
context = super().get_context_data(*args, **kwargs)
|
|
context['title'] = _('Add custom PageKite service')
|
|
return context
|
|
|
|
def form_valid(self, form):
|
|
"""Add a custom service."""
|
|
form.save(self.request)
|
|
return super().form_valid(form)
|
|
|
|
|
|
class ConfigurationView(AppView):
|
|
app_id = 'pagekite'
|
|
template_name = 'pagekite_configure.html'
|
|
form_class = ConfigurationForm
|
|
prefix = 'pagekite'
|
|
success_url = reverse_lazy('pagekite:index')
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
"""Load and store the current configuration."""
|
|
super().__init__(*args, **kwargs)
|
|
self.config = utils.get_config()
|
|
self.initial = self.config
|
|
|
|
def get_context_data(self, *args, **kwargs):
|
|
context = super().get_context_data(*args, **kwargs)
|
|
for service in self.config['custom_services']:
|
|
service['delete_form'] = DeleteCustomServiceForm(initial=service)
|
|
context.update(self.config)
|
|
return context
|
|
|
|
def form_valid(self, form):
|
|
form.save(self.request)
|
|
return super(ConfigurationView, self).form_valid(form)
|