Skip to content

Commit

Permalink
Use POST for timer stop and restart operations
Browse files Browse the repository at this point in the history
  • Loading branch information
cdubz committed Jul 31, 2021
1 parent 4673c2b commit c2513ff
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
24 changes: 13 additions & 11 deletions core/templates/core/timer_detail.html
Expand Up @@ -60,30 +60,32 @@ <h2 class="text-muted">
</a>
{% endif %}

<div class="btn-group btn-group-lg center-block" role="group" aria-label="{% trans "Timer actions" %}">

<div class="center-block" role="group" aria-label="{% trans "Timer actions" %}">
{% if perms.core.delete_timer %}
<a class="btn btn-danger"
<a class="btn btn-lg btn-danger"
href="{% url 'core:timer-delete' timer.id %}"
role="button"><i class="icon icon-delete" aria-hidden="true"></i></a>
{% endif %}

{% if perms.core.change_timer %}
<a class="btn btn-primary"
<a class="btn btn-lg btn-primary"
href="{% url 'core:timer-update' timer.id %}"
role="button"><i class="icon icon-update" aria-hidden="true"></i></a>

<a class="btn btn-secondary"
href="{% url 'core:timer-restart' timer.id %}"
role="button"><i class="icon icon-refresh" aria-hidden="true"></i></a>
<form action="{% url 'core:timer-restart' timer.id %}" role="form" method="post" class="d-inline">
{% csrf_token %}
<label class="sr-only">{% trans "Restart timer" %}</label>
<button type="submit" class="btn btn-lg btn-secondary"><i class="icon icon-refresh" aria-hidden="true"></i></button>
</form>

{% if object.active %}
<a class="btn btn-warning"
href="{% url 'core:timer-stop' timer.id %}"
role="button"><i class="icon icon-stop" aria-hidden="true"></i></a>
<form action="{% url 'core:timer-stop' timer.id %}" role="form" method="post" class="d-inline">
{% csrf_token %}
<label class="sr-only">{% trans "Delete timer" %}</label>
<button type="submit" class="btn btn-lg btn-warning"><i class="icon icon-stop" aria-hidden="true"></i></button>
</form>
{% endif %}
{% endif %}

</div>
</div>
{% endblock %}
Expand Down
10 changes: 8 additions & 2 deletions core/tests/tests_views.py
Expand Up @@ -125,9 +125,15 @@ def test_timer_views(self):
self.assertEqual(page.status_code, 200)
page = self.c.get('/timers/{}/delete/'.format(entry.id))
self.assertEqual(page.status_code, 200)
page = self.c.get('/timers/{}/stop/'.format(entry.id), follow=True)

page = self.c.get('/timers/{}/stop/'.format(entry.id))
self.assertEqual(page.status_code, 405)
page = self.c.post('/timers/{}/stop/'.format(entry.id), follow=True)
self.assertEqual(page.status_code, 200)
page = self.c.get('/timers/{}/restart/'.format(entry.id), follow=True)

page = self.c.get('/timers/{}/restart/'.format(entry.id))
self.assertEqual(page.status_code, 405)
page = self.c.post('/timers/{}/restart/'.format(entry.id), follow=True)
self.assertEqual(page.status_code, 200)

page = self.c.get('/timers/delete-inactive/', follow=True)
Expand Down
2 changes: 2 additions & 0 deletions core/views.py
Expand Up @@ -324,6 +324,7 @@ def get(self, request, *args, **kwargs):


class TimerRestart(PermissionRequired403Mixin, RedirectView):
http_method_names = ['post']
permission_required = ('core.change_timer',)

def get(self, request, *args, **kwargs):
Expand All @@ -337,6 +338,7 @@ def get_redirect_url(self, *args, **kwargs):


class TimerStop(PermissionRequired403Mixin, SuccessMessageMixin, RedirectView):
http_method_names = ['post']
permission_required = ('core.change_timer',)
success_message = _('%(timer)s stopped.')

Expand Down

0 comments on commit c2513ff

Please sign in to comment.