# 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 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()
#                 ]
#             }
# 
# 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})


import uuid
from django.db.models import signals
from django.template.defaultfilters import slugify
from .models import Author, Quote, Tag
# coding: utf-8




def author_pre_save(signal, instance, sender, **kwargs):
    if not instance.uuid:
        instance.uuid = uuid.uuid4().hex[:12]
    instance.slug = slugify(instance.name[:99])


def quote_pre_save(signal, instance, sender, **kwargs):
    if not instance.uuid:
        instance.uuid = uuid.uuid4().hex[:12]
    instance.slug = slugify(instance.body[:99])


def tag_pre_save(signal, instance, sender, **kwargs):
    if not instance.uuid:
        instance.uuid = uuid.uuid4().hex[:12]
    instance.slug = slugify(instance.name[:99])


signals.pre_save.connect(author_pre_save, sender=Author)
signals.pre_save.connect(quote_pre_save, sender=Quote)

# 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 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()
#                 ]
#             }
# 
# 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})


# Path: quotes/signals.py
import uuid
from django.db.models import signals
from django.template.defaultfilters import slugify
from .models import Author, Quote, Tag

# coding: utf-8




def author_pre_save(signal, instance, sender, **kwargs):
    if not instance.uuid:
        instance.uuid = uuid.uuid4().hex[:12]
    instance.slug = slugify(instance.name[:99])


def quote_pre_save(signal, instance, sender, **kwargs):
    if not instance.uuid:
        instance.uuid = uuid.uuid4().hex[:12]
    instance.slug = slugify(instance.body[:99])


def tag_pre_save(signal, instance, sender, **kwargs):
    if not instance.uuid:
        instance.uuid = uuid.uuid4().hex[:12]
    instance.slug = slugify(instance.name[:99])


signals.pre_save.connect(author_pre_save, sender=Author)
signals.pre_save.connect(quote_pre_save, sender=Quote)

signals.pre_save.connect(tag_pre_save, sender=Tag)