

def favourite(request):
    if request.user.is_anonymous():
        return redirect('/login/')
    key = [k for k in request.POST.keys() if ('fave' in k)][0].split('.')[0]
    (verb, pk) = key.split('-')
    blast = get_object_or_404(Blast, pk=pk)
    blast.set_viewing_user(request.user)
    if (not blast.user_can_favourite()):
        return HttpResponse('You are not allowed to favourite that')
    if (verb == 'fave'):
        blast.favourited_by.add(request.user)
    if (verb == 'notfave'):
        blast.favourited_by.remove(request.user)
    return redirect((request.POST.get('back_to', '') or '/'))

dataset/ETHPy150Open simonw/bugle_project/bugle_project/bugle/views.py favourite/original