Пример #1
0
 def get_article_list(self, **kwargs):
     if self.is_un_classified:
         unclassified_name = current_app.config.get('UNCLASSIFIED', "not classified")
         category = Category.query.filter_by(name=unclassified_name).first()
     else:
         category_name = kwargs.get('category', None)
         if category_name is None:
             raise ValueError(DATA_FORMAT_ERROR)
         category_name = urllib.unquote_plus(category_name)
         category = Category.query.filter_by(name=category_name).first()
     page = kwargs.get('page', 1)
     if page < 1:
         raise ValueError(PAGE_SMALL_THAN_ONE)
     per_page_num = current_app.config.get('ARTICLE_NUM_PER_PAGE', 10)
     if category is not None:
         # TODO: need rewrite for improve efficiency
         ss = Site.query.filter_by(is_subscribe=True).all()
         ssids = [item.id for item in ss]
         ids = [item.id for item in category.sites]
         ids = set(ssids).intersection(set(ids))
         ids = list(ids)
         article_list = Article.query.filter(Article.site_id.in_(ids)).order_by(
                 desc(Article.updated)).paginate(page=page, per_page=per_page_num, error_out=False).items
     else:
         article_list = []
     result = []
     for article in article_list:
         result.append(fill_list_article_object(article.id, article.title,
             article.site.title, article.updated, article.first_image_url,
             article.is_fav))
     return result
Пример #2
0
 def get_article_list(self, **kwargs):
     article_list = []
     per_page_num = current_app.config.get('ARTICLE_NUM_PER_PAGE', 10)
     page = kwargs.get('page', 1)
     if page >= 1:
         article_list = Article.query.filter(Article.site_id.in_(
             Site.query.with_entities(Site.id).filter(Site.is_read_daily==True))).filter(
                     Article.id!=None).order_by(desc(Article.updated)).paginate(
                             page=page, per_page=per_page_num, error_out=False).items
     else:
         raise ValueError(PAGE_SMALL_THAN_ONE)
     result = []
     for article in article_list:
         result.append(fill_list_article_object(article.id, article.title, article.site.title,
             article.updated, article.first_image_url, article.is_fav))
     return result
Пример #3
0
 def get_article_list(self, **kwargs):
     article_list = []
     site_id = kwargs.get('site_id', 1)
     if 'page' in kwargs:
         per_page_num = current_app.config.get('ARTICLE_NUM_PER_PAGE', 10)
         page = kwargs.get('page', 1)
         if page < 1:
             raise ValueError(PAGE_SMALL_THAN_ONE)
         article_list = Article.query.filter_by(site_id=site_id).order_by(desc(
             Article.updated)).paginate(page=page, per_page=per_page_num,
                     error_out=False).items
     else:
         article_list = Article.query.filter_by(site_id=site_id).order_by(desc(
             Article.updated)).all()
     result = []
     for article in article_list:
         result.append(fill_list_article_object(article.id, article.title,
             article.site.title, article.updated, article.first_image_url,
             article.is_fav))
     return result