# Path: scrum/models.py
# class Project(models.Model):
#     name = models.CharField(max_length=255, blank=True)
#     description = models.TextField(blank=True)
#     users = models.ManyToManyField(User, related_name='Project_users', blank=True, null=True)
# 
#     class Meta:
#         ordering = ('id',)
# 
#     def __unicode__(self):
#         return "%s" % (self.name, )
# 
# class Story(models.Model):
#     title = models.CharField(max_length=255)
#     note = models.TextField(blank=True)
#     last_modified = models.DateTimeField(auto_now=True)
#     project = models.ForeignKey(Project, related_name='stories')
#     estimated_time = models.FloatField(validators=[MinValueValidator(0), MaxValueValidator(5)])
# 
#     class Meta:
#         ordering = ('title',)
# 
#     def __unicode__(self):
#         return "%s" % (self.title, )
# 
# class Task(models.Model):
#     title = models.CharField(max_length=255)
#     note = models.TextField(blank=True)
#     status = models.CharField(max_length=2, choices=TASKS_STATUS)
#     last_modified = models.DateTimeField(auto_now=True)
#     assigned_to = models.ForeignKey(User, related_name='Task_users', blank=True, null=True)
#     story = models.ForeignKey(Story, related_name='Task_story')
#     estimated_time = models.FloatField(validators=[MinValueValidator(0), MaxValueValidator(8)])
#     objects = TaskManager()
# 
#     class Meta:
#         ordering = ('id',)
#         verbose_name = "Task"
# 
#     def __unicode__(self):
#         return "%s" % (self.title,)
# 
# class Sprint(models.Model):
#     number = models.IntegerField()
#     is_closed = models.BooleanField()
#     project = models.ForeignKey(Project, related_name='sprints')
#     last_modified = models.DateTimeField(auto_now=True)
#     tasks = models.ManyToManyField(Task, through='SprintTasks', blank=True, null=True)
#     objects = SprintManager()
# 
#     class Meta:
#         ordering = ('number',)
#         unique_together = ('number', 'project')
# 
#     def __unicode__(self):
#         return "sprint %s" % (self.number, )
# 
#     def save(self, *args, **kwargs):
#         if self.id is None:
#             self.number = (Sprint.objects.filter(project_id=self.project_id).aggregate(Max('number'))['number__max'] or 0) + 1
# 
#         super(Sprint, self).save(*args, **kwargs)
# 
# class SprintTasks(models.Model):
#     sprint = models.ForeignKey(Sprint, related_name='sprints')
#     task = models.ForeignKey(Task, related_name='tasks')
#     task_end_status = models.CharField(max_length=2, choices=TASKS_STATUS)
# 
#     class Meta:
#         unique_together = ('sprint', 'task')
# 
# Path: scrum/forms.py
# class ProjectForm(ModelForm):
#     class Meta:
#         model = Project
# 
# class StoryForm(ModelForm):
#     class Meta:
#         model = Story
# 
# class TaskForm(ModelForm):
#     class Meta:
#         model = Task
# 
# class SprintTasksForm(ModelForm):
#     class Meta:
#         model = SprintTasks


from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from django.http import HttpResponse, Http404, HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.db.models import Q
from .models import Project, Story, Task, Sprint, SprintTasks
from .forms import ProjectForm, StoryForm, TaskForm, SprintTasksForm
import json

        return context

    def render_to_response(self, context, **response_kwargs):
        #If the user is not a manager
        if is_manager(self.request.user):
            #Display whiteboard in read only
            self.template_name = 'scrum/whiteboard.html'
        else:
            self.template_name = 'scrum/whiteboard_read.html'

        return self.response_class(
            request=self.request,
            template=self.template_name,
            context=context,
            **response_kwargs
        )


def add_story(request, pk_project):
    if request.method == 'POST':
        response_data = {}

        #Add the project to post values
        post_values = request.POST.copy()
        post_values['project'] = pk_project

        #Call form with post values
        f = StoryForm(post_values)
        if f.is_valid():

# Path: scrum/models.py
# class Project(models.Model):
#     name = models.CharField(max_length=255, blank=True)
#     description = models.TextField(blank=True)
#     users = models.ManyToManyField(User, related_name='Project_users', blank=True, null=True)
# 
#     class Meta:
#         ordering = ('id',)
# 
#     def __unicode__(self):
#         return "%s" % (self.name, )
# 
# class Story(models.Model):
#     title = models.CharField(max_length=255)
#     note = models.TextField(blank=True)
#     last_modified = models.DateTimeField(auto_now=True)
#     project = models.ForeignKey(Project, related_name='stories')
#     estimated_time = models.FloatField(validators=[MinValueValidator(0), MaxValueValidator(5)])
# 
#     class Meta:
#         ordering = ('title',)
# 
#     def __unicode__(self):
#         return "%s" % (self.title, )
# 
# class Task(models.Model):
#     title = models.CharField(max_length=255)
#     note = models.TextField(blank=True)
#     status = models.CharField(max_length=2, choices=TASKS_STATUS)
#     last_modified = models.DateTimeField(auto_now=True)
#     assigned_to = models.ForeignKey(User, related_name='Task_users', blank=True, null=True)
#     story = models.ForeignKey(Story, related_name='Task_story')
#     estimated_time = models.FloatField(validators=[MinValueValidator(0), MaxValueValidator(8)])
#     objects = TaskManager()
# 
#     class Meta:
#         ordering = ('id',)
#         verbose_name = "Task"
# 
#     def __unicode__(self):
#         return "%s" % (self.title,)
# 
# class Sprint(models.Model):
#     number = models.IntegerField()
#     is_closed = models.BooleanField()
#     project = models.ForeignKey(Project, related_name='sprints')
#     last_modified = models.DateTimeField(auto_now=True)
#     tasks = models.ManyToManyField(Task, through='SprintTasks', blank=True, null=True)
#     objects = SprintManager()
# 
#     class Meta:
#         ordering = ('number',)
#         unique_together = ('number', 'project')
# 
#     def __unicode__(self):
#         return "sprint %s" % (self.number, )
# 
#     def save(self, *args, **kwargs):
#         if self.id is None:
#             self.number = (Sprint.objects.filter(project_id=self.project_id).aggregate(Max('number'))['number__max'] or 0) + 1
# 
#         super(Sprint, self).save(*args, **kwargs)
# 
# class SprintTasks(models.Model):
#     sprint = models.ForeignKey(Sprint, related_name='sprints')
#     task = models.ForeignKey(Task, related_name='tasks')
#     task_end_status = models.CharField(max_length=2, choices=TASKS_STATUS)
# 
#     class Meta:
#         unique_together = ('sprint', 'task')
# 
# Path: scrum/forms.py
# class ProjectForm(ModelForm):
#     class Meta:
#         model = Project
# 
# class StoryForm(ModelForm):
#     class Meta:
#         model = Story
# 
# class TaskForm(ModelForm):
#     class Meta:
#         model = Task
# 
# class SprintTasksForm(ModelForm):
#     class Meta:
#         model = SprintTasks


# Path: scrum/views.py
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from django.http import HttpResponse, Http404, HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.db.models import Q
from .models import Project, Story, Task, Sprint, SprintTasks
from .forms import ProjectForm, StoryForm, TaskForm, SprintTasksForm
import json


        return context

    def render_to_response(self, context, **response_kwargs):
        #If the user is not a manager
        if is_manager(self.request.user):
            #Display whiteboard in read only
            self.template_name = 'scrum/whiteboard.html'
        else:
            self.template_name = 'scrum/whiteboard_read.html'

        return self.response_class(
            request=self.request,
            template=self.template_name,
            context=context,
            **response_kwargs
        )


def add_story(request, pk_project):
    if request.method == 'POST':
        response_data = {}

        #Add the project to post values
        post_values = request.POST.copy()
        post_values['project'] = pk_project

        #Call form with post values
        f = StoryForm(post_values)
        if f.is_valid():

            new_story = f.save()