mirror of https://github.com/snachodog/mybuddy.git
Use POST for timer quick add functionality
This commit is contained in:
parent
824d2af0da
commit
c1dab44596
|
@ -8,9 +8,15 @@
|
||||||
<span class="text-primary">Baby</span> Buddy
|
<span class="text-primary">Baby</span> Buddy
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<div class="d-lg-none d-md-none ml-auto p-0 mr-2">
|
<div class="d-lg-none d-md-none d-flex ml-auto p-0 mr-2">
|
||||||
<a class="text-success mr-2" href="{% url 'core:timer-add-quick' %}"><i class="icon icon-2x icon-timer" aria-hidden="true"></i></a>
|
<form action="{% url 'core:timer-add-quick' %}" role="form" method="post" class="mr-2">
|
||||||
<div class="dropdown show d-inline">
|
{% csrf_token %}
|
||||||
|
<label class="sr-only">{% trans "Quick Start Timer" %}</label>
|
||||||
|
<button class="btn m-0 p-0 text-success">
|
||||||
|
<i class="icon icon-2x icon-timer" aria-hidden="true"></i>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
<div class="dropdown show">
|
||||||
<a class="text-success"
|
<a class="text-success"
|
||||||
href="#"
|
href="#"
|
||||||
role="button"
|
role="button"
|
||||||
|
|
|
@ -11,9 +11,14 @@
|
||||||
</a>
|
</a>
|
||||||
<div class="dropdown-menu" aria-labelledby="nav-timer-menu-link">
|
<div class="dropdown-menu" aria-labelledby="nav-timer-menu-link">
|
||||||
{% if perms.core.add_timer %}
|
{% if perms.core.add_timer %}
|
||||||
<a class="dropdown-item" href="{% url 'core:timer-add-quick' %}">
|
<div class="dropdown-item">
|
||||||
|
<form action="{% url 'core:timer-add-quick' %}" role="form" method="post" class="d-inline">
|
||||||
|
{% csrf_token %}
|
||||||
|
<button class="btn text-left p-0">
|
||||||
<i class="icon icon-timer" aria-hidden="true"></i> {% trans "Quick Start Timer" %}
|
<i class="icon icon-timer" aria-hidden="true"></i> {% trans "Quick Start Timer" %}
|
||||||
</a>
|
</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
<a class="dropdown-item" href="{% url 'core:timer-add' %}">
|
<a class="dropdown-item" href="{% url 'core:timer-add' %}">
|
||||||
<i class="icon icon-add" aria-hidden="true"></i> {% trans "Start Timer" %}
|
<i class="icon icon-add" aria-hidden="true"></i> {% trans "Start Timer" %}
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -115,7 +115,9 @@ class ViewsTestCase(TestCase):
|
||||||
page = self.c.get('/timers/add/')
|
page = self.c.get('/timers/add/')
|
||||||
self.assertEqual(page.status_code, 200)
|
self.assertEqual(page.status_code, 200)
|
||||||
|
|
||||||
page = self.c.get('/timers/add/quick/', follow=True)
|
page = self.c.get('/timers/add/quick/')
|
||||||
|
self.assertEqual(page.status_code, 405)
|
||||||
|
page = self.c.post('/timers/add/quick/', follow=True)
|
||||||
self.assertEqual(page.status_code, 200)
|
self.assertEqual(page.status_code, 200)
|
||||||
|
|
||||||
entry = models.Timer.objects.first()
|
entry = models.Timer.objects.first()
|
||||||
|
|
|
@ -310,9 +310,10 @@ class TimerUpdate(CoreUpdateView):
|
||||||
|
|
||||||
|
|
||||||
class TimerAddQuick(PermissionRequired403Mixin, RedirectView):
|
class TimerAddQuick(PermissionRequired403Mixin, RedirectView):
|
||||||
|
http_method_names = ['post']
|
||||||
permission_required = ('core.add_timer',)
|
permission_required = ('core.add_timer',)
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
instance = models.Timer.objects.create(user=request.user)
|
instance = models.Timer.objects.create(user=request.user)
|
||||||
# Add child relationship if there is only Child instance.
|
# Add child relationship if there is only Child instance.
|
||||||
if models.Child.count() == 1:
|
if models.Child.count() == 1:
|
||||||
|
|
Loading…
Reference in New Issue