Exemplo n.º 1
0
def home(request):
    if not request.user.is_authenticated():
        return render(request, "submit.html", {"content": "<h1>SITCON 夏令營點數系統</h1>", "title":"首頁"})
    elif is_player(request.user):
        return redirect("player data")
    else:
        return redirect("dashboard")
Exemplo n.º 2
0
def edit(request, id=None):
    if not request.user.is_staff:
        raise PermissionDenied
    else:
        try:
            user = User.objects.get(username=id)
        except ObjectDoesNotExist:
            return render(request, "submit.html", {"content":"<h1>Wrong user</h1><meta http-equiv=\"refresh\" content=\"3; url=/\">", "title":"錯誤!"}, status=404)
        if not is_player(user):
            return render(request, "submit.html", {"content":"<h1>Wrong user</h1><meta http-equiv=\"refresh\" content=\"3; url=/\">", "title":"錯誤!"}, status=404)
        else:
            if not request.POST:
                form = PlayerForm({"name": user.username, "value": card.value, "long_desc": card.long_desc, "active": card.active, "retrieved": card.retrieved, "modified_reason": ""})
                return render(request, "card/edit.html", locals())
            else:
                form = CardForm(request.POST)
                if form.is_valid():
                    card = Card()
                    card.name = form.cleaned_data["name"]
                    card.value = form.cleaned_data["value"]
                    card.long_desc = form.cleaned_data["long_desc"]
                    card.active = form.cleaned_data["active"]
                    card.modified_reason = form.cleaned_data["modified_reason"]
                    card.save()
                return render(request, "submit.html", {"content": "<h1>Submitted.</h1><meta http-equiv=\"refresh\" content=\"3; url=/card/" + card.cid + "\">"})
Exemplo n.º 3
0
Arquivo: views.py Projeto: Zekt/arcane
def player(request, id=None):
    if not request.user.is_authenticated():
        return redirect("login", id)
    else:
        if not id == request.user.username:
            # rediect logged-in user to /player/<username>
            return redirect('player data', request.user.username)
        if not is_player(request.user):
            # ban non player
            raise PermissionDenied
        else:
            user = request.user
            sorted_players = list(user.player.team.player.all())
            sorted_players.sort(key=lambda x: x.points_acquired, reverse=True)
            this_records = History.objects.filter(user=user)
            fun = True
            records = []
            for player_i in user.player.team.player.all():
                records = records + list(History.objects.filter(user=player_i.user))
            for i in sorted_players:
                if user.player.team.points == 0:
                    i.weight = 0
                else:
                    i.weight = i.points_acquired / user.player.team.points * 100
            return render(request, 'player/player.html', locals())
Exemplo n.º 4
0
def home(request):
    if not request.user.is_authenticated():
        return render(request, "index.html")
    elif is_player(request.user):
        return redirect("player data")
    else:
        return redirect("dashboard")
Exemplo n.º 5
0
def get(request, id=None):
    if not is_player(request.user):
        return render(request,
                      "submit.html", {
                          "success": False,
                          "content": "你可能需要先掃描一下識別證上的 QR_Code 來登入系統",
                          "title": "未登入!"
                      },
                      status=404)
    else:
        try:
            card = Card.objects.get(cid=id)
        except ObjectDoesNotExist:
            return CardNotFound(request)

        if is_player(request.user):
            if not card.retrieved or card.active:
                # Add points
                player = request.user.player
                player.captured_card.add(card)
                player.save()
                card.retrieved = True
                card.save()
                record = History(action=10, user=request.user, card=card)
                record.save()
            else:
                return render(
                    request, "submit.html", {
                        "success": False,
                        "title": "卡片已被捕獲",
                        "content": "這張卡片已經被使用過囉,何不換張卡片呢?",
                    })

            return render(
                request, "submit.html", {
                    "success": True,
                    "title": "恭喜獲得 %d 點" % card.value,
                    "content": "從 %s 中得到了 %d 點" % (card.name, card.value),
                    "next_page": reverse('home')
                })
        else:
            raise PermissionDenied
Exemplo n.º 6
0
def get(request, id=None):
    if not is_player(request.user):
        return render(
            request, "submit.html", {
                "success": False,
                "content": "你可能需要先掃描一下識別證上的 QR_Code 來登入系統",
                "title": "未登入!"}, status=404)
    else:
        try:
            card = Card.objects.get(cid=id)
        except ObjectDoesNotExist:
            return CardNotFound(request)

        if is_player(request.user):
            if not card.retrieved or card.active:
                # Add points
                player = request.user.player
                player.captured_card.add(card)
                player.save()
                card.retrieved = True
                card.save()
                record = History(action=10, user=request.user, card=card)
                record.save()
            else:
                return render(
                    request, "submit.html", {
                        "success": False,
                        "title": "卡片已被捕獲",
                        "content": "這張卡片已經被使用過囉,何不換張卡片呢?",
                        })

            return render(
                request, "submit.html", {
                    "success": True,
                    "title": "恭喜獲得 %d 點" % card.value,
                    "content": "從 %s 中得到了 %d 點" % (card.name, card.value),
                    "next_page": reverse('home')
                })
        else:
            raise PermissionDenied
Exemplo n.º 7
0
def get(request, id=None):
    if not is_player(request.user):
        raise PermissionDenied
    else:
        try:
            card = Card.objects.get(cid=id)
        except ObjectDoesNotExist:
            return render(
                request,
                "submit.html",
                {"content": '<h1>Wrong card</h1><meta http-equiv="refresh" content="3; url=/">', "title": "錯誤!"},
                status=404,
            )

        if not request.POST:
            form = CardForm(
                {
                    "name": card.name,
                    "value": card.value,
                    "long_desc": card.long_desc,
                    "active": card.active,
                    "retrieved": card.retrieved,
                    "modified_reason": "",
                }
            )
            return render(request, "card/get.html", locals())
        else:
            if is_player(request.user):
                # Add points
                return render(
                    request,
                    "submit.html",
                    {"content": '<h1>Submitted.</h1><meta http-equiv="refresh" content="3; url="/">'},
                )
            else:
                return redirect("/card/" + id)
Exemplo n.º 8
0
def player(request, id=None):
    if not request.user.is_authenticated():
        return redirect("login", id)
    else:
        if not id == request.user.username:
            # rediect logged-in user to /player/<username>
            return redirect('player data', request.user.username)
        if not is_player(request.user):
            # ban non player
            raise PermissionDenied
        else:
            user = request.user
            records = History.objects.filter(user=user)
            return render(request, 'player/player.html',
                          {"user": user, "records": records})
Exemplo n.º 9
0
Arquivo: views.py Projeto: Zekt/arcane
def feed(request, id=None):
    if not request.user.is_staff:
        raise PermissionDenied
    else:
        try:
            user = User.objects.get(username=id)
        except ObjectDoesNotExist:
            return render(
                request, "submit.html", {
                    "content": "你是誰?",
                    "title": "錯誤!"}, status=404)

        if not is_player(user):
            return render(
                request, "submit.html", {
                    "content": "工作人員的世界你是看不到的!",
                    "title": "錯誤!"}, status=404)
        else:
            if not request.POST:
                form = FeedForm()
                return render(request, "player/feed.html", locals())
            else:
                form = FeedForm(request.POST)
                if form.is_valid():
                    with transaction.atomic():
                        player = user.player
                        card = form.cleaned_data["card"]
                        card.capturer = player
                        card.retrieved = True
                        card.save()
                        record_sender = History(
                            action=0xfeed, user=request.user, card=card,
                            comment="給了 %s (%s)" % (player.user.get_full_name(), player.user.username))
                        record_sender.save()
                        record_reciever = History(
                            action=0xfeed, user=player.user, card=card,
                            comment="從 %s 收到一張卡片" % request.user.get_full_name())
                        record_reciever.save()

                    return render(
                        request, "submit.html", {
                            "title": "成功發送",
                            "content": "你送給 %s 一張卡片" % player.user.get_full_name(),
                        })
                else:
                    return render(request, "player/feed.html", locals())
Exemplo n.º 10
0
def feed(request, id=None):
    if not request.user.is_staff:
        raise PermissionDenied
    else:
        try:
            user = User.objects.get(username=id)
        except ObjectDoesNotExist:
            return render(
                request, "submit.html", {
                    "content": "你是誰?",
                    "title": "錯誤!"}, status=404)

        if not is_player(user):
            return render(
                request, "submit.html", {
                    "content": "工作人員的世界你是看不到的!",
                    "title": "錯誤!"}, status=404)
        else:
            if not request.POST:
                form = FeedForm()
                return render(request, "player/feed.html", locals())
            else:
                form = FeedForm(request.POST)
                if form.is_valid():
                    player = user.player
                    card = form.cleaned_data["card"]
                    player.captured_card.add(card)
                    player.save()
                    card.retrieved = True
                    card.save()
                    record = History(action=0xfeed, user=request.user, card=card,
                                     comment="給" + user.get_full_name() + " (" + user.username + ")")
                    record.save()
                    card.save()

                    return render(
                        request, "submit.html", {
                            "title": "成功發送",
                            "content": "你送給 %s 一張卡片" % player.user.get_full_name(),
                        })
                else:
                    return render(request, "player/feed.html", locals())