<commit_before>"""
byceps.blueprints.board.views_category
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2019 <NAME>
:License: Modified BSD, see LICENSE for details.
"""

from flask import abort, g, url_for

from ...services.board import \
    category_query_service as board_category_query_service, \
    last_view_service as board_last_view_service, \
    topic_query_service as board_topic_query_service
from ...util.framework.templating import templated
from ...util.views import respond_no_content_with_location

from .blueprint import blueprint
from . import _helpers as h, service


@blueprint.route('/')
@templated
def category_index():
    """List categories."""
    board_id = h.get_board_id()
    user = g.current_user

    h.require_board_access(board_id, user.id)

    categories = board_category_query_service \
        .get_categories_with_last_updates(board_id)

    categories_with_flag = service.add_unseen_postings_flag_to_categories(
        categories, user)

    return {
        'categories': categories_with_flag,
    }


@blueprint.route('/categories/<slug>', defaults={'page': 1})
@blueprint.route('/categories/<slug>/pages/<int:page>')
@templated
def category_view(slug, page):
    """List latest topics in the category."""
    board_id = h.get_board_id()
    user = g.current_user

    h.require_board_access(board_id, user.id)

    category = board_category_query_service \
        .find_category_by_slug(board_id, slug)

    if category is None:
        abort(404)

    if category.hidden:
        abort(404)

    if not user.is_anonymous:
        board_last_view_service.mark_category_as_just_viewed(category.id,
                                                             user.id)

    topics_per_page = service.get_topics_per_page_value()

    topics = board_topic_query_service \
        .paginate_topics_of_category(category.id, user, page, topics_per_page)

    service.add_topic_creators(topics.items)
    service.add_topic_unseen_flag(topics.items, user)

    return {
        'category': category,
        'topics': topics,
    }


@blueprint.route('/categories/<category_id>/mark_all_topics_as_read', methods=['POST'])
@respond_no_content_with_location
def mark_all_topics_in_category_as_viewed(category_id):
    category = h.get_category_or_404(category_id)

    board_last_view_service.mark_all_topics_in_category_as_viewed(
        category_id, g.current_user.id)

    return url_for('.category_view', slug=category.slug)<commit_msg>Flash message after marking all topics in a category as viewed<commit_after>"""
byceps.blueprints.board.views_category
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2019 <NAME>
:License: Modified BSD, see LICENSE for details.
"""

from flask import abort, g, url_for

from ...services.board import \
    category_query_service as board_category_query_service, \
    last_view_service as board_last_view_service, \
    topic_query_service as board_topic_query_service
from ...util.framework.flash import flash_success
from ...util.framework.templating import templated
from ...util.views import respond_no_content_with_location

from .blueprint import blueprint
from . import _helpers as h, service


@blueprint.route('/')
@templated
def category_index():
    """List categories."""
    board_id = h.get_board_id()
    user = g.current_user

    h.require_board_access(board_id, user.id)

    categories = board_category_query_service \
        .get_categories_with_last_updates(board_id)

    categories_with_flag = service.add_unseen_postings_flag_to_categories(
        categories, user)

    return {
        'categories': categories_with_flag,
    }


@blueprint.route('/categories/<slug>', defaults={'page': 1})
@blueprint.route('/categories/<slug>/pages/<int:page>')
@templated
def category_view(slug, page):
    """List latest topics in the category."""
    board_id = h.get_board_id()
    user = g.current_user

    h.require_board_access(board_id, user.id)

    category = board_category_query_service \
        .find_category_by_slug(board_id, slug)

    if category is None:
        abort(404)

    if category.hidden:
        abort(404)

    if not user.is_anonymous:
        board_last_view_service.mark_category_as_just_viewed(category.id,
                                                             user.id)

    topics_per_page = service.get_topics_per_page_value()

    topics = board_topic_query_service \
        .paginate_topics_of_category(category.id, user, page, topics_per_page)

    service.add_topic_creators(topics.items)
    service.add_topic_unseen_flag(topics.items, user)

    return {
        'category': category,
        'topics': topics,
    }


@blueprint.route('/categories/<category_id>/mark_all_topics_as_read', methods=['POST'])
@respond_no_content_with_location
def mark_all_topics_in_category_as_viewed(category_id):
    category = h.get_category_or_404(category_id)

    board_last_view_service.mark_all_topics_in_category_as_viewed(
        category_id, g.current_user.id)

    flash_success(
        'Alle Themen in dieser Kategorie wurden als gelesen markiert.')

    return url_for('.category_view', slug=category.slug)
{'fraction_non_alphanumeric': 0.10803484995159729, 'fraction_numerical': 0.0069699903194578895, 'mean_word_length': 3.810055865921788, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4542315', 'n_tokens_mistral': 1675, 'n_tokens_neox': 1621, 'n_words': 295}