mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
packagekit: use TemplateView instead of FormView
For the installation procedure a TemplateView is sufficient, and the user won't be able to edit any form-data on the client-side.
This commit is contained in:
parent
b3e8e53c73
commit
e905d1a8f2
@ -1,33 +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 <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
|
|
||||||
"""
|
|
||||||
Plinth framework forms
|
|
||||||
"""
|
|
||||||
|
|
||||||
from django import forms
|
|
||||||
|
|
||||||
|
|
||||||
class PackageInstallForm(forms.Form):
|
|
||||||
"""Prompt for installation of a package.
|
|
||||||
|
|
||||||
XXX: Don't store the package list in a hidden input as it can be
|
|
||||||
modified on the client side. Use session store to store and retrieve
|
|
||||||
the package list. It has to be form specific so that multiple
|
|
||||||
instances of forms don't clash with each other.
|
|
||||||
"""
|
|
||||||
package_names = forms.CharField(widget=forms.HiddenInput)
|
|
||||||
@ -55,9 +55,6 @@
|
|||||||
|
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|
||||||
{{ form|bootstrap }}
|
|
||||||
|
|
||||||
<input type="submit" class="btn btn-md btn-primary" value="Install" />
|
<input type="submit" class="btn btn-md btn-primary" value="Install" />
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|||||||
@ -19,13 +19,11 @@
|
|||||||
Main Plinth views
|
Main Plinth views
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.http.response import HttpResponseRedirect
|
from django.http.response import HttpResponseRedirect
|
||||||
from django.views.generic.edit import FormView
|
from django.views.generic import TemplateView
|
||||||
|
|
||||||
from plinth import package as package_module
|
from plinth import package as package_module
|
||||||
from plinth.forms import PackageInstallForm
|
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
@ -36,18 +34,16 @@ def index(request):
|
|||||||
return HttpResponseRedirect(reverse('help:about'))
|
return HttpResponseRedirect(reverse('help:about'))
|
||||||
|
|
||||||
|
|
||||||
class PackageInstallView(FormView):
|
class PackageInstallView(TemplateView):
|
||||||
"""View to prompt and install packages."""
|
"""View to prompt and install packages."""
|
||||||
template_name = 'package_install.html'
|
template_name = 'package_install.html'
|
||||||
form_class = PackageInstallForm
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
"""Return the context data rendering the template."""
|
"""Return the context data rendering the template."""
|
||||||
context = super(PackageInstallView, self).get_context_data(**kwargs)
|
context = super(PackageInstallView, self).get_context_data(**kwargs)
|
||||||
|
|
||||||
if 'packages_names' not in context:
|
if 'packages_names' not in context:
|
||||||
context['package_names'] = self.kwargs.get('package_names', [])
|
context['package_names'] = self.kwargs.get('package_names', [])
|
||||||
|
|
||||||
# Package details must have been resolved before building the form
|
|
||||||
context['packages'] = [package_module.packages_resolved[package_name]
|
context['packages'] = [package_module.packages_resolved[package_name]
|
||||||
for package_name in context['package_names']]
|
for package_name in context['package_names']]
|
||||||
context['is_installing'] = \
|
context['is_installing'] = \
|
||||||
@ -56,24 +52,11 @@ class PackageInstallView(FormView):
|
|||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def get_initial(self):
|
def post(self, *args, **kwargs):
|
||||||
"""Return the initial data to be filled in the form."""
|
"""Handle installing packages
|
||||||
initial = super(PackageInstallView, self).get_initial()
|
|
||||||
try:
|
|
||||||
initial['package_names'] = ','.join(self.kwargs['package_names'])
|
|
||||||
except KeyError:
|
|
||||||
raise ImproperlyConfigured('Argument package_names must be '
|
|
||||||
'provided to PackageInstallView')
|
|
||||||
|
|
||||||
return initial
|
Start the package installation, and refresh the page every x seconds to
|
||||||
|
keep displaying PackageInstallView.get() with the installation status.
|
||||||
def form_valid(self, form):
|
|
||||||
"""Handle successful validation of the form.
|
|
||||||
|
|
||||||
Start the package installation and show this view again.
|
|
||||||
"""
|
"""
|
||||||
package_names = form.cleaned_data['package_names'].split(',')
|
package_module.start_install(self.kwargs['package_names'])
|
||||||
package_module.start_install(package_names)
|
return self.render_to_response(self.get_context_data())
|
||||||
|
|
||||||
return self.render_to_response(
|
|
||||||
self.get_context_data(package_names=package_names))
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user