From a002ca300cc7cf25b6b14bd4cacba6c9edad3fa5 Mon Sep 17 00:00:00 2001
From: Joel Valleroy
Date: Thu, 26 Nov 2015 17:05:34 -0500
Subject: [PATCH] Use POST for reboot/shutdown now
---
plinth/modules/power/templates/power.html | 23 +++++---------
.../modules/power/templates/power_reboot.html | 5 ++-
.../power/templates/power_shutdown.html | 4 ++-
plinth/modules/power/urls.py | 2 --
plinth/modules/power/views.py | 31 ++++++++++++-------
5 files changed, 34 insertions(+), 31 deletions(-)
diff --git a/plinth/modules/power/templates/power.html b/plinth/modules/power/templates/power.html
index d91582f46..376715ad5 100644
--- a/plinth/modules/power/templates/power.html
+++ b/plinth/modules/power/templates/power.html
@@ -31,21 +31,14 @@
{% endblocktrans %}
-
-
-
-
-
+
+
+ {% trans "Reboot..." %}
+
+
+
+ {% trans "Shut Down..." %}
+
{% endblock %}
diff --git a/plinth/modules/power/templates/power_reboot.html b/plinth/modules/power/templates/power_reboot.html
index 7e79ee8f5..4733a095d 100644
--- a/plinth/modules/power/templates/power_reboot.html
+++ b/plinth/modules/power/templates/power_reboot.html
@@ -31,11 +31,14 @@
{% endblocktrans %}
-
{% endblock %}
diff --git a/plinth/modules/power/templates/power_shutdown.html b/plinth/modules/power/templates/power_shutdown.html
index 7acb4f529..8b66bfbba 100644
--- a/plinth/modules/power/templates/power_shutdown.html
+++ b/plinth/modules/power/templates/power_shutdown.html
@@ -31,9 +31,11 @@
{% endblocktrans %}
-
diff --git a/plinth/modules/power/urls.py b/plinth/modules/power/urls.py
index e5f33d039..d37708ca5 100644
--- a/plinth/modules/power/urls.py
+++ b/plinth/modules/power/urls.py
@@ -25,7 +25,5 @@ urlpatterns = patterns(
'plinth.modules.power.views',
url(r'^sys/power/$', 'index', name='index'),
url(r'^sys/power/reboot$', 'reboot', name='reboot'),
- url(r'^sys/power/reboot/now$', 'reboot_now', name='reboot_now'),
url(r'^sys/power/shutdown$', 'shutdown', name='shutdown'),
- url(r'^sys/power/shutdown/now$', 'shutdown_now', name='shutdown_now'),
)
diff --git a/plinth/modules/power/views.py b/plinth/modules/power/views.py
index d844f9498..007233a5a 100644
--- a/plinth/modules/power/views.py
+++ b/plinth/modules/power/views.py
@@ -19,6 +19,7 @@
Plinth module for power module.
"""
+from django.forms import Form
from django.template.response import TemplateResponse
from django.utils.translation import ugettext as _
@@ -33,21 +34,27 @@ def index(request):
def reboot(request):
"""Serve reboot confirmation page."""
+ form = None
+
+ if request.method == 'POST':
+ actions.superuser_run('power', ['reboot'])
+ else:
+ form = Form(prefix='power')
+
return TemplateResponse(request, 'power_reboot.html',
- {'title': _('Power Control')})
-
-
-def reboot_now(request):
- """Reboot the system."""
- actions.superuser_run('power', ['reboot'])
+ {'title': _('Power Control'),
+ 'form': form})
def shutdown(request):
"""Serve shutdown confirmation page."""
+ form = None
+
+ if request.method == 'POST':
+ actions.superuser_run('power', ['shutdown'])
+ else:
+ form = Form(prefix='power')
+
return TemplateResponse(request, 'power_shutdown.html',
- {'title': _('Power Control')})
-
-
-def shutdown_now(request):
- """Shutdown the system."""
- actions.superuser_run('power', ['shutdown'])
+ {'title': _('Power Control'),
+ 'form': form})