Use POST for reboot/shutdown now

This commit is contained in:
Joel Valleroy 2015-11-26 17:05:34 -05:00
parent eca36e6f96
commit a002ca300c
5 changed files with 34 additions and 31 deletions

View File

@ -31,21 +31,14 @@
{% endblocktrans %}
</p>
<form class="form" method="post" action="{% url 'power:reboot' %}">
{% csrf_token %}
<input type="submit" class="btn btn-primary"
value="{% trans "Reboot... &raquo;" %}"/>
</form>
</br>
<form class="form" method="post" action="{% url 'power:shutdown' %}">
{% csrf_token %}
<input type="submit" class="btn btn-primary"
value="{% trans "Shut Down... &raquo;" %}"/>
</form>
<p>
<a class="btn btn-primary btn-md" href="{% url 'power:reboot' %}">
{% trans "Reboot..." %}</a>
</p>
<p>
<a class="btn btn-primary btn-md" href="{% url 'power:shutdown' %}">
{% trans "Shut Down..." %}</a>
</p>
{% endblock %}

View File

@ -31,11 +31,14 @@
{% endblocktrans %}
</p>
<form class="form" method="post" action="{% url 'power:reboot_now' %}">
<form class="form" method="post">
{% csrf_token %}
{{ form|bootstrap }}
<input type="submit" class="btn btn-primary"
value="{% trans "Reboot Now &raquo;" %}"/>
</form>
{% endblock %}

View File

@ -31,9 +31,11 @@
{% endblocktrans %}
</p>
<form class="form" method="post" action="{% url 'power:shutdown_now' %}">
<form class="form" method="post">
{% csrf_token %}
{{ form|bootstrap }}
<input type="submit" class="btn btn-primary"
value="{% trans "Shut Down Now &raquo;" %}"/>
</form>

View File

@ -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'),
)

View File

@ -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})