示例#1
0
def new_subscribe():
    body = json.get_request_body()
    package_id = body['packageId']
    package_type = body['packageType']
    folder = body['folder']
    if not (package_id and package_type and folder >= 0):
        raise json.InvalidRequest()
    current_user_id = session_user.user.id
    if folder != 0:
        folder_subscribe = Subscribe.query.filter((Subscribe.user_id == current_user_id) &
                                                  (Subscribe.id == folder)).first()
        if not folder_subscribe:
            raise Exception("Subscriber folder is not exists")
    package = find_package(package_type, package_id)
    if not package:
        raise Exception("Package is not exists")
    sub = Subscribe(user_id=session_user.user.id, parent_id=folder, type=Subscribe.TYPE_FEED,
                    name=package.title, order=20, active=True, feed_id=package.id)
    db.session.add(sub)
    db.session.commit()

    from rdr.modules.feeds.articles.unread import TotalUnreadArticlesSet
    total_unread_set = TotalUnreadArticlesSet(session_user.user)
    sub_dict = prepare_subscribe(sub)

    return {
        'success': True,
        'subscribe': sub_dict,
        'totalUnreadCount': total_unread_set.count
    }
示例#2
0
文件: articles.py 项目: Rikanishu/rdr
def search():
    page = 1
    body = json.get_request_body()
    if 'page' in body:
        page = int(body['page'])
    params = {}
    if 'type' in body:
        params['filter_criteria'] = body['type']
    if 'where' in body:
        params['where'] = body['where']
    from rdr.modules.feeds.search import ArticleSearchProvider
    if 'feed' in body:
        provider = ArticleSearchProvider(feeds=[int(body['feed'])], user=session_user.identity)
    else:
        provider = ArticleSearchProvider(user=session_user.identity)
    ids = provider.search(body['query'], **params)
    if ids:
        articles_pagination = Article.query \
            .options(db.joinedload(Article.statuses),
                     db.joinedload(Article.feed)) \
            .filter((Article.active == True) & (Article.id.in_(ids))).order_by(Article.published.desc()) \
            .paginate(page, per_page=60, error_out=False)

        records = UserArticleRecord.wrap_articles_list(articles_pagination.items)
        records = [x.to_dict() for x in records]
    else:
        records = []
    return {
        'success': True,
        'articles': records
    }
示例#3
0
def remove_article():
    body = json.get_request_body()
    article_id = body["articleId"]
    queue = OfflineReadQueue.query.filter(
        (OfflineReadQueue.user_id == session_user.identity.id) & (OfflineReadQueue.article_id == article_id)
    ).first()
    if not queue:
        raise json.NotFound("Queue not found")
    db.session.delete(queue)
    db.session.commit()
    return {"success": True}
示例#4
0
def add_article():
    body = json.get_request_body()
    article_id = body["articleId"]
    queue = OfflineReadQueue.query.filter(
        (OfflineReadQueue.user_id == session_user.identity.id) & (OfflineReadQueue.article_id == article_id)
    ).first()
    if not queue:
        queue = OfflineReadQueue(user_id=session_user.identity.id, article_id=article_id, add_date=datetime.now())
        db.session.add(queue)
        db.session.commit()
    return {"success": True}
示例#5
0
文件: articles.py 项目: Rikanishu/rdr
def article_remove_from_favorites():
    body = json.get_request_body()
    article_id = body['articleId']
    fav = ArticleFavorite.query \
        .filter((ArticleFavorite.user_id == session_user.user.id) & (ArticleFavorite.article_id == article_id)) \
        .first()
    if fav:
        db.session.delete(fav)
        db.session.commit()

    return {
        'success': True
    }
示例#6
0
def create_folder():
    body = json.get_request_body()
    folder_name = body['name']
    if not folder_name:
        raise json.InvalidRequest('Folder name must be non-empty string')
    sub = Subscribe(user_id=session_user.user.id, parent_id=0,
                    name=folder_name, type=Subscribe.TYPE_FOLDER,
                    order=10, active=True)
    db.session.add(sub)
    db.session.commit()
    return {
        'success': True,
        'subscribe': sub.to_dict()
    }
示例#7
0
文件: articles.py 项目: Rikanishu/rdr
def article_add_to_favorites():
    body = json.get_request_body()
    article_id = body['articleId']
    fav = ArticleFavorite.query \
        .filter((ArticleFavorite.user_id == session_user.user.id) & (ArticleFavorite.article_id == article_id)) \
        .first()
    if not fav:
        fav = ArticleFavorite(article_id=article_id, user_id=session_user.user.id, fav_date=datetime.now())
        db.session.add(fav)
        db.session.commit()

    return {
        'success': True
    }
示例#8
0
文件: feeds.py 项目: Rikanishu/rdr
def feed_mark_all_as_read():
    from rdr.modules.feeds.articles.unread import FeedUnreadArticlesSet

    body = json.get_request_body()
    feed_id = body["feedId"]
    feed = Feed.query.filter(Feed.id == feed_id).first()
    if not feed:
        raise NotFound("Feed not found")
    unread_set = FeedUnreadArticlesSet(session_user.user, feed)
    for article in unread_set.articles:
        article_status = ArticleStatus()
        article_status.user_id = session_user.user.id
        article_status.article_id = article.id
        article_status.status = ArticleStatus.STATUS_READ
        article_status.read_date = datetime.now()
        db.session.add(article_status)
    db.session.commit()
    return {"success": True}
示例#9
0
def add_feed_unread():
    from rdr.modules.feeds.articles.unread import FeedUnreadArticlesSet
    from rdr.modules.feeds.models import Feed

    body = json.get_request_body()
    feed_id = body["feedId"]
    feed = Feed.query.filter(Feed.id == feed_id).first()
    if not feed:
        raise json.NotFound("Feed not found")
    unread_set = FeedUnreadArticlesSet(session_user.user, feed)
    for article in unread_set.articles:
        queue = OfflineReadQueue.query.filter(
            (OfflineReadQueue.user_id == session_user.identity.id) & (OfflineReadQueue.article_id == article.id)
        ).first()
        if not queue:
            queue = OfflineReadQueue(user_id=session_user.identity.id, article_id=article.id, add_date=datetime.now())
            db.session.add(queue)
    db.session.commit()
    return {"success": True}
示例#10
0
文件: articles.py 项目: Rikanishu/rdr
def article_mark_as_read():
    body = json.get_request_body()
    article_id = body['articleId']
    existed_status = ArticleStatus.query \
        .filter((ArticleStatus.article_id == article_id) & (ArticleStatus.user_id == session_user.user.id)) \
        .first()
    if existed_status:
        existed_status.status = ArticleStatus.STATUS_READ
    else:
        article_status = ArticleStatus()
        article_status.user_id = session_user.user.id
        article_status.article_id = article_id
        article_status.status = ArticleStatus.STATUS_READ
        article_status.read_date = datetime.now()
        db.session.add(article_status)
    db.session.commit()

    return {
        'success': True
    }
示例#11
0
def save():
    body = json.get_request_body()
    root_subscribes = body['rootSubscribes']
    folders = body['folders']

    subscriptions = Subscribe.query.filter(Subscribe.user_id == session_user.identity.id)
    for sub in subscriptions:
        db.session.delete(sub)

    for folder_data in folders:
        folder_name = folder_data['name']
        folder = Subscribe(user_id=session_user.identity.id, parent_id=0,
                        name=folder_name, type=Subscribe.TYPE_FOLDER,
                        order=10, active=True, feed_id=None)
        db.session.add(folder)
        db.session.flush()
        folder_feeds = folder_data['feeds']
        if folder_feeds:
            for sub_data in folder_feeds:
                feed_id = sub_data['feedId']
                feed_name = sub_data['name']
                sub = Subscribe(user_id=session_user.identity.id, parent_id=folder.id,
                                name=feed_name, type=Subscribe.TYPE_FEED,
                                order=20, active=True, feed_id=feed_id)
                db.session.add(sub)

    for sub_data in root_subscribes:
        feed_id = sub_data['feedId']
        feed_name = sub_data['name']
        sub = Subscribe(user_id=session_user.identity.id, parent_id=0,
                        name=feed_name, type=Subscribe.TYPE_FEED,
                        order=20, active=True, feed_id=feed_id)
        db.session.add(sub)

    db.session.commit()

    return {
        'success': True
    }