def post(self, request, cid):
    if not request.user.is_authenticated:
      messages.error(request, "请先登录。")
    else:
      contest = get_object_or_404(Contest, pk=cid)
      if contest.access_level == 30 and contest.status == -1:
        with transaction.atomic():
          if not contest.contestparticipant_set.filter(user=request.user).exists():
            contest.contestparticipant_set.get_or_create(user=request.user)
          else:
            contest.contestparticipant_set.filter(user=request.user).delete()
    return HttpResponseRedirect(reverse('contest:dashboard', kwargs={'cid': cid}))