def accept_request(request, tutorial_request_id):
    tutorial_request = Peticioncita.objects.get(idcita=tutorial_request_id)
    lecturer = Profesor.objects.get(id=request.user.id)

    assert lecturer == tutorial_request.profesor

    if PeticionCitaService.can_accept(tutorial_request):
        PeticionCitaService.accept(tutorial_request)
        EmailViews.send_tutorial_accepted_mail(tutorial_request)
        messages.success(request, _('Request was accepted successfully.'))
    else:
        messages.warning(request, _('There is another accepted request for this date. The request was not accepted.'))

    return HttpResponseRedirect('/lecturer/tutorialRequest/list')
def accept_request(request, tutorial_request_id):
    tutorial_request = Peticioncita.objects.get(idcita=tutorial_request_id)
    lecturer = Profesor.objects.get(id=request.user.id)

    assert lecturer == tutorial_request.profesor

    if PeticionCitaService.can_accept(tutorial_request):
        PeticionCitaService.accept(tutorial_request)
        EmailViews.send_tutorial_accepted_mail(tutorial_request)
        messages.success(request, _("Request was accepted successfully."))
    else:
        messages.warning(request, _("There is another accepted request for this date. The request was not accepted."))

    return HttpResponseRedirect("/lecturer/tutorialRequest/list")
def accept_from_mail(request):
    request_token = request.GET['token']
    tutorial_request_id = request.GET['id']
    tutorial_request = Peticioncita.objects.get(idcita=tutorial_request_id)

    assert PeticionCitaService.is_token_valid(tutorial_request, request_token)

    if PeticionCitaService.can_accept(tutorial_request):
        PeticionCitaService.accept(tutorial_request)
        messages.success(request, _('Tutorial request was accepted successfully.'))
    else:
        messages.error(request, _('You cannot accept this tutorial request due to a schedule incompatibility.'))

    return HttpResponseRedirect('/')
def accept_from_mail(request):
    request_token = request.GET["token"]
    tutorial_request_id = request.GET["id"]
    tutorial_request = Peticioncita.objects.get(idcita=tutorial_request_id)

    assert PeticionCitaService.is_token_valid(tutorial_request, request_token)

    if PeticionCitaService.can_accept(tutorial_request):
        PeticionCitaService.accept(tutorial_request)
        messages.success(request, _("Tutorial request was accepted successfully."))
    else:
        messages.error(request, _("You cannot accept this tutorial request due to a schedule incompatibility."))

    return HttpResponseRedirect("/")