# Path: quotes/models.py
# 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 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})
# 
# Path: quotes/feeds.py
# class LatestEntriesFeed(Feed):
#     title = "def programming: latest quotes"
#     link = "/"
#     description = "Latest published quotes from defprogramming.com"
# 
#     def items(self):
#         return Quote.objects.order_by('-publish_date')[:20]
# 
#     def item_title(self, item):
#         authors = ""
#         for author in item.authors.all():
#             authors += author.name + " and "
#         return re.sub(r' and $', '', authors)
# 
#     def item_description(self, item):
#         return item.body


from random import choice
from django.conf.urls import patterns, include, url
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.conf import settings
from django.contrib import admin
from django.contrib.sitemaps import GenericSitemap
from rest_framework import routers, serializers, viewsets, generics
from quotes.models import Quote, Author, Tag
from quotes.feeds import LatestEntriesFeed
    'queryset': Tag.objects.all()
}

sitemaps = {
    'quotes': GenericSitemap(quotes, changefreq='weekly', priority=0.6),
    'authors': GenericSitemap(authors, changefreq='weekly', priority=0.6),
    'tags': GenericSitemap(tags, changefreq='weekly', priority=0.6),
}

# Serializers define the API representation.
class AuthorSerializer(serializers.ModelSerializer):
    class Meta:
        model = Author
        fields = ('name', 'slug')


class QuoteSerializer(serializers.HyperlinkedModelSerializer):
    authors = AuthorSerializer(many=True, read_only=True)

    class Meta:
        model = Quote
        fields = ('body', 'authors', 'slug')

# ViewSets define the view behavior.
class QuoteViewSet(viewsets.ModelViewSet):
    queryset = Quote.objects.all()
    serializer_class = QuoteSerializer


class RandomQuoteViewSet(viewsets.ModelViewSet):

# Path: quotes/models.py
# 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 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})
# 
# Path: quotes/feeds.py
# class LatestEntriesFeed(Feed):
#     title = "def programming: latest quotes"
#     link = "/"
#     description = "Latest published quotes from defprogramming.com"
# 
#     def items(self):
#         return Quote.objects.order_by('-publish_date')[:20]
# 
#     def item_title(self, item):
#         authors = ""
#         for author in item.authors.all():
#             authors += author.name + " and "
#         return re.sub(r' and $', '', authors)
# 
#     def item_description(self, item):
#         return item.body


# Path: defprogramming/urls.py
from random import choice
from django.conf.urls import patterns, include, url
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.conf import settings
from django.contrib import admin
from django.contrib.sitemaps import GenericSitemap
from rest_framework import routers, serializers, viewsets, generics
from quotes.models import Quote, Author, Tag
from quotes.feeds import LatestEntriesFeed

    'queryset': Tag.objects.all()
}

sitemaps = {
    'quotes': GenericSitemap(quotes, changefreq='weekly', priority=0.6),
    'authors': GenericSitemap(authors, changefreq='weekly', priority=0.6),
    'tags': GenericSitemap(tags, changefreq='weekly', priority=0.6),
}

# Serializers define the API representation.
class AuthorSerializer(serializers.ModelSerializer):
    class Meta:
        model = Author
        fields = ('name', 'slug')


class QuoteSerializer(serializers.HyperlinkedModelSerializer):
    authors = AuthorSerializer(many=True, read_only=True)

    class Meta:
        model = Quote
        fields = ('body', 'authors', 'slug')

# ViewSets define the view behavior.
class QuoteViewSet(viewsets.ModelViewSet):
    queryset = Quote.objects.all()
    serializer_class = QuoteSerializer


class RandomQuoteViewSet(viewsets.ModelViewSet):

    queryset = Quote.objects.all().order_by('?')[:1]