Exemple #1
0
def gen(request):
    if request.user.is_staff:
        if not request.POST:
            form = CardForm()
            return render(request, "card/generate.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.issuer = request.user
                card.save()
                record = History(action=1, user=request.user, card=card)
                record.save()
            return render(
                request, "submit.html", {
                    "success": True,
                    "title": "一張卡片就此誕生!",
                    "content": "生成了一張卡片 %s 含有 %d 點" % (card.name, card.value),
                    "next_page": reverse('generate card'),
                })
    else:
        raise PermissionDenied
Exemple #2
0
def gen(request):
    if request.user.is_staff:
        if not request.POST:
            form = CardForm()
            return render(request, "card/generate.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.issuer = request.user
                card.save()
                record = History(action=1, user=request.user, card=card)
                record.save()
            return render(
                request, "submit.html", {
                    "success": True,
                    "title": "一張卡片就此誕生!",
                    "content": "生成了一張卡片 %s 含有 %d 點" % (card.name, card.value),
                    "next_page": reverse('generate card'),
                })
    else:
        raise PermissionDenied
Exemple #3
0
def gen(request):
    if request.user.has_perm('app.add_card'):
        # only teamleader can use
        if not request.POST:
            form = CardForm()
            return render(request, "card/generate.html", locals())
        else:
            form = CardForm(request.POST)
            if form.is_valid():
                with transaction.atomic():
                    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.issuer = request.user
                    card.save()
                    record = History(action=1, user=request.user, card=card)
                    record.save()
                return render(
                    request, "submit.html", {
                        "success": True,
                        "title": "一張卡片就此誕生!",
                        "content": "生成了一張卡片 %s 含有 %d 點" % (card.name, card.value),
                        "next_page": reverse('view card', args=[card.cid]),
                    })
            else:
                return render(request, "submit.html", {
                    "success": False,
                    "title": "產生卡片失敗",
                    "content": "要不要去戳戳系統管理員呢?"
                    "(如果是POST奇怪的資料,可能會收到彈力繩喔ˊ_>ˋ)"
                })
    else:
        raise PermissionDenied
Exemple #4
0
def feed(request, id=None):
    if request.user.has_perm('app.feed_card'):
        try:
            card = Card.objects.get(cid=id)
        except ObjectDoesNotExist:
            return CardNotFound(request)

        if card.retrieved:
            return render(
                request, "submit.html", {
                    "success": False,
                    "title": "卡片已被捕獲",
                    "content": "這張卡片已經被使用過囉,何不換張卡片呢?",
                })
        else:
            if request.method == 'GET':
                form = FeedForm()
                return render(request, "card/feed.html", locals())
            else:
                form = FeedForm(request.POST)
                if form.is_valid():
                    with transaction.atomic():
                        player = form.cleaned_data["player"]
                        card.retrieved = True
                        card.active = True
                        card.capturer = player
                        card.save()
                        record_reciever = History(action=0xfeed,
                                                  user=player.user,
                                                  card=card,
                                                  comment="從 %s 收到一張卡片" %
                                                  request.user.get_full_name())
                        record_reciever.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()
                    return render(
                        request, "submit.html", {
                            "success":
                            True,
                            "title":
                            "成功發送卡片",
                            "content":
                            "成功將卡片送給 %s 了!" % player.user.get_full_name(),
                        })
                else:
                    return render(
                        request, "submit.html", {
                            "success": False,
                            "title": "發送卡片失敗",
                            "content": "要不要去戳戳系統管理員呢?"
                        })
    else:
        raise PermissionDenied
Exemple #5
0
def edit(request, id=None):
    if request.user.has_perm('app.change_card'):
        try:
            card = Card.objects.get(cid=id)
        except ObjectDoesNotExist:
            return CardNotFound(request)

        if not request.POST:
            form = CardForm({
                "name": card.name,
                "value": card.value,
                "long_desc": card.long_desc,
                "active": card.active,
                "retrieved": card.retrieved
            })
            return render(request, "card/edit.html", locals())

        else:
            form = CardForm(request.POST)
            if form.is_valid():
                action = 2
                if card.active is not form.cleaned_data["active"]:
                    if form.cleaned_data["active"]:
                        action = 4
                    else:
                        action = 3
                with transaction.atomic():
                    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.save()
                    record = History(action=action,
                                     user=request.user,
                                     card=card)
                    record.save()
                return render(
                    request, "submit.html", {
                        "success": True,
                        "title": "成功編輯",
                        "content": "成功編輯卡片 %s" % card.name,
                        "next_page": reverse('view card', args=[card.cid]),
                    })
            else:
                # invalid value in form
                return render(
                    request, "submit.html", {
                        "success": True,
                        "title": "編輯失敗",
                        "next_page": reverse('edit card', id),
                    })
    else:
        raise PermissionDenied
Exemple #6
0
def addToHistory(track, user):
    history = History()
    history.track = track
    history.save()
    if UserHistory.objects.filter(user=user).count() == 0:
        userHistory = UserHistory(user=user)
        userHistory.save()
        userHistory.histories.add(history)
    # Adding to existing history
    else:
        userHistory = UserHistory.objects.get(user=user)
        userHistory.save()
        userHistory.histories.add(history)
Exemple #7
0
def get(request, id=None):
    if not request.user.is_authenticated():
        # Anonymous User
        return render(
            request, "submit.html", {
                "success": False,
                "content": "你可能需要先掃描一下識別證上的 QR_Code 來登入系統",
                "title": "未登入!"}, status=403)
    elif request.user.has_perm('app.get_card'):
        # player
        try:
            card = Card.objects.get(cid=id)
        except ObjectDoesNotExist:
            return CardNotFound(request)

        if not card.retrieved and card.active:
            # Add points
            with transaction.atomic():
                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()
            abscardvalue = abs(card.value)
            return render(
                request, "card/get.html", locals())
        elif not card.active:
            return render(
                request, "submit.html", {
                    "success": False,
                    "title": "卡片已被失效",
                    "content": "這張卡片已經被使註銷囉,何不換張卡片呢?",
                })
        else:
            return render(
                request, "submit.html", {
                    "success": False,
                    "title": "卡片已被捕獲",
                    "content": "這張卡片已經被使用過囉,何不換張卡片呢?",
                })
    else:
        # user without permission of capturing a card
        # worker and teamleader
        return render(
            request, "submit.html", {
                "success": False,
                "title": "工人是不能領卡的",
                "content": "工人是不能領卡的,下去領五百。",
            })
Exemple #8
0
def get(request, id=None):
    if not request.user.is_authenticated():
        # Anonymous User
        return render(request,
                      "submit.html", {
                          "success": False,
                          "content": "你可能需要先掃描一下識別證上的 QR_Code 來登入系統",
                          "title": "未登入!"
                      },
                      status=403)
    elif request.user.has_perm('app.get_card'):
        # player
        try:
            card = Card.objects.get(cid=id)
        except ObjectDoesNotExist:
            return CardNotFound(request)

        if not card.retrieved and card.active:
            # Add points
            with transaction.atomic():
                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()
            abscardvalue = abs(card.value)
            return render(request, "card/get.html", locals())
        elif not card.active:
            return render(
                request, "submit.html", {
                    "success": False,
                    "title": "卡片已被失效",
                    "content": "這張卡片已經被使註銷囉,何不換張卡片呢?",
                })
        else:
            return render(
                request, "submit.html", {
                    "success": False,
                    "title": "卡片已被捕獲",
                    "content": "這張卡片已經被使用過囉,何不換張卡片呢?",
                })
    else:
        # user without permission of capturing a card
        # worker and teamleader
        return render(request, "submit.html", {
            "success": False,
            "title": "工人是不能領卡的",
            "content": "工人是不能領卡的,下去領五百。",
        })
Exemple #9
0
def edit(request, id=None):
    if request.user.has_perm('app.change_card'):
        try:
            card = Card.objects.get(cid=id)
        except ObjectDoesNotExist:
            return CardNotFound(request)

        if not request.POST:
            form = CardForm(
                {"name": card.name,
                 "value": card.value,
                 "long_desc": card.long_desc,
                 "active": card.active,
                 "retrieved": card.retrieved})
            return render(request, "card/edit.html", locals())

        else:
            form = CardForm(request.POST)
            if form.is_valid():
                action = 2
                if card.active is not form.cleaned_data["active"]:
                    if form.cleaned_data["active"]:
                        action = 4
                    else:
                        action = 3
                with transaction.atomic():
                    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.save()
                    record = History(action=action, user=request.user, card=card)
                    record.save()
                return render(
                    request, "submit.html", {
                        "success": True,
                        "title": "成功編輯",
                        "content": "成功編輯卡片 %s" % card.name,
                        "next_page": reverse('view card', args=[card.cid]),
                    })
            else:
                # invalid value in form
                return render(
                    request, "submit.html", {
                        "success": True,
                        "title": "編輯失敗",
                        "next_page": reverse('edit card', id),
                    })
    else:
        raise PermissionDenied
Exemple #10
0
def feed(request, id=None):
    if request.user.has_perm('app.feed_card'):
        try:
            card = Card.objects.get(cid=id)
        except ObjectDoesNotExist:
            return CardNotFound(request)

        if card.retrieved:
            return render(
                request, "submit.html", {
                    "success": False,
                    "title": "卡片已被捕獲",
                    "content": "這張卡片已經被使用過囉,何不換張卡片呢?",
                })
        else:
            if request.method == 'GET':
                form = FeedForm()
                return render(request, "card/feed.html", locals())
            else:
                form = FeedForm(request.POST)
                if form.is_valid():
                    with transaction.atomic():
                        player = form.cleaned_data["player"]
                        card.retrieved = True
                        card.active = True
                        card.capturer = player
                        card.save()
                        record_reciever = History(
                            action=0xfeed, user=player.user, card=card,
                            comment="從 %s 收到一張卡片" % request.user.get_full_name())
                        record_reciever.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()
                    return render(
                        request, "submit.html", {
                            "success": True,
                            "title": "成功發送卡片",
                            "content": "成功將卡片送給 %s 了!" % player.user.get_full_name(),
                        })
                else:
                    return render(
                        request, "submit.html", {
                            "success": False,
                            "title": "發送卡片失敗",
                            "content": "要不要去戳戳系統管理員呢?"
                        })
    else:
        raise PermissionDenied
Exemple #11
0
def gift(request):
    if not request.user.has_perm('app.master'):
        raise PermissionDenied
    if request.method == 'GET':
        return render(request, 'staff/gift.html', {"form": FastSendForm()})
    else:
        form = FastSendForm(request.POST)
        if form.is_valid():
            player = form.cleaned_data['player']
            card = Card()
            # hard code
            present = request.user.first_name
            if present == "":
                present = '祝福'
            with transaction.atomic():
                card.name = "來自 %s 的%s" % (request.user.last_name, present)
                card.value = form.cleaned_data['point']
                card.comment = form.cleaned_data['message']
                card.active = True
                card.retrieved = True
                card.issuer = request.user
                card.capturer = player
                card.save()
                record_reciever = History(action=0xfeed,
                                          user=player.user,
                                          card=card,
                                          comment="從 %s 收到一張卡片" %
                                          request.user.get_full_name())
                record_reciever.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()
            return render(
                request, "submit.html", {
                    "success": True,
                    "title": "成功發送卡片",
                    "content": "成功將卡片送給 %s 了!" % player.user.get_full_name(),
                })
        else:
            return render(
                request, "submit.html", {
                    "success": False,
                    "title": "發送卡片失敗",
                    "content": "要不要去戳戳系統管理員呢?"
                    "(如果是POST奇怪的資料,可能會收到彈力繩喔ˊ_>ˋ)"
                })
Exemple #12
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():
                    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())
Exemple #13
0
def gift(request):
    if user_permission(request.user) < 3:
        raise PermissionDenied
    if request.method == 'GET':
        return render(request, 'staff/gift.html', {"form": FastSendForm()})
    else:
        form = FastSendForm(request.POST)
        if form.is_valid():
            player = form.cleaned_data['player']
            card = Card()
            # hard code
            present = request.user.first_name
            if present == "":
                present = '祝福'
            with transaction.atomic():
                card.name = "來自 %s 的%s" % (request.user.last_name, present)
                card.value = form.cleaned_data['point']
                card.comment = form.cleaned_data['message']
                card.active = True
                card.retrieved = True
                card.issuer = request.user
                card.capturer = player
                card.save()
                record_reciever = History(
                    action=0xfeed, user=player.user, card=card,
                    comment="從 %s 收到一張卡片" % request.user.get_full_name())
                record_reciever.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()
            return render(
                request, "submit.html", {
                    "success": True,
                    "title": "成功發送卡片",
                    "content": "成功將卡片送給 %s 了!" % player.user.get_full_name(),
                })
        else:
            return render(
                request, "submit.html", {
                    "success": False,
                    "title": "發送卡片失敗",
                    "content": "要不要去戳戳系統管理員呢?"
                    "(如果是POST奇怪的資料,可能會收到彈力繩喔ˊ_>ˋ)"
                })
Exemple #14
0
def feed(request, id=None):
    if request.user.has_perm('app.feed_card'):
        try:
            user = User.objects.get(username=id)
        except ObjectDoesNotExist:
            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())
    else:
        return render(
            request, "submit.html", {
                "content": "工作人員的世界你是看不到的!",
                "title": "錯誤!"}, status=403)
Exemple #15
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
Exemple #16
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())
Exemple #17
0
def gift(request):
    if request.method == 'GET':
        return render(request, 'staff/gift.html', {"form": FastSendForm()})
    else:
        form = FastSendForm(request.POST)
        if form.is_valid():
            player = form.cleaned_data['player']
            card = Card()
            card.name = "來自 %s 的祝福" % request.user.get_full_name()
            card.value = form.cleaned_data['point']
            card.comment = form.cleaned_data['message']
            card.active = True
            card.retrieved = True
            card.issuer = request.user
            card.capturer = player
            card.save()
            record_reciever = History(action=0xfeed,
                                      user=player.user,
                                      card=card,
                                      comment="從 %s 收到一張卡片" %
                                      request.user.get_full_name())
            record_reciever.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()
            return render(
                request, "submit.html", {
                    "success": True,
                    "title": "成功發送卡片",
                    "content": "成功將卡片送給 %s 了!" % player.user.get_full_name(),
                })
        else:
            return render(request, "submit.html", {
                "success": False,
                "title": "發送卡片失敗",
                "content": "要不要去戳戳系統管理員呢?"
            })
 def create(self, request, *args, **kwargs):
     account = request.data["params"]["account"]
     newsID = request.data["params"]["newsID"]
     try:
         newRecord = History(
             account=account,
             newsID=newsID,
         )
         newRecord.save()
         return JsonResponse({
             "status": 0,
             "mes": "success",
             "data": {
                 "id": newRecord.id
             }
         })
     except:
         return JsonResponse({
             "status": 1,
             "mes": "fail",
         })
Exemple #19
0
def get(request, id=None):
    if user_permission(request.user) == 0:
        # Anonymous User
        return render(
            request, "submit.html", {
                "success": False,
                "content": "你可能需要先掃描一下識別證上的 QR_Code 來登入系統",
                "title": "未登入!"}, status=404)
    elif user_permission(request.user) == 1:
        # player   
        try:
            card = Card.objects.get(cid=id)
        except ObjectDoesNotExist:
            return CardNotFound(request)

        if not card.retrieved and card.active:
            # Add points
            with transaction.atomic():
                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()
            abscardvalue = abs(card.value)
            return render(
                request, "card/get.html", locals())
        else:
            return render(
                request, "submit.html", {
                    "success": False,
                    "title": "卡片已被捕獲",
                    "content": "這張卡片已經被使用過囉,何不換張卡片呢?",
                })
    elif user_permission(request.user) > 1:
        # worker and teamleader
        return redirect('view card', card.cid)
    else:
        raise PermissionDenied
Exemple #20
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
Exemple #21
0
def lite(request, tt=None):
    denomination = [32, 64, 128, 256, -128, -32, -64]
    if not request.user.has_perm('app.gen_card'):
        raise PermissionDenied
    if tt is not None:
        try:
            tt = int(tt)
        except:
            return render(
                request, "submit.html", {
                    "success": False,
                    "title": "發送卡片失敗",
                    "content": "我幫你綁好繩子了,"
                    "你要自己跳還是我推你跳呢?(本繩載重20g)"
                })
        if tt not in range(0, len(denomination)):
            return render(
                request, "submit.html", {
                    "success": False,
                    "title": "發送卡片失敗",
                    "content": "要不要去戳戳系統管理員呢?"
                    "(如果是POST奇怪的資料,可能會收到彈力繩喔ˊ_>ˋ)"
                })
        with transaction.atomic():
            card = Card()
            present = request.user.first_name
            if present == "":
                present = '祝福'
            card.name = "來自 %s 的%s" % (request.user.last_name, present)
            card.value = denomination[tt]
            card.active = True
            card.retrieved = False
            card.issuer = request.user
            card.save()
            record = History(action=1, user=request.user, card=card)
            record.save()
        return redirect('view card', card.cid)
    else:
        return render(request, 'staff/lite.html', locals())
Exemple #22
0
def lite(request, tt=None):
    denomination = [32, 64, 128, 256, -128, -32, -64]
    if user_permission(request.user) < 2:
        raise PermissionDenied
    if tt is not None:
        try:
            tt = int(tt)
        except:
            return render(
                request, "submit.html", {
                    "success": False,
                    "title": "發送卡片失敗",
                    "content": "我幫你綁好繩子了,"
                    "你要自己跳還是我推你跳呢?(本繩載重20g)"})
        if tt not in range(0, len(denomination)):
            return render(
                request, "submit.html", {
                    "success": False,
                    "title": "發送卡片失敗",
                    "content": "要不要去戳戳系統管理員呢?"
                    "(如果是POST奇怪的資料,可能會收到彈力繩喔ˊ_>ˋ)"
                })
        with transaction.atomic():
            card = Card()
            present = request.user.first_name
            if present == "":
                present = '祝福'
            card.name = "來自 %s 的%s" % (request.user.last_name, present)
            card.value = denomination[tt]
            card.active = True
            card.retrieved = False
            card.issuer = request.user
            card.save()
            record = History(action=1, user=request.user, card=card)
            record.save()
        return redirect('view card', card.cid)
    else:
        return render(request, 'staff/lite.html',locals())
Exemple #23
0
def gen(request):
    if request.user.has_perm('app.add_card'):
        # only teamleader can use
        if not request.POST:
            form = CardForm()
            return render(request, "card/generate.html", locals())
        else:
            form = CardForm(request.POST)
            if form.is_valid():
                with transaction.atomic():
                    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.issuer = request.user
                    card.save()
                    record = History(action=1, user=request.user, card=card)
                    record.save()
                return render(
                    request, "submit.html", {
                        "success": True,
                        "title": "一張卡片就此誕生!",
                        "content": "生成了一張卡片 %s 含有 %d 點" %
                        (card.name, card.value),
                        "next_page": reverse('view card', args=[card.cid]),
                    })
            else:
                return render(
                    request, "submit.html", {
                        "success": False,
                        "title": "產生卡片失敗",
                        "content": "要不要去戳戳系統管理員呢?"
                        "(如果是POST奇怪的資料,可能會收到彈力繩喔ˊ_>ˋ)"
                    })
    else:
        raise PermissionDenied
Exemple #24
0
def gift(request):
    if request.method == 'GET':
        return render(request, 'staff/gift.html', {"form": FastSendForm()})
    else:
        form = FastSendForm(request.POST)
        if form.is_valid():
            player = form.cleaned_data['player']
            card = Card()
            card.name = "來自 %s 的祝福" % request.user.get_full_name()
            card.value = form.cleaned_data['point']
            card.comment = form.cleaned_data['message']
            card.active = True
            card.retrieved = True
            card.issuer = request.user
            card.capturer = player
            card.save()
            record_reciever = History(
                action=0xfeed, user=player.user, card=card,
                comment="從 %s 收到一張卡片" % request.user.get_full_name())
            record_reciever.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()
            return render(
                request, "submit.html", {
                    "success": True,
                    "title": "成功發送卡片",
                    "content": "成功將卡片送給 %s 了!" % player.user.get_full_name(),
                })
        else:
            return render(
                request, "submit.html", {
                    "success": False,
                    "title": "發送卡片失敗",
                    "content": "要不要去戳戳系統管理員呢?"
                })