# Path: apps/news/models.py
# class News(models.Model):
# 
#     class Meta:
#         verbose_name_plural = 'News'
#         ordering = ['-date_and_time']
# 
#     title = models.CharField(max_length=200)
#     summary = models.CharField(max_length=200, null=True, blank=True)
#     body = models.TextField()
#     image = ImageWithThumbsField(null=True, blank=True, upload_to='images/news', sizes=((150, 150), (90, 90), ))
#     author = models.ForeignKey(User)
#     date_and_time = models.DateTimeField(default=dt.now())
#     projects_relateds = models.ManyToManyField(Project, null=True, blank=True)
#     slug = models.SlugField(max_length=200, blank=True)
# 
#     def __unicode__(self):
#         return self.title
# 
#     def body_as_html(self):
#         parts = publish_parts(source=self.body, writer_name="html4css1")
#         return parts['fragment']
# 
#     def save(self, *args, **kwargs):
#         self.slug = slugify(self.title)
#         super(News, self).save(*args, **kwargs)
# 
# Path: apps/projects/models.py
# class Project(models.Model):
#     name = models.CharField(max_length=100)
#     description = models.TextField()
#     logo = ImageWithThumbsField(upload_to='images/projects', null=True, blank=True, sizes=((200, 200), (90, 90), ))
#     sponsor = models.CharField(max_length=100)
#     github = models.CharField(max_length=80, null=True, blank=True)
#     status = models.CharField(max_length=100, choices=PROJECT_STATES)
#     start_date = models.DateField()
#     end_date = models.DateField(null=True, blank=True)
#     slug = models.SlugField(max_length=100, blank=True)
# 
#     def github_link(self):
#         return "http://github.com/" + self.github
# 
#     def github_feed(self):
#         return self.github_link() + "/commits/master.atom"
# 
# 
#     def finished(self):
#         return self.end_date is not None
# 
#     def __unicode__(self):
#         return self.name
# 
#     def save(self, *args, **kwargs):
#         self.slug = slugify(self.name)
#         if self.finished():
#             self.status = 'finalizado'
#             super(Project, self).save(*args, **kwargs)
#         else:
#             super(Project, self).save(*args, **kwargs)
# 
# Path: apps/tools/models.py
# class Tool(models.Model):
#     name = models.CharField(max_length=100)
#     short_description = models.TextField(max_length=200)
#     description = models.TextField()
#     repository = models.CharField(max_length=100)
#     site = models.CharField(max_length=100)
#     logo = models.ImageField(upload_to='images/tools', null=True, blank=True)
#     status = models.CharField(max_length=100, choices=TOOLS_STATES)
#     highlight = models.BooleanField()
#     relateds_projects = models.ManyToManyField(Project, null=True, blank=True)
#     slug = models.SlugField(max_length=100, blank=True)
# 
#     def __unicode__(self):
#         return self.name
# 
#     def save(self, *args, **kwargs):
#         self.slug = slugify(self.name)
#         super(Tool, self).save(*args, **kwargs)


import os
import shutil
from datetime import datetime
from django.conf import settings
from lettuce import step
from model_mommy import mommy
from apps.news.models import News
from apps.projects.models import Project
from apps.tools.models import Tool
from django.contrib.auth.models import User
# -*- coding: utf-8 -*-


@step(u'exist a author:')
def exist_a_author(step):
    for user in step.hashes:
        mommy.make_one(User, username=user.get('name'), email='a@a.com')

@step(u'exist a news:')
def exist_a_news(step):
    for news_hashes in step.hashes:
        author = User.objects.get(username__exact=news_hashes.get('author'))
        date, hour = news_hashes.get('date_and_time').split()
        day, month, year = date.split('/')
        hours, minutes = hour.split(':')
        date_time = datetime(int(year), int(month), int(day), int(hours), int(minutes))
        news = mommy.make_one(News, title=news_hashes.get('title'), image=news_hashes.get('image'), author=author, date_and_time=date_time).save()
        file_name = news_hashes.get('image').split('/')[-1]
        shutil.copy2(os.path.join(settings.PROJECT_ROOT_PATH, 'apps', 'home_page',
                                  'features', 'resources', file_name),
                     os.path.join(settings.MEDIA_ROOT, 'test', 'images', 'news'))

@step(u'exist a project:')
def exist_a_project(step):
    for project_hashes in step.hashes:

# Path: apps/news/models.py
# class News(models.Model):
# 
#     class Meta:
#         verbose_name_plural = 'News'
#         ordering = ['-date_and_time']
# 
#     title = models.CharField(max_length=200)
#     summary = models.CharField(max_length=200, null=True, blank=True)
#     body = models.TextField()
#     image = ImageWithThumbsField(null=True, blank=True, upload_to='images/news', sizes=((150, 150), (90, 90), ))
#     author = models.ForeignKey(User)
#     date_and_time = models.DateTimeField(default=dt.now())
#     projects_relateds = models.ManyToManyField(Project, null=True, blank=True)
#     slug = models.SlugField(max_length=200, blank=True)
# 
#     def __unicode__(self):
#         return self.title
# 
#     def body_as_html(self):
#         parts = publish_parts(source=self.body, writer_name="html4css1")
#         return parts['fragment']
# 
#     def save(self, *args, **kwargs):
#         self.slug = slugify(self.title)
#         super(News, self).save(*args, **kwargs)
# 
# Path: apps/projects/models.py
# class Project(models.Model):
#     name = models.CharField(max_length=100)
#     description = models.TextField()
#     logo = ImageWithThumbsField(upload_to='images/projects', null=True, blank=True, sizes=((200, 200), (90, 90), ))
#     sponsor = models.CharField(max_length=100)
#     github = models.CharField(max_length=80, null=True, blank=True)
#     status = models.CharField(max_length=100, choices=PROJECT_STATES)
#     start_date = models.DateField()
#     end_date = models.DateField(null=True, blank=True)
#     slug = models.SlugField(max_length=100, blank=True)
# 
#     def github_link(self):
#         return "http://github.com/" + self.github
# 
#     def github_feed(self):
#         return self.github_link() + "/commits/master.atom"
# 
# 
#     def finished(self):
#         return self.end_date is not None
# 
#     def __unicode__(self):
#         return self.name
# 
#     def save(self, *args, **kwargs):
#         self.slug = slugify(self.name)
#         if self.finished():
#             self.status = 'finalizado'
#             super(Project, self).save(*args, **kwargs)
#         else:
#             super(Project, self).save(*args, **kwargs)
# 
# Path: apps/tools/models.py
# class Tool(models.Model):
#     name = models.CharField(max_length=100)
#     short_description = models.TextField(max_length=200)
#     description = models.TextField()
#     repository = models.CharField(max_length=100)
#     site = models.CharField(max_length=100)
#     logo = models.ImageField(upload_to='images/tools', null=True, blank=True)
#     status = models.CharField(max_length=100, choices=TOOLS_STATES)
#     highlight = models.BooleanField()
#     relateds_projects = models.ManyToManyField(Project, null=True, blank=True)
#     slug = models.SlugField(max_length=100, blank=True)
# 
#     def __unicode__(self):
#         return self.name
# 
#     def save(self, *args, **kwargs):
#         self.slug = slugify(self.name)
#         super(Tool, self).save(*args, **kwargs)


# Path: apps/home_page/features/steps.py
import os
import shutil
from datetime import datetime
from django.conf import settings
from lettuce import step
from model_mommy import mommy
from apps.news.models import News
from apps.projects.models import Project
from apps.tools.models import Tool
from django.contrib.auth.models import User

# -*- coding: utf-8 -*-


@step(u'exist a author:')
def exist_a_author(step):
    for user in step.hashes:
        mommy.make_one(User, username=user.get('name'), email='a@a.com')

@step(u'exist a news:')
def exist_a_news(step):
    for news_hashes in step.hashes:
        author = User.objects.get(username__exact=news_hashes.get('author'))
        date, hour = news_hashes.get('date_and_time').split()
        day, month, year = date.split('/')
        hours, minutes = hour.split(':')
        date_time = datetime(int(year), int(month), int(day), int(hours), int(minutes))
        news = mommy.make_one(News, title=news_hashes.get('title'), image=news_hashes.get('image'), author=author, date_and_time=date_time).save()
        file_name = news_hashes.get('image').split('/')[-1]
        shutil.copy2(os.path.join(settings.PROJECT_ROOT_PATH, 'apps', 'home_page',
                                  'features', 'resources', file_name),
                     os.path.join(settings.MEDIA_ROOT, 'test', 'images', 'news'))

@step(u'exist a project:')
def exist_a_project(step):
    for project_hashes in step.hashes:

        project = mommy.make_one(Project, name=project_hashes.get('name'), status=project_hashes.get('status'))