# Path: djwechat/rss/models.py
# class Article(models.Model):
#     channel = models.ForeignKey(to=FeedChannel,
#                                 verbose_name=_('Feed Channel'))
#     title = models.CharField(verbose_name=_('Title'),
#                              max_length=255)
#     link = models.URLField(verbose_name=_('Link'))
#     authors = models.ManyToManyField(Author,
#                                      verbose_name=_('Authors'))
#     categories = models.ManyToManyField(Category,
#                                         verbose_name=_('Categories'))
#     content = models.TextField(verbose_name=_('Content'))
#     publishedAt = models.DateTimeField(verbose_name=_('Published Time'))
#     updatedAt = models.DateTimeField(verbose_name=_('Updated Time'),
#                                      auto_now=True)
#     show = models.BooleanField(verbose_name=_('Show'),
#                                help_text=_('Whether to show this article'),
#                                default=True)
# 
#     def __str__(self):
#         return self.title
# 
#     class Meta:
#         verbose_name = _('Article')
#         verbose_name_plural = _('Articles')
#         unique_together = (('channel', 'title', 'link'),)
#         ordering = ('-updatedAt', '-publishedAt')
# 
# Path: djwechat/rss/models.py
# class Author(models.Model):
#     name = models.CharField(verbose_name=_('Name'),
#                             max_length=25)
#     link = models.URLField(verbose_name=_('Homepage'),
#                            null=True, blank=True)
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name = _('Author')
#         verbose_name_plural = _('Authors')
#         unique_together = (('name', 'link'),)
# 
# Path: djwechat/rss/models.py
# class Category(models.Model):
#     tag = models.CharField(verbose_name=_('Tag'),
#                            max_length=25,
#                            unique=True)
# 
#     def __str__(self):
#         return self.tag
# 
#     class Meta:
#         verbose_name = _('Category')
#         verbose_name_plural = _('Categories')
# 
# Path: djwechat/rss/models.py
# class FeedChannel(models.Model):
#     title = models.CharField(verbose_name=_('Title'),
#                              max_length=50)
#     link = models.URLField(verbose_name=_('Feed Link'))
#     website = models.URLField(verbose_name=_('Official Website'))
#     subtitle = models.TextField(verbose_name=_('Subtitle'),
#                                 null=True, blank=True)
#     description = models.TextField(verbose_name=_('Description'),
#                                    null=True, blank=True)
# 
#     def __str__(self):
#         return self.title
# 
#     class Meta:
#         verbose_name = _('Feed Channel')
#         verbose_name_plural = _('Feed Channels')
#         unique_together = (('title', 'link'),)
#         ordering = ('title',)
# 
# Path: djwechat/rss/parser.py
# def get_feed_channel(url):
#     channel = get_feed(url)
#     feed_channel, _ = FeedChannel.objects.get_or_create(
#         title=channel['title'],
#         link=channel['link'],
#         website=channel['website'],
#         subtitle=channel['subtitle'],
#         description=channel['description'])
#     return feed_channel
# 
# Path: djwechat/rss/parser.py
# def update_articles(url):
#     add_num = 0
#     articles = get_articles(url)
#     feed_channel = get_feed_channel(url)
#     for article in articles:
#         try:
#             authors = []
#             for author in article['authors']:
#                 a, _ = Author.objects.get_or_create(
#                     name=author.get('name', ''))
#                 authors.append(a)
# 
#             categories = []
#             for category in article['categories']:
#                 c, _ = Category.objects.get_or_create(
#                     tag=category)
#                 categories.append(c)
# 
#             saved_article = Article(
#                 channel=feed_channel,
#                 title=article['title'],
#                 link=article['link'],
#                 content=article['content'],
#                 publishedAt=article['published']
#             )
#             saved_article.save()
#             saved_article.authors = authors
#             saved_article.categories = categories
#         except IntegrityError:
#             pass
#         else:
#             add_num += 1
#     return add_num


from django.core.paginator import EmptyPage
from django.core.paginator import PageNotAnInteger
from django.core.paginator import Paginator
from django.http import JsonResponse
from django.shortcuts import get_list_or_404
from django.shortcuts import get_object_or_404
from django.shortcuts import render
from django.utils.translation import ugettext_lazy as _
from .models import Article
from .models import Author
from .models import Category
from .models import FeedChannel
from .parser import get_feed_channel
from .parser import update_articles
# -*- coding: utf-8 -*-



# Create your views here.


class Page:

    def __init__(self, **kw):
        self.title = kw.get('title')
        self.description = kw.get('description', '')
        self.keywords = kw.get('keywords', '')


def home(request):

# Path: djwechat/rss/models.py
# class Article(models.Model):
#     channel = models.ForeignKey(to=FeedChannel,
#                                 verbose_name=_('Feed Channel'))
#     title = models.CharField(verbose_name=_('Title'),
#                              max_length=255)
#     link = models.URLField(verbose_name=_('Link'))
#     authors = models.ManyToManyField(Author,
#                                      verbose_name=_('Authors'))
#     categories = models.ManyToManyField(Category,
#                                         verbose_name=_('Categories'))
#     content = models.TextField(verbose_name=_('Content'))
#     publishedAt = models.DateTimeField(verbose_name=_('Published Time'))
#     updatedAt = models.DateTimeField(verbose_name=_('Updated Time'),
#                                      auto_now=True)
#     show = models.BooleanField(verbose_name=_('Show'),
#                                help_text=_('Whether to show this article'),
#                                default=True)
# 
#     def __str__(self):
#         return self.title
# 
#     class Meta:
#         verbose_name = _('Article')
#         verbose_name_plural = _('Articles')
#         unique_together = (('channel', 'title', 'link'),)
#         ordering = ('-updatedAt', '-publishedAt')
# 
# Path: djwechat/rss/models.py
# class Author(models.Model):
#     name = models.CharField(verbose_name=_('Name'),
#                             max_length=25)
#     link = models.URLField(verbose_name=_('Homepage'),
#                            null=True, blank=True)
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name = _('Author')
#         verbose_name_plural = _('Authors')
#         unique_together = (('name', 'link'),)
# 
# Path: djwechat/rss/models.py
# class Category(models.Model):
#     tag = models.CharField(verbose_name=_('Tag'),
#                            max_length=25,
#                            unique=True)
# 
#     def __str__(self):
#         return self.tag
# 
#     class Meta:
#         verbose_name = _('Category')
#         verbose_name_plural = _('Categories')
# 
# Path: djwechat/rss/models.py
# class FeedChannel(models.Model):
#     title = models.CharField(verbose_name=_('Title'),
#                              max_length=50)
#     link = models.URLField(verbose_name=_('Feed Link'))
#     website = models.URLField(verbose_name=_('Official Website'))
#     subtitle = models.TextField(verbose_name=_('Subtitle'),
#                                 null=True, blank=True)
#     description = models.TextField(verbose_name=_('Description'),
#                                    null=True, blank=True)
# 
#     def __str__(self):
#         return self.title
# 
#     class Meta:
#         verbose_name = _('Feed Channel')
#         verbose_name_plural = _('Feed Channels')
#         unique_together = (('title', 'link'),)
#         ordering = ('title',)
# 
# Path: djwechat/rss/parser.py
# def get_feed_channel(url):
#     channel = get_feed(url)
#     feed_channel, _ = FeedChannel.objects.get_or_create(
#         title=channel['title'],
#         link=channel['link'],
#         website=channel['website'],
#         subtitle=channel['subtitle'],
#         description=channel['description'])
#     return feed_channel
# 
# Path: djwechat/rss/parser.py
# def update_articles(url):
#     add_num = 0
#     articles = get_articles(url)
#     feed_channel = get_feed_channel(url)
#     for article in articles:
#         try:
#             authors = []
#             for author in article['authors']:
#                 a, _ = Author.objects.get_or_create(
#                     name=author.get('name', ''))
#                 authors.append(a)
# 
#             categories = []
#             for category in article['categories']:
#                 c, _ = Category.objects.get_or_create(
#                     tag=category)
#                 categories.append(c)
# 
#             saved_article = Article(
#                 channel=feed_channel,
#                 title=article['title'],
#                 link=article['link'],
#                 content=article['content'],
#                 publishedAt=article['published']
#             )
#             saved_article.save()
#             saved_article.authors = authors
#             saved_article.categories = categories
#         except IntegrityError:
#             pass
#         else:
#             add_num += 1
#     return add_num


# Path: djwechat/rss/views.py
from django.core.paginator import EmptyPage
from django.core.paginator import PageNotAnInteger
from django.core.paginator import Paginator
from django.http import JsonResponse
from django.shortcuts import get_list_or_404
from django.shortcuts import get_object_or_404
from django.shortcuts import render
from django.utils.translation import ugettext_lazy as _
from .models import Article
from .models import Author
from .models import Category
from .models import FeedChannel
from .parser import get_feed_channel
from .parser import update_articles

# -*- coding: utf-8 -*-



# Create your views here.


class Page:

    def __init__(self, **kw):
        self.title = kw.get('title')
        self.description = kw.get('description', '')
        self.keywords = kw.get('keywords', '')


def home(request):

    accessible_articles = get_list_or_404(Article, show=True)