# Path: wireframes/models.py
# class Wireframe(models.Model):
#     """(Project description)"""
# 
#     author = models.ForeignKey(User, null=True)
#     project = models.ForeignKey(Project, null=True)
#     name = models.CharField(blank=False, max_length=255)
#     creation_date = models.DateTimeField(auto_now=True)
#     #model = models.ForeignKey(Wireframe, null=True)
#     grid_width = models.PositiveIntegerField(default="50")
#     grid_spacing = models.PositiveIntegerField(default="10")
#     grid_columns = models.PositiveIntegerField(default="16")
# 
#     def total_width(self):
#         return (self.grid_columns * self.grid_width) + (self.grid_spacing *
#                                         (self.grid_columns-1))
# 
# 
#     def __str__(self):
#         return "wireframe %s %d" % (self.name, self.id)
# 
#     def save(self):
#         super(Wireframe, self).save()
# 
# class Revision(models.Model):
# 
#     author = models.ForeignKey(User, null=True)
#     wireframe = models.ForeignKey(Wireframe)
#     creation_date = models.DateTimeField(auto_now=True)
#     content = models.TextField()
# 
#     def __str__(self):
#         return "%s" % (self.wireframe)
# 
#     def save(self):
#         super(Revision, self).save()
# 
# class Component(models.Model):
#     """(Component description)"""
# 
#     author = models.ForeignKey(User, null=True, blank=True)
#     project = models.ForeignKey(Project, null=True, blank=True)
#     name = models.CharField(blank=False, max_length=255)
#     creation_date = models.DateTimeField(auto_now=True)
# 
#     default_content = models.TextField(blank=True)
#     javascript = models.TextField()
#     css = models.TextField(blank=True)
# 
#     def css_out(self):
#         rules = ""
#         r_list = self.css.strip().split('}')
#         for r in r_list:
#             if r.strip():
#                 rules += ".component-%d %s }\n" % (self.id , r.strip())
#         return rules
# 
#     def __str__(self):
#         return "Component %s" % (self.name)
# 
# class Project(models.Model):
#     """(Project description)"""
# 
#     admin = models.ForeignKey(User, related_name='selfs_as_admin', null=True)
#     members = models.ManyToManyField(User, related_name='selfs_as_member')
# 
#     name = models.CharField(blank=False, max_length=255)
#     grid_width = models.PositiveIntegerField(default="50")
#     grid_spacing = models.PositiveIntegerField(default="10")
#     grid_columns = models.PositiveIntegerField(default="16")
# 
#     def total_width(self):
#         return self.grid_columns * self.grid_width + (self.grid_spacing * self.grid_columns-1)
# 
#     def __str__(self):
#         return "%s" % (self.name)
# 
#     def get_absolute_url(self):
#         return 'not done'
# 
#     def save(self):
#         super(Project, self).save()
# 
# Path: wireframes/forms.py
# class CreateWireframeForm(ModelForm):
#     name = forms.CharField(initial="New wireframe")
#     grid_width = forms.IntegerField(min_value=12, initial=70)
#     grid_spacing = forms.IntegerField(min_value=0, initial=10)
#     grid_columns = forms.IntegerField(min_value=1, max_value=100, initial=12)
#     class Meta:
#         model=Wireframe
#         fields=('name', 'grid_width', 'grid_spacing', 'grid_columns')


from wireframes.models import Wireframe, Revision, Component, Project
from wireframes.forms import CreateWireframeForm
from django.http import HttpResponseRedirect, HttpResponse
from django.core.urlresolvers import reverse
from django.shortcuts import render_to_response
from django.template import RequestContext

def home(request):
    if request.POST:
        form = CreateWireframeForm(request.POST)
        if form.is_valid():
            wireframe = form.save()
            return HttpResponseRedirect(reverse('wireframes-edit',
                    args=[wireframe.id]))
    else:

# Path: wireframes/models.py
# class Wireframe(models.Model):
#     """(Project description)"""
# 
#     author = models.ForeignKey(User, null=True)
#     project = models.ForeignKey(Project, null=True)
#     name = models.CharField(blank=False, max_length=255)
#     creation_date = models.DateTimeField(auto_now=True)
#     #model = models.ForeignKey(Wireframe, null=True)
#     grid_width = models.PositiveIntegerField(default="50")
#     grid_spacing = models.PositiveIntegerField(default="10")
#     grid_columns = models.PositiveIntegerField(default="16")
# 
#     def total_width(self):
#         return (self.grid_columns * self.grid_width) + (self.grid_spacing *
#                                         (self.grid_columns-1))
# 
# 
#     def __str__(self):
#         return "wireframe %s %d" % (self.name, self.id)
# 
#     def save(self):
#         super(Wireframe, self).save()
# 
# class Revision(models.Model):
# 
#     author = models.ForeignKey(User, null=True)
#     wireframe = models.ForeignKey(Wireframe)
#     creation_date = models.DateTimeField(auto_now=True)
#     content = models.TextField()
# 
#     def __str__(self):
#         return "%s" % (self.wireframe)
# 
#     def save(self):
#         super(Revision, self).save()
# 
# class Component(models.Model):
#     """(Component description)"""
# 
#     author = models.ForeignKey(User, null=True, blank=True)
#     project = models.ForeignKey(Project, null=True, blank=True)
#     name = models.CharField(blank=False, max_length=255)
#     creation_date = models.DateTimeField(auto_now=True)
# 
#     default_content = models.TextField(blank=True)
#     javascript = models.TextField()
#     css = models.TextField(blank=True)
# 
#     def css_out(self):
#         rules = ""
#         r_list = self.css.strip().split('}')
#         for r in r_list:
#             if r.strip():
#                 rules += ".component-%d %s }\n" % (self.id , r.strip())
#         return rules
# 
#     def __str__(self):
#         return "Component %s" % (self.name)
# 
# class Project(models.Model):
#     """(Project description)"""
# 
#     admin = models.ForeignKey(User, related_name='selfs_as_admin', null=True)
#     members = models.ManyToManyField(User, related_name='selfs_as_member')
# 
#     name = models.CharField(blank=False, max_length=255)
#     grid_width = models.PositiveIntegerField(default="50")
#     grid_spacing = models.PositiveIntegerField(default="10")
#     grid_columns = models.PositiveIntegerField(default="16")
# 
#     def total_width(self):
#         return self.grid_columns * self.grid_width + (self.grid_spacing * self.grid_columns-1)
# 
#     def __str__(self):
#         return "%s" % (self.name)
# 
#     def get_absolute_url(self):
#         return 'not done'
# 
#     def save(self):
#         super(Project, self).save()
# 
# Path: wireframes/forms.py
# class CreateWireframeForm(ModelForm):
#     name = forms.CharField(initial="New wireframe")
#     grid_width = forms.IntegerField(min_value=12, initial=70)
#     grid_spacing = forms.IntegerField(min_value=0, initial=10)
#     grid_columns = forms.IntegerField(min_value=1, max_value=100, initial=12)
#     class Meta:
#         model=Wireframe
#         fields=('name', 'grid_width', 'grid_spacing', 'grid_columns')


# Path: wireframes/views.py
from wireframes.models import Wireframe, Revision, Component, Project
from wireframes.forms import CreateWireframeForm
from django.http import HttpResponseRedirect, HttpResponse
from django.core.urlresolvers import reverse
from django.shortcuts import render_to_response
from django.template import RequestContext


def home(request):
    if request.POST:
        form = CreateWireframeForm(request.POST)
        if form.is_valid():
            wireframe = form.save()
            return HttpResponseRedirect(reverse('wireframes-edit',
                    args=[wireframe.id]))
    else:

        form = CreateWireframeForm()