# Path: app/models.py
# class Team(models.Model):
# class Player(models.Model):
# class Card(models.Model):
#     class Meta:
# class History(models.Model):
#     class Meta:
#     def points(self):
#     def __str__(self):
#     def points_acquired(self):
#     def __str__(self):
#     def random():
#     def __str__(self):
#     def action_explain(self):
#     ACTION_CODE = {
#         1: "建立卡片",
#         2: "編輯卡片",
#         3: "關閉卡片",
#         4: "啟動卡片",
#         10: "獲得卡片",
#         0xfeed: "餵食卡片",
#     }
# 
# Path: app/staff/forms.py
# class FastSendForm(forms.Form):
#     message = forms.CharField(max_length=255, label="訊息", help_text="悄悄話", required=False)
#     point = forms.IntegerField(label="價值", help_text="點數卡的價值", initial=1)
#     player = forms.ModelChoiceField(Player.objects.all(), label="玩家")
# 
# Path: app/models.py
# class Card(models.Model):
#     def random():
#         return str(get_random_string(16))
#     cid = models.CharField(max_length=16,
#                            primary_key=True,
#                            default=random,
#                            verbose_name="Card ID",
#                            help_text="The unique ID for the points card.")
#     value = models.IntegerField(default="1",
#                                 verbose_name="Value",
#                                 help_text="The value of the points card.")
#     active = models.BooleanField(default=True, verbose_name="Active?")
#     retrieved = models.BooleanField(default=False, verbose_name="Retrieved")
#     name = models.CharField(
#         max_length=32,
#         verbose_name="Name",
#         help_text="Name of the card.",
#         blank=True)
#     long_desc = models.TextField(verbose_name="Descriptions",
#                                  help_text="Long descriptions about the card.",
#                                  blank=True)
#     issuer = models.ForeignKey(User, related_name="issued_card")
#     capturer = models.ForeignKey(Player, related_name="captured_card", null=True, blank=True)
# 
#     def __str__(self):
#         if self.active and not self.retrieved:
#             return (str(self.name) + " (" + str(self.cid) + "), "
#                     "active, " + str(self.value) + " points.")
#         elif not self.active and self.retrieved:
#             return (str(self.name) + " (" + str(self.cid) + "), "
#                     "retrieved by " + str(self.capturer) + ", " + str(self.value) + " points.")
#         else:
#             return (str(self.name) + " (" + str(self.cid) + "), "
#                     "inactive, " + str(self.value) + " points.")
# 
#     class Meta:
#         permissions = (
#             ('read_card', 'can view card detail message'),
#             ('get_card', 'can capture card'),
#             ('toggle_card', 'can active/inactive card'),
#             ('gen_card', 'can generate card within limit'),
#             ('feed_card', 'can directly send card to someone'),
#             ('view_cardlist', 'can list all card'),
# 
#             ('master', 'game master'),
#             ('worker', 'normal staff'),
#         )
# 
# class History(models.Model):
#     ACTION_CODE = {
#         1: "建立卡片",
#         2: "編輯卡片",
#         3: "關閉卡片",
#         4: "啟動卡片",
#         10: "獲得卡片",
#         0xfeed: "餵食卡片",
#     }
# 
#     no = models.AutoField(primary_key=True)
#     action = models.IntegerField(choices=list(ACTION_CODE.items()))
#     user = models.ForeignKey(User)
#     card = models.ForeignKey(Card)
#     comment = models.CharField(max_length=255)
#     date = models.DateTimeField(auto_now_add=True)
# 
#     @property
#     def action_explain(self):
#         return History.ACTION_CODE[self.action]
# 
#     class Meta:
#         permissions = (
#             ('view_history', 'can view history'),
#         )


from django.contrib.auth.decorators import login_required
from django.shortcuts import render, redirect
from django.core.exceptions import PermissionDenied
from django.db import transaction, models
from app import models as data
from app.staff.forms import FastSendForm
from app.models import Card, History
                    "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())


@login_required
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:

# Path: app/models.py
# class Team(models.Model):
# class Player(models.Model):
# class Card(models.Model):
#     class Meta:
# class History(models.Model):
#     class Meta:
#     def points(self):
#     def __str__(self):
#     def points_acquired(self):
#     def __str__(self):
#     def random():
#     def __str__(self):
#     def action_explain(self):
#     ACTION_CODE = {
#         1: "建立卡片",
#         2: "編輯卡片",
#         3: "關閉卡片",
#         4: "啟動卡片",
#         10: "獲得卡片",
#         0xfeed: "餵食卡片",
#     }
# 
# Path: app/staff/forms.py
# class FastSendForm(forms.Form):
#     message = forms.CharField(max_length=255, label="訊息", help_text="悄悄話", required=False)
#     point = forms.IntegerField(label="價值", help_text="點數卡的價值", initial=1)
#     player = forms.ModelChoiceField(Player.objects.all(), label="玩家")
# 
# Path: app/models.py
# class Card(models.Model):
#     def random():
#         return str(get_random_string(16))
#     cid = models.CharField(max_length=16,
#                            primary_key=True,
#                            default=random,
#                            verbose_name="Card ID",
#                            help_text="The unique ID for the points card.")
#     value = models.IntegerField(default="1",
#                                 verbose_name="Value",
#                                 help_text="The value of the points card.")
#     active = models.BooleanField(default=True, verbose_name="Active?")
#     retrieved = models.BooleanField(default=False, verbose_name="Retrieved")
#     name = models.CharField(
#         max_length=32,
#         verbose_name="Name",
#         help_text="Name of the card.",
#         blank=True)
#     long_desc = models.TextField(verbose_name="Descriptions",
#                                  help_text="Long descriptions about the card.",
#                                  blank=True)
#     issuer = models.ForeignKey(User, related_name="issued_card")
#     capturer = models.ForeignKey(Player, related_name="captured_card", null=True, blank=True)
# 
#     def __str__(self):
#         if self.active and not self.retrieved:
#             return (str(self.name) + " (" + str(self.cid) + "), "
#                     "active, " + str(self.value) + " points.")
#         elif not self.active and self.retrieved:
#             return (str(self.name) + " (" + str(self.cid) + "), "
#                     "retrieved by " + str(self.capturer) + ", " + str(self.value) + " points.")
#         else:
#             return (str(self.name) + " (" + str(self.cid) + "), "
#                     "inactive, " + str(self.value) + " points.")
# 
#     class Meta:
#         permissions = (
#             ('read_card', 'can view card detail message'),
#             ('get_card', 'can capture card'),
#             ('toggle_card', 'can active/inactive card'),
#             ('gen_card', 'can generate card within limit'),
#             ('feed_card', 'can directly send card to someone'),
#             ('view_cardlist', 'can list all card'),
# 
#             ('master', 'game master'),
#             ('worker', 'normal staff'),
#         )
# 
# class History(models.Model):
#     ACTION_CODE = {
#         1: "建立卡片",
#         2: "編輯卡片",
#         3: "關閉卡片",
#         4: "啟動卡片",
#         10: "獲得卡片",
#         0xfeed: "餵食卡片",
#     }
# 
#     no = models.AutoField(primary_key=True)
#     action = models.IntegerField(choices=list(ACTION_CODE.items()))
#     user = models.ForeignKey(User)
#     card = models.ForeignKey(Card)
#     comment = models.CharField(max_length=255)
#     date = models.DateTimeField(auto_now_add=True)
# 
#     @property
#     def action_explain(self):
#         return History.ACTION_CODE[self.action]
# 
#     class Meta:
#         permissions = (
#             ('view_history', 'can view history'),
#         )


# Path: app/staff/views.py
from django.contrib.auth.decorators import login_required
from django.shortcuts import render, redirect
from django.core.exceptions import PermissionDenied
from django.db import transaction, models
from app import models as data
from app.staff.forms import FastSendForm
from app.models import Card, History

                    "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())


@login_required
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)