# Path: quotes/models.py
# class Author(models.Model):
#     name = models.CharField(max_length=200)
#     short_bio = models.TextField(max_length=500, null=True, blank=True)
#     slug = models.SlugField(max_length=100, blank=True)
#     uuid = models.CharField(max_length=100, blank=True, null=True)
#     avatar = ImageField(upload_to='authors',
#                         blank=True,
#                         null=True)
# 
#     class Meta:
#         ordering = ['name']
# 
#     def __unicode__(self):
#         return self.name
# 
#     def get_absolute_url(self):
#         return reverse('author', kwargs={'slug': self.slug})
# 
#     def get_avatar(self, size='60x60'):
#         try:
#             thumbnail = get_thumbnail(self.avatar,
#                                  size,
#                                  crop='center',
#                                  quality=70)
#             if thumbnail:
#                 return thumbnail.url
#         except ThumbnailError:
#             return None
# 
# class Tag(models.Model):
#     name = models.CharField(max_length=100)
#     slug = models.SlugField(max_length=100, blank=True)
#     uuid = models.CharField(max_length=100, blank=True, null=True)
# 
#     class Meta:
#         ordering = ['name']
# 
#     def __unicode__(self):
#         return self.name
# 
#     def get_absolute_url(self):
#         return reverse('tag', kwargs={'slug': self.slug})
# 
# class Quote(models.Model):
#         body = models.TextField()
#         authors = models.ManyToManyField(Author)
#         tags = models.ManyToManyField(Tag, blank=True, null=True)
#         slug = models.SlugField(max_length=100, blank=True)
#         publish_date = models.DateTimeField(default=datetime.now)
#         source = models.TextField(null=True, blank=True)
#         featured = models.BooleanField(default=False)
#         uuid = models.CharField(max_length=100, blank=True, null=True)
# 
#         class Meta:
#             ordering = ['-publish_date']
# 
#         def __unicode__(self):
#             return self.body
# 
#         def get_absolute_url(self):
#             return reverse('quote', kwargs={'uuid': self.uuid})
# 
#         def serialize(self):
#             return {
#                 'body': self.body,
#                 'url': self.get_absolute_url(),
#                 'authors': [
#                     {
#                         'name': author.name,
#                         'url': author.get_absolute_url(),
#                         'avatar': author.get_avatar(),
#                     }
#                     for author in self.authors.all()
#                 ],
#                 'tags': [
#                     {
#                         'name': tag.name,
#                         'url': tag.get_absolute_url(),
#                     }
#                     for tag in self.tags.all()
#                 ]
#             }


from datetime import datetime
from quotes.models import Author, Tag, Quote


def create_test_quote():
    body = 'Test quote'
    now = datetime.now()
    quote = Quote.objects.create(body=body, publish_date=now)
    quote.authors.create(name='Author 1')
    quote.authors.create(name='Author 2')
    quote.tags.create(name='Tag 1')
    quote.tags.create(name='Tag 2')
    return quote


def create_test_author():
    name = 'Author'
    author = Author.objects.create(name=name)
    now = datetime.now()
    for i in xrange(10):
        body = 'Test quote %d' % i
        quote = Quote.objects.create(body=body, publish_date=now)
        quote.authors.add(author)
    return author


def create_test_tag():
    name = 'Tag'
    tag = Tag.objects.create(name=name)
    now = datetime.now()
    for i in xrange(10):
        body = 'Test quote %d' % i

# Path: quotes/models.py
# class Author(models.Model):
#     name = models.CharField(max_length=200)
#     short_bio = models.TextField(max_length=500, null=True, blank=True)
#     slug = models.SlugField(max_length=100, blank=True)
#     uuid = models.CharField(max_length=100, blank=True, null=True)
#     avatar = ImageField(upload_to='authors',
#                         blank=True,
#                         null=True)
# 
#     class Meta:
#         ordering = ['name']
# 
#     def __unicode__(self):
#         return self.name
# 
#     def get_absolute_url(self):
#         return reverse('author', kwargs={'slug': self.slug})
# 
#     def get_avatar(self, size='60x60'):
#         try:
#             thumbnail = get_thumbnail(self.avatar,
#                                  size,
#                                  crop='center',
#                                  quality=70)
#             if thumbnail:
#                 return thumbnail.url
#         except ThumbnailError:
#             return None
# 
# class Tag(models.Model):
#     name = models.CharField(max_length=100)
#     slug = models.SlugField(max_length=100, blank=True)
#     uuid = models.CharField(max_length=100, blank=True, null=True)
# 
#     class Meta:
#         ordering = ['name']
# 
#     def __unicode__(self):
#         return self.name
# 
#     def get_absolute_url(self):
#         return reverse('tag', kwargs={'slug': self.slug})
# 
# class Quote(models.Model):
#         body = models.TextField()
#         authors = models.ManyToManyField(Author)
#         tags = models.ManyToManyField(Tag, blank=True, null=True)
#         slug = models.SlugField(max_length=100, blank=True)
#         publish_date = models.DateTimeField(default=datetime.now)
#         source = models.TextField(null=True, blank=True)
#         featured = models.BooleanField(default=False)
#         uuid = models.CharField(max_length=100, blank=True, null=True)
# 
#         class Meta:
#             ordering = ['-publish_date']
# 
#         def __unicode__(self):
#             return self.body
# 
#         def get_absolute_url(self):
#             return reverse('quote', kwargs={'uuid': self.uuid})
# 
#         def serialize(self):
#             return {
#                 'body': self.body,
#                 'url': self.get_absolute_url(),
#                 'authors': [
#                     {
#                         'name': author.name,
#                         'url': author.get_absolute_url(),
#                         'avatar': author.get_avatar(),
#                     }
#                     for author in self.authors.all()
#                 ],
#                 'tags': [
#                     {
#                         'name': tag.name,
#                         'url': tag.get_absolute_url(),
#                     }
#                     for tag in self.tags.all()
#                 ]
#             }


# Path: quotes/tests/utils.py
from datetime import datetime
from quotes.models import Author, Tag, Quote



def create_test_quote():
    body = 'Test quote'
    now = datetime.now()
    quote = Quote.objects.create(body=body, publish_date=now)
    quote.authors.create(name='Author 1')
    quote.authors.create(name='Author 2')
    quote.tags.create(name='Tag 1')
    quote.tags.create(name='Tag 2')
    return quote


def create_test_author():
    name = 'Author'
    author = Author.objects.create(name=name)
    now = datetime.now()
    for i in xrange(10):
        body = 'Test quote %d' % i
        quote = Quote.objects.create(body=body, publish_date=now)
        quote.authors.add(author)
    return author


def create_test_tag():
    name = 'Tag'
    tag = Tag.objects.create(name=name)
    now = datetime.now()
    for i in xrange(10):
        body = 'Test quote %d' % i

        quote = Quote.objects.create(body=body, publish_date=now)