<commit_before>"""
byceps.services.board.category_service
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

from typing import Optional, Sequence

from ...database import db

from . import board_service
from .models.category import Category
from .transfer.models import BoardID, CategoryID


def create_category(board_id: BoardID, slug: str, title: str, description: str
                   ) -> Category:
    """Create a category in that board."""
    board = board_service.find_board(board_id)
    if board is None:
        raise ValueError('Unknown board ID "{}"'.format(board_id))

    category = Category(board.id, slug, title, description)
    board.categories.append(category)<commit_msg>Explicitly obtain board as database object to append created board category<commit_after>"""
byceps.services.board.category_service
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

from typing import Optional, Sequence

from ...database import db

from .models.board import Board as DbBoard
from .models.category import Category
from .transfer.models import BoardID, CategoryID


def create_category(board_id: BoardID, slug: str, title: str, description: str
                   ) -> Category:
    """Create a category in that board."""
    board = DbBoard.query.get(board_id)
    if board is None:
        raise ValueError('Unknown board ID "{}"'.format(board_id))

    category = Category(board.id, slug, title, description)
    board.categories.append(category)
{'fraction_non_alphanumeric': 0.14463840399002495, 'fraction_numerical': 0.00997506234413965, 'mean_word_length': 4.228013029315961, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '964101', 'n_tokens_mistral': 454, 'n_tokens_neox': 418, 'n_words': 144}