# Path: hackday/blog/models.py
# class Entry(models.Model):
#     title = models.CharField('title of entry', max_length=255)
#     slug = models.SlugField('slugified title', db_index=True,
#             unique_for_date="pub_date")
#     content = models.TextField('entry content')
#     format = models.CharField(max_length=5, choices=FORMAT.CHOICES)
#     status = models.CharField(max_length=1, choices=STATUS.CHOICES)
# 
#     attachments = models.ManyToManyField(Attachment,
#             related_name="%(app_label)s_%(class)s_attachments", \
#             blank=True)
#     images = models.ManyToManyField(ImageAttachment,
#             related_name="%(app_label)s_%(class)s_images", \
#             blank=True)
#     links = models.ManyToManyField(Link,
#             related_name="%(app_label)s_%(class)s_links", \
#             blank=True)
# 
#     author = models.ForeignKey(User)
# 
#     categories = models.ManyToManyField(Category, blank=True)
#     tags = models.ManyToManyField(Tag, blank=True)
# 
#     create_date = models.DateTimeField('date created', auto_now_add=True,
#             editable=False)
#     mod_date = models.DateTimeField('date modified', auto_now=True,
#             editable=False)
#     pub_date = models.DateTimeField('date published', null=True, blank=True)
# 
#     def __unicode__(self):
#         return self.title
# 
#     def get_absolute_url(self):
#         return reverse('blog-entry', args=[self.id])
# 
#     def short_url(self):
#         return get_short_url(self.get_absolute_url())
# 
#     class Meta:
#         verbose_name_plural = "Entries"
# 
# class FORMAT(object):
#     HTML = 'H'
#     MARKDOWN = 'MD'
#     RESTRUCTURED_TEXT = 'RST'
# 
#     CHOICES = (
#         (MARKDOWN, 'Markdown'),
#         (RESTRUCTURED_TEXT, 'Restructured Text'),
#         (HTML, 'HTML'),
#     )


from markdown import markdown
from docutils.core import publish_parts
from django.contrib.syndication.views import Feed
from django.utils import feedgenerator
from hackday.blog.models import Entry, FORMAT


class LatestEntriesFeed(Feed):
    title = "Hack Day Blog"
    link = "/blog/"
    description = "A list of the Hack Day blog entries"

    feed_type = feedgenerator.Rss201rev2Feed

    def items(self):
        return Entry.objects.order_by('-pub_date')[:20]

    def item_title(self, item):
        return item.title

    def item_description(self, item):
        if item.format == FORMAT.MARKDOWN:
            return markdown(item.content, safe_mode='remove')

# Path: hackday/blog/models.py
# class Entry(models.Model):
#     title = models.CharField('title of entry', max_length=255)
#     slug = models.SlugField('slugified title', db_index=True,
#             unique_for_date="pub_date")
#     content = models.TextField('entry content')
#     format = models.CharField(max_length=5, choices=FORMAT.CHOICES)
#     status = models.CharField(max_length=1, choices=STATUS.CHOICES)
# 
#     attachments = models.ManyToManyField(Attachment,
#             related_name="%(app_label)s_%(class)s_attachments", \
#             blank=True)
#     images = models.ManyToManyField(ImageAttachment,
#             related_name="%(app_label)s_%(class)s_images", \
#             blank=True)
#     links = models.ManyToManyField(Link,
#             related_name="%(app_label)s_%(class)s_links", \
#             blank=True)
# 
#     author = models.ForeignKey(User)
# 
#     categories = models.ManyToManyField(Category, blank=True)
#     tags = models.ManyToManyField(Tag, blank=True)
# 
#     create_date = models.DateTimeField('date created', auto_now_add=True,
#             editable=False)
#     mod_date = models.DateTimeField('date modified', auto_now=True,
#             editable=False)
#     pub_date = models.DateTimeField('date published', null=True, blank=True)
# 
#     def __unicode__(self):
#         return self.title
# 
#     def get_absolute_url(self):
#         return reverse('blog-entry', args=[self.id])
# 
#     def short_url(self):
#         return get_short_url(self.get_absolute_url())
# 
#     class Meta:
#         verbose_name_plural = "Entries"
# 
# class FORMAT(object):
#     HTML = 'H'
#     MARKDOWN = 'MD'
#     RESTRUCTURED_TEXT = 'RST'
# 
#     CHOICES = (
#         (MARKDOWN, 'Markdown'),
#         (RESTRUCTURED_TEXT, 'Restructured Text'),
#         (HTML, 'HTML'),
#     )


# Path: hackday/blog/feeds.py
from markdown import markdown
from docutils.core import publish_parts
from django.contrib.syndication.views import Feed
from django.utils import feedgenerator
from hackday.blog.models import Entry, FORMAT



class LatestEntriesFeed(Feed):
    title = "Hack Day Blog"
    link = "/blog/"
    description = "A list of the Hack Day blog entries"

    feed_type = feedgenerator.Rss201rev2Feed

    def items(self):
        return Entry.objects.order_by('-pub_date')[:20]

    def item_title(self, item):
        return item.title

    def item_description(self, item):
        if item.format == FORMAT.MARKDOWN:
            return markdown(item.content, safe_mode='remove')

        elif item.format == FORMAT.RESTRUCTURED_TEXT: