# Path: django_fortunes/models.py
# class Fortune(models.Model):
#     author = models.ForeignKey(User)
#     title = models.CharField(max_length=200, blank=False)
#     slug = models.SlugField(_('slug'), db_index=True, max_length=255, unique_for_date='pub_date')
#     content = models.TextField(blank=False)
#     pub_date = models.DateTimeField(_('published date'), db_index=True, default=datetime.now())
#     votes = models.IntegerField(default=0)
#     comments = generic.GenericRelation(
#         Comment,
#         content_type_field='content_type',
#         object_id_field='object_pk'
#     )
# 
#     objects = FortuneManager()
# 
#     def __unicode__(self):
#         return _("%(title)s, from %(author)s") % {
#             'title': self.title,
#             'author': self.author.username ,
#         }
# 
#     def check_slug(self):
#         """
#         If no slug has been generated yet for the current Fortune, tries to generate a
#         unique one
#         """
#         if not self.slug:
#             prefix = ""
#             i = 0
#             while True:
#                 self.slug = prefix + slugify(self.title)
#                 try:
#                     self._default_manager.values('id').get(slug=self.slug)
#                     i += 1
#                     prefix = str(i) + "-"
#                 except Fortune.DoesNotExist:
#                     break
#         return self.slug
# 
#     @models.permalink
#     def get_absolute_url(self):
#         "Retrieves the absolute django url of a fortune"
#         return ('fortune_detail', (), {
#             'slug': self.slug,
#             'year': self.pub_date.year,
#             'month': self.pub_date.month,
#             'day': self.pub_date.day
#         })
# 
#     def save(self):
#         "Saves a fortune after havng checked and generated its slug"
#         self.check_slug()
#         super(Fortune, self).save()
# 
# Path: django_fortunes/templatetags/fortune_extras.py
# @register.filter
# @stringfilter
# def fortunize(value):
#     """
#     Transforms a fortune plain text into htmlized (but safe) one.
#     """
#     r = ""
#     for i, line in enumerate(value.splitlines()):
#         m = re.findall(r"^<(\w+)>\s?(.*)$", line.strip())
#         className = "odd" if i % 2 == 0 else "even"
#         if (len(m) > 0):
#             for match in m:
#                 nick = match[0]
#                 quote = escape(match[1])
#                 r += "<dt class=\"%s\">&lt;%s&gt;</dt><dd><q>%s</q></dd>\n" % (className, nick, quote)
#         else:
#             r += "<dt>&nbsp;</dt><dd>%s</dd>\n" % (escape(line))
#     return "<dl>%s</dl>" % r


from django.contrib.syndication.views import Feed
from django.contrib.sites.models import Site
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from django.shortcuts import get_object_or_404
from django.conf import settings
from django.core.urlresolvers import reverse
from django_fortunes.models import Fortune
from django_fortunes.templatetags.fortune_extras import fortunize


class FortuneFeed(Feed):
    author_name = 'The django_fortunes application'
    _site = Site.objects.get_current()

# Path: django_fortunes/models.py
# class Fortune(models.Model):
#     author = models.ForeignKey(User)
#     title = models.CharField(max_length=200, blank=False)
#     slug = models.SlugField(_('slug'), db_index=True, max_length=255, unique_for_date='pub_date')
#     content = models.TextField(blank=False)
#     pub_date = models.DateTimeField(_('published date'), db_index=True, default=datetime.now())
#     votes = models.IntegerField(default=0)
#     comments = generic.GenericRelation(
#         Comment,
#         content_type_field='content_type',
#         object_id_field='object_pk'
#     )
# 
#     objects = FortuneManager()
# 
#     def __unicode__(self):
#         return _("%(title)s, from %(author)s") % {
#             'title': self.title,
#             'author': self.author.username ,
#         }
# 
#     def check_slug(self):
#         """
#         If no slug has been generated yet for the current Fortune, tries to generate a
#         unique one
#         """
#         if not self.slug:
#             prefix = ""
#             i = 0
#             while True:
#                 self.slug = prefix + slugify(self.title)
#                 try:
#                     self._default_manager.values('id').get(slug=self.slug)
#                     i += 1
#                     prefix = str(i) + "-"
#                 except Fortune.DoesNotExist:
#                     break
#         return self.slug
# 
#     @models.permalink
#     def get_absolute_url(self):
#         "Retrieves the absolute django url of a fortune"
#         return ('fortune_detail', (), {
#             'slug': self.slug,
#             'year': self.pub_date.year,
#             'month': self.pub_date.month,
#             'day': self.pub_date.day
#         })
# 
#     def save(self):
#         "Saves a fortune after havng checked and generated its slug"
#         self.check_slug()
#         super(Fortune, self).save()
# 
# Path: django_fortunes/templatetags/fortune_extras.py
# @register.filter
# @stringfilter
# def fortunize(value):
#     """
#     Transforms a fortune plain text into htmlized (but safe) one.
#     """
#     r = ""
#     for i, line in enumerate(value.splitlines()):
#         m = re.findall(r"^<(\w+)>\s?(.*)$", line.strip())
#         className = "odd" if i % 2 == 0 else "even"
#         if (len(m) > 0):
#             for match in m:
#                 nick = match[0]
#                 quote = escape(match[1])
#                 r += "<dt class=\"%s\">&lt;%s&gt;</dt><dd><q>%s</q></dd>\n" % (className, nick, quote)
#         else:
#             r += "<dt>&nbsp;</dt><dd>%s</dd>\n" % (escape(line))
#     return "<dl>%s</dl>" % r


# Path: django_fortunes/feeds.py
from django.contrib.syndication.views import Feed
from django.contrib.sites.models import Site
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from django.shortcuts import get_object_or_404
from django.conf import settings
from django.core.urlresolvers import reverse
from django_fortunes.models import Fortune
from django_fortunes.templatetags.fortune_extras import fortunize



class FortuneFeed(Feed):
    author_name = 'The django_fortunes application'
    _site = Site.objects.get_current()

    manager = Fortune.objects