# 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'),
#         )


from django import forms
from app.models import Card


class CardCoiceField(forms.ModelChoiceField):
    def label_from_instance(self, obj):
        return "%s: %d point" % (obj.name, obj.value)


class FeedForm(forms.Form):

# 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'),
#         )


# Path: app/player/forms.py
from django import forms
from app.models import Card



class CardCoiceField(forms.ModelChoiceField):
    def label_from_instance(self, obj):
        return "%s: %d point" % (obj.name, obj.value)


class FeedForm(forms.Form):

    card = CardCoiceField(Card.objects.filter(active=True, retrieved=False), label="Card")