def posts_housekeeping():
    ''' goes through all posts, move 'old' posts to archive status,
        delete reeeeealy old posts. '''

    time_now = now()
    archive_time = time_now - \
                   timedelta(days=config_var('posts.archive_after_days', 7))
    delete_time = time_now - \
                  timedelta(days=config_var('posts.delete_after_days', 30))

    # first delete really old posts:

    delete_count = 0
    archive_count = 0

    if config_var('posts.delete_when_old', True):
        for post in Post.select().where(Post.active_end < delete_time):
            delete_post_and_run_callback(post, post_types.load(post.type))
            delete_count += 1

    # next set old-ish posts to archived:

    if config_var('posts.archive_when_old', True):
        archive_count = Post.update(status=2) \
                            .where((Post.active_end < archive_time) &
                                   (Post.status != 2)) \
                            .execute()

    # And done.

    return jsonify({"deleted": delete_count,
                    "archived": archive_count,
                    "delete_before": delete_time,
                    "archive_before": archive_time,
                    "now": time_now})
Beispiel #2
0
def posts_housekeeping():
    ''' goes through all posts, move 'old' posts to archive status,
        delete reeeeealy old posts. '''

    time_now = now()
    archive_time = time_now - \
                   timedelta(days=config_var('posts.archive_after_days', 7))
    delete_time = time_now - \
                  timedelta(days=config_var('posts.delete_after_days', 30))

    # first delete really old posts:

    delete_count = 0
    archive_count = 0

    if config_var('posts.delete_when_old', True):
        for post in Post.select().where(Post.active_end < delete_time):
            delete_post_and_run_callback(post, post_types.load(post.type))
            delete_count += 1

    # next set old-ish posts to archived:

    if config_var('posts.archive_when_old', True):
        archive_count = Post.update(status=2) \
                            .where((Post.active_end < archive_time) &
                                   (Post.status != 2)) \
                            .execute()

    # And done.

    return jsonify({"deleted": delete_count,
                    "archived": archive_count,
                    "delete_before": delete_time,
                    "archive_before": archive_time,
                    "now": time_now})