# Path: blog/main/models.py
# class Post(models.Model):
#     title = models.CharField(max_length=256, default='new blog')
#     abstract = models.TextField(null=True, blank=True)
#     raw = models.TextField()
#     pub_time = models.DateTimeField(auto_now_add=True)
#     update_time = models.DateTimeField(auto_now=True)
#     content_html = models.TextField(null=True, blank=True)
#     author = models.ForeignKey(User)
#     tags = models.ManyToManyField('Tag', blank=True)
#     category = models.ForeignKey('Category', null=True, blank=True)
#     is_draft = models.BooleanField(default=False)
# 
#     def save(self, *args, **kwargs):
#         self.content_html = markdown2.markdown(self.raw, extras=['code-friendly', 'fenced-code-blocks']).encode('utf-8')
#         super(Post, self).save(*args, **kwargs)
# 
#     def __str__(self):
#         return self.title
# 
#     def get_absolute_url(self):
#         return reverse('main:post', kwargs={ 'pk': self.id })
# 
# class BlogMeta(models.Model):
#     key = models.CharField(max_length=256)
#     value = models.CharField(max_length=256, null=True, blank=True)
#     flag = models.BooleanField(default=False)
#     misc = models.CharField(max_length=256, null=True, blank=True)
# 
#     def __str__(self):
#         return self.key
# 
# Path: blog/main/views.py
# def get_site_meta():
#     seo = {}
#     try:
#         record = models.BlogMeta.objects.get(key='blog_name')
#         seo['title'] = record.value
#     except models.BlogMeta.DoesNotExist:
#         pass
# 
#     try:
#         record = models.BlogMeta.objects.get(key='blog_desc')
#         seo['desc'] = record.value
#     except models.BlogMeta.DoesNotExist:
#         pass
# 
#     try:
#         record = models.BlogMeta.objects.get(key='owner')
#         seo['author'] = record.value
#     except models.BlogMeta.DoesNotExist:
#         pass
# 
#     try:
#         record = models.BlogMeta.objects.get(key='keywords')
#         seo['keywords'] = record.value
#     except models.BlogMeta.DoesNotExist:
#         pass
# 
#     try:
#         record = models.BlogMeta.objects.get(key='blog_subtitle')
#         seo['subtitle'] = record.value
#     except models.BlogMeta.DoesNotExist:
#         pass
# 
#     try:
#         record = models.BlogMeta.objects.get(key='google_verify')
#         seo['google_verify'] = record.value
#     except models.BlogMeta.DoesNotExist:
#         pass
# 
#     try:
#         record = models.BlogMeta.objects.get(key='baidu_verify')
#         seo['baidu_verify'] = record.value
#     except models.BlogMeta.DoesNotExist:
#         pass
# 
#     return seo


from django.contrib.syndication.views import Feed
from django.core.urlresolvers import reverse
from django.utils.feedgenerator import Atom1Feed
from django.shortcuts import get_object_or_404
from django.conf import settings
from .models import Post, BlogMeta
from .views import get_site_meta
#     def link(self, item):
#         return reverse('main:post', args=[item.pk])
#         # return '/'

#     def items(self):
#         return Post.objects.filter(is_draft=False)

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

#     def item_description(self, item):
#         return item.content_html

#     # item_link is only needed if Post has no get_absolute_url method.
#     def item_link(self, item):
#         return reverse('main:post', args=[item.pk])
#         # return '/'

class LatestEntriesFeed2(Feed):


    def title(self):
        META_DATA = get_site_meta()
        return META_DATA.get('title')

    def link(self, item):
        return reverse('main:rss')
        # return '/rss/'

    def description(self):

# Path: blog/main/models.py
# class Post(models.Model):
#     title = models.CharField(max_length=256, default='new blog')
#     abstract = models.TextField(null=True, blank=True)
#     raw = models.TextField()
#     pub_time = models.DateTimeField(auto_now_add=True)
#     update_time = models.DateTimeField(auto_now=True)
#     content_html = models.TextField(null=True, blank=True)
#     author = models.ForeignKey(User)
#     tags = models.ManyToManyField('Tag', blank=True)
#     category = models.ForeignKey('Category', null=True, blank=True)
#     is_draft = models.BooleanField(default=False)
# 
#     def save(self, *args, **kwargs):
#         self.content_html = markdown2.markdown(self.raw, extras=['code-friendly', 'fenced-code-blocks']).encode('utf-8')
#         super(Post, self).save(*args, **kwargs)
# 
#     def __str__(self):
#         return self.title
# 
#     def get_absolute_url(self):
#         return reverse('main:post', kwargs={ 'pk': self.id })
# 
# class BlogMeta(models.Model):
#     key = models.CharField(max_length=256)
#     value = models.CharField(max_length=256, null=True, blank=True)
#     flag = models.BooleanField(default=False)
#     misc = models.CharField(max_length=256, null=True, blank=True)
# 
#     def __str__(self):
#         return self.key
# 
# Path: blog/main/views.py
# def get_site_meta():
#     seo = {}
#     try:
#         record = models.BlogMeta.objects.get(key='blog_name')
#         seo['title'] = record.value
#     except models.BlogMeta.DoesNotExist:
#         pass
# 
#     try:
#         record = models.BlogMeta.objects.get(key='blog_desc')
#         seo['desc'] = record.value
#     except models.BlogMeta.DoesNotExist:
#         pass
# 
#     try:
#         record = models.BlogMeta.objects.get(key='owner')
#         seo['author'] = record.value
#     except models.BlogMeta.DoesNotExist:
#         pass
# 
#     try:
#         record = models.BlogMeta.objects.get(key='keywords')
#         seo['keywords'] = record.value
#     except models.BlogMeta.DoesNotExist:
#         pass
# 
#     try:
#         record = models.BlogMeta.objects.get(key='blog_subtitle')
#         seo['subtitle'] = record.value
#     except models.BlogMeta.DoesNotExist:
#         pass
# 
#     try:
#         record = models.BlogMeta.objects.get(key='google_verify')
#         seo['google_verify'] = record.value
#     except models.BlogMeta.DoesNotExist:
#         pass
# 
#     try:
#         record = models.BlogMeta.objects.get(key='baidu_verify')
#         seo['baidu_verify'] = record.value
#     except models.BlogMeta.DoesNotExist:
#         pass
# 
#     return seo


# Path: blog/main/feeds.py
from django.contrib.syndication.views import Feed
from django.core.urlresolvers import reverse
from django.utils.feedgenerator import Atom1Feed
from django.shortcuts import get_object_or_404
from django.conf import settings
from .models import Post, BlogMeta
from .views import get_site_meta

#     def link(self, item):
#         return reverse('main:post', args=[item.pk])
#         # return '/'

#     def items(self):
#         return Post.objects.filter(is_draft=False)

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

#     def item_description(self, item):
#         return item.content_html

#     # item_link is only needed if Post has no get_absolute_url method.
#     def item_link(self, item):
#         return reverse('main:post', args=[item.pk])
#         # return '/'

class LatestEntriesFeed2(Feed):


    def title(self):
        META_DATA = get_site_meta()
        return META_DATA.get('title')

    def link(self, item):
        return reverse('main:rss')
        # return '/rss/'

    def description(self):

        META_DATA = get_site_meta()