def toggle(request):
    if request.user.is_anonymous():
        return redirect('/login/')
    key = [k for k in request.POST.keys() if 'check' in k][0].split('.')[0]
    # key will now be uncheck-45 or check-23
    verb, pk = key.split('-')
    blast = get_object_or_404(Blast, pk = pk)
    # Check the user is allowed to modify this blast
    blast.set_viewing_user(request.user)
    if not blast.viewing_user_can_mark_done():
        return HttpResponse('You are not allowed to check off that task')
    if verb == 'check':
        blast.done = True
    if verb == 'uncheck':
        blast.done = False
    blast.save()
    return redirect(request.POST.get('back_to', '') or '/')
dataset/ETHPy150Open simonw/bugle_project/bugle_project/bugle/views.py/toggle/original