Split up views into separate modules
This commit is contained in:
parent
21ec87cee4
commit
78e9c510bc
15 changed files with 557 additions and 464 deletions
28
todo/views/reorder_tasks.py
Normal file
28
todo/views/reorder_tasks.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
from django.contrib.auth.decorators import login_required
|
||||
from django.http import HttpResponse
|
||||
|
||||
from todo.models import Task
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
@login_required
|
||||
def reorder_tasks(request) -> HttpResponse:
|
||||
"""Handle task re-ordering (priorities) from JQuery drag/drop in list_detail.html
|
||||
"""
|
||||
newtasklist = request.POST.getlist("tasktable[]")
|
||||
if newtasklist:
|
||||
# First task in received list is always empty - remove it
|
||||
del newtasklist[0]
|
||||
|
||||
# Re-prioritize each task in list
|
||||
i = 1
|
||||
for id in newtasklist:
|
||||
task = Task.objects.get(pk=id)
|
||||
task.priority = i
|
||||
task.save()
|
||||
i += 1
|
||||
|
||||
# All views must return an httpresponse of some kind ... without this we get
|
||||
# error 500s in the log even though things look peachy in the browser.
|
||||
return HttpResponse(status=201)
|
Loading…
Add table
Add a link
Reference in a new issue