<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def join_event_view(request, id):
 """Join event page. If a POST request, actually add or remove the attendance of the current user. Otherwise, display a page with confirmation. id: event id """


    event = get_object_or_404(Event, id=id)

    if request.method == "POST":
        if not event.show_attending:
            return redirect("events")
        if "attending" in request.POST:
            attending = request.POST.get("attending")
            attending = (attending == "true")

            if attending:
                event.attending.add(request.user)
            else:
                event.attending.remove(request.user)

            return redirect("events")

    context = {"event": event, "is_events_admin": request.user.has_admin_permission('events')}
    return render(request, "events/join_event.html", context)