# Path: characters/forms.py
# class CharacterForm(forms.ModelForm):
# 
#     class Meta:
#         model = Character
#         fields = ['name', 'background', 'race', 'cclass', 'alignment',
#                 'strength', 'dexterity', 'constitution', 'intelligence',
#                 'wisdom', 'charisma', 'max_hit_points']
# 
#     def __init__(self, *args, **kwargs):
#         super(CharacterForm, self).__init__(*args, **kwargs)
#         for field in ['strength', 'dexterity', 'constitution', 'intelligence',
#                 'wisdom', 'charisma', 'max_hit_points']:
#             self.fields[field].widget.attrs['readonly'] = True
# 
# Path: characters/models.py
# class Character(models.Model):
# 
#     objects = CharacterManager()
# 
#     player = models.ForeignKey(User)
# 
#     name = models.CharField(max_length=200)
#     background = models.TextField()
# 
#     race = models.ForeignKey(Race)
#     # This name isn't ideal, but 'class' is a Python builtin, so here we are...
#     # I went with 'cclass' as short for 'character class'.
#     cclass = models.ForeignKey(Class, verbose_name="class")
# 
#     alignment = models.CharField(max_length=2, choices=Alignment.CHOICES,
#             default=Alignment.NEUTRAL)
# 
#     level = models.IntegerField(default=1)
#     experience_points = models.IntegerField(default=0)
# 
#     max_hit_points = models.IntegerField(default=10)
#     current_hit_points = models.IntegerField(default=10)
# 
#     strength = models.IntegerField(default=generate_stat)
#     dexterity = models.IntegerField(default=generate_stat)
#     constitution = models.IntegerField(default=generate_stat)
#     intelligence = models.IntegerField(default=generate_stat)
#     wisdom = models.IntegerField(default=generate_stat)
#     charisma = models.IntegerField(default=generate_stat)
# 
#     inventory = models.ManyToManyField(Item, null=True, blank=True)
# 
#     created = models.DateTimeField(auto_now_add=True)
#     modified = models.DateTimeField(auto_now=True)
# 
#     def __str__(self):
#         return self.name
# 
# class Class(models.Model):
# 
#     name = models.CharField('class', max_length=200)
#     description = models.TextField()
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name_plural = "Classes"
# 
# class Race(models.Model):
# 
#     name = models.CharField('race', max_length=200)
#     description = models.TextField()
# 
#     def __str__(self):
#         return self.name


from django.core.urlresolvers import reverse
from django.shortcuts import get_object_or_404, redirect, render
from django.views.generic import ListView, DetailView
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from characters.forms import CharacterForm
from characters.models import Character, Class, Race



class CharacterIndexView(ListView):

    template_name = 'characters/index.html'
    context_object_name = 'all_characters'  # better than 'object_list'

    def get_queryset(self):

# Path: characters/forms.py
# class CharacterForm(forms.ModelForm):
# 
#     class Meta:
#         model = Character
#         fields = ['name', 'background', 'race', 'cclass', 'alignment',
#                 'strength', 'dexterity', 'constitution', 'intelligence',
#                 'wisdom', 'charisma', 'max_hit_points']
# 
#     def __init__(self, *args, **kwargs):
#         super(CharacterForm, self).__init__(*args, **kwargs)
#         for field in ['strength', 'dexterity', 'constitution', 'intelligence',
#                 'wisdom', 'charisma', 'max_hit_points']:
#             self.fields[field].widget.attrs['readonly'] = True
# 
# Path: characters/models.py
# class Character(models.Model):
# 
#     objects = CharacterManager()
# 
#     player = models.ForeignKey(User)
# 
#     name = models.CharField(max_length=200)
#     background = models.TextField()
# 
#     race = models.ForeignKey(Race)
#     # This name isn't ideal, but 'class' is a Python builtin, so here we are...
#     # I went with 'cclass' as short for 'character class'.
#     cclass = models.ForeignKey(Class, verbose_name="class")
# 
#     alignment = models.CharField(max_length=2, choices=Alignment.CHOICES,
#             default=Alignment.NEUTRAL)
# 
#     level = models.IntegerField(default=1)
#     experience_points = models.IntegerField(default=0)
# 
#     max_hit_points = models.IntegerField(default=10)
#     current_hit_points = models.IntegerField(default=10)
# 
#     strength = models.IntegerField(default=generate_stat)
#     dexterity = models.IntegerField(default=generate_stat)
#     constitution = models.IntegerField(default=generate_stat)
#     intelligence = models.IntegerField(default=generate_stat)
#     wisdom = models.IntegerField(default=generate_stat)
#     charisma = models.IntegerField(default=generate_stat)
# 
#     inventory = models.ManyToManyField(Item, null=True, blank=True)
# 
#     created = models.DateTimeField(auto_now_add=True)
#     modified = models.DateTimeField(auto_now=True)
# 
#     def __str__(self):
#         return self.name
# 
# class Class(models.Model):
# 
#     name = models.CharField('class', max_length=200)
#     description = models.TextField()
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name_plural = "Classes"
# 
# class Race(models.Model):
# 
#     name = models.CharField('race', max_length=200)
#     description = models.TextField()
# 
#     def __str__(self):
#         return self.name


# Path: characters/views.py
from django.core.urlresolvers import reverse
from django.shortcuts import get_object_or_404, redirect, render
from django.views.generic import ListView, DetailView
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from characters.forms import CharacterForm
from characters.models import Character, Class, Race




class CharacterIndexView(ListView):

    template_name = 'characters/index.html'
    context_object_name = 'all_characters'  # better than 'object_list'

    def get_queryset(self):

        return Character.objects.all().order_by('name')