# Path: planet/models.py
# class Post(models.Model):
#     """
#     A feed contains a collection of posts. This model stores them.
#     """
#     feed = models.ForeignKey("planet.Feed", null=False, blank=False)
#     title = models.CharField(_("Title"), max_length=255, db_index=True)
#     authors = models.ManyToManyField("planet.Author", through=PostAuthorData)
#     url = models.URLField(_("Url"), max_length=1000, db_index=True)
#     guid = models.CharField(_("Guid"), max_length=32, db_index=True)
#     content = models.TextField(_("Content"))
#     comments_url = models.URLField(_("Comments URL"), blank=True, null=True)
# 
#     date_modified = models.DateTimeField(_("Date modified"), null=True,
#         blank=True, db_index=True)
#     date_created = models.DateTimeField(_("Date created"), auto_now_add=True)
# 
#     site_objects = PostManager()
#     objects = models.Manager()
# 
#     class Meta:
#         verbose_name = _("Post")
#         verbose_name_plural = _("Posts")
#         ordering = ('-date_created', '-date_modified')
#         unique_together = (('feed', 'guid'),)
# 
#     def __str__(self):
#         return "{} [{}]".format(self.title, self.feed.title)
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('planet.views.post_detail', [str(self.id), self.get_slug()])
# 
#     def get_slug(self):
#         return slugify(self.title) or "no-title"
# 
# class Author(models.Model):
#     """
#     An author is everyone who wrote or has contributed to write a post.
#     """
#     name = models.CharField(_("Name"), max_length=255, null=True,
#         blank=True, db_index=True)
#     email = models.EmailField(_("Author email"), blank=True, db_index=True)
#     profile_url = models.URLField(_("Profile URL"), blank=True, null=True)
# 
#     site_objects = AuthorManager()
#     objects = models.Manager()
# 
#     class Meta:
#         verbose_name = _("Author")
#         verbose_name_plural = _("Authors")
#         ordering = ('name', 'email')
# 
#     def __str__(self):
#         return "{} ({})".format(self.name, self.email)
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('planet.views.author_detail', [str(self.id), self.get_slug()])
# 
#     def get_slug(self):
#         return slugify(self.name) or "no-title"


from django.conf import settings
from django.contrib.sites.models import Site
from django.contrib.syndication.views import Feed
from django.core.urlresolvers import reverse
from django.shortcuts import get_object_or_404
from django.template.defaultfilters import linebreaks, escape
from django.utils.translation import ugettext_lazy as _
from planet.models import Post, Author
from tagging.models import Tag, TaggedItem
    def links(self, author):
        return ({'href': reverse("planet_author_show", args=(author.pk, author.get_slug()))},)

    def items(self, author):
        return Post.objects.filter(authors=author,
            ).distinct().order_by("-date_created")[:ITEMS_PER_FEED]


class TagFeed(PostFeed):

    def get_object(self, request, tag):
        return get_object_or_404(Tag, name=tag)

    def title(self, tag):
        return _("Posts under %(tag)s tag - %(site_name)s") %\
            {'tag': tag, 'site_name': self.site.name}

    def links(self, tag):
        return ({'href': reverse("planet_tag_detail", kwargs={"tag": tag.name})},)

    def items(self, tag):
        return TaggedItem.objects.get_by_model(
            Post.objects.filter(feed__site=self.site), tag)\
            .distinct().order_by("-date_created")[:ITEMS_PER_FEED]


class AuthorTagFeed(PostFeed):

    def get_object(self, request, author_id, tag):
        self.tag = tag

# Path: planet/models.py
# class Post(models.Model):
#     """
#     A feed contains a collection of posts. This model stores them.
#     """
#     feed = models.ForeignKey("planet.Feed", null=False, blank=False)
#     title = models.CharField(_("Title"), max_length=255, db_index=True)
#     authors = models.ManyToManyField("planet.Author", through=PostAuthorData)
#     url = models.URLField(_("Url"), max_length=1000, db_index=True)
#     guid = models.CharField(_("Guid"), max_length=32, db_index=True)
#     content = models.TextField(_("Content"))
#     comments_url = models.URLField(_("Comments URL"), blank=True, null=True)
# 
#     date_modified = models.DateTimeField(_("Date modified"), null=True,
#         blank=True, db_index=True)
#     date_created = models.DateTimeField(_("Date created"), auto_now_add=True)
# 
#     site_objects = PostManager()
#     objects = models.Manager()
# 
#     class Meta:
#         verbose_name = _("Post")
#         verbose_name_plural = _("Posts")
#         ordering = ('-date_created', '-date_modified')
#         unique_together = (('feed', 'guid'),)
# 
#     def __str__(self):
#         return "{} [{}]".format(self.title, self.feed.title)
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('planet.views.post_detail', [str(self.id), self.get_slug()])
# 
#     def get_slug(self):
#         return slugify(self.title) or "no-title"
# 
# class Author(models.Model):
#     """
#     An author is everyone who wrote or has contributed to write a post.
#     """
#     name = models.CharField(_("Name"), max_length=255, null=True,
#         blank=True, db_index=True)
#     email = models.EmailField(_("Author email"), blank=True, db_index=True)
#     profile_url = models.URLField(_("Profile URL"), blank=True, null=True)
# 
#     site_objects = AuthorManager()
#     objects = models.Manager()
# 
#     class Meta:
#         verbose_name = _("Author")
#         verbose_name_plural = _("Authors")
#         ordering = ('name', 'email')
# 
#     def __str__(self):
#         return "{} ({})".format(self.name, self.email)
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('planet.views.author_detail', [str(self.id), self.get_slug()])
# 
#     def get_slug(self):
#         return slugify(self.name) or "no-title"


# Path: planet/feeds.py
from django.conf import settings
from django.contrib.sites.models import Site
from django.contrib.syndication.views import Feed
from django.core.urlresolvers import reverse
from django.shortcuts import get_object_or_404
from django.template.defaultfilters import linebreaks, escape
from django.utils.translation import ugettext_lazy as _
from planet.models import Post, Author
from tagging.models import Tag, TaggedItem

    def links(self, author):
        return ({'href': reverse("planet_author_show", args=(author.pk, author.get_slug()))},)

    def items(self, author):
        return Post.objects.filter(authors=author,
            ).distinct().order_by("-date_created")[:ITEMS_PER_FEED]


class TagFeed(PostFeed):

    def get_object(self, request, tag):
        return get_object_or_404(Tag, name=tag)

    def title(self, tag):
        return _("Posts under %(tag)s tag - %(site_name)s") %\
            {'tag': tag, 'site_name': self.site.name}

    def links(self, tag):
        return ({'href': reverse("planet_tag_detail", kwargs={"tag": tag.name})},)

    def items(self, tag):
        return TaggedItem.objects.get_by_model(
            Post.objects.filter(feed__site=self.site), tag)\
            .distinct().order_by("-date_created")[:ITEMS_PER_FEED]


class AuthorTagFeed(PostFeed):

    def get_object(self, request, author_id, tag):
        self.tag = tag

        return get_object_or_404(Author, pk=author_id)