
from ...util.framework import create_blueprint
from ...util.templating import templated

from ..authorization.registry import permission_registry

from .authorization import BoardPostingPermission, BoardTopicPermission
from .models import Category, Topic


blueprint = create_blueprint('board', __name__)


permission_registry.register_enum('board_topic', BoardTopicPermission)
permission_registry.register_enum('board_posting', BoardPostingPermission)


@blueprint.route('/categories')
@templated
def category_index():
    """List categories."""
    categories = Category.query.for_current_brand().all()
    return {'categories': categories}


@blueprint.route('/categories/<id>')
@templated
def category_view(id):
    """List latest topics in the category."""
    category = Category.query.get(id)
    return {'category': category}


@blueprint.route('/topics/<id>')
@templated
def topic_view(id):
    """List postings for the topic."""
    topic = Topic.query.get(id)
    return {'topic': topic}


from ...util.framework import create_blueprint
from ...util.templating import templated

from ..authorization.registry import permission_registry

from .authorization import BoardPostingPermission, BoardTopicPermission
from .models import Category, Topic


blueprint = create_blueprint('board', __name__)


permission_registry.register_enum('board_topic', BoardTopicPermission)
permission_registry.register_enum('board_posting', BoardPostingPermission)


@blueprint.route('/categories')
@templated
def category_index():
    """List categories."""
    categories = Category.query.for_current_brand().all()
    return {'categories': categories}


@blueprint.route('/categories/<id>')
@templated
def category_view(id):
    """List latest topics in the category."""
    category = Category.query.get_or_404(id)
    return {'category': category}


@blueprint.route('/topics/<id>')
@templated
def topic_view(id):
    """List postings for the topic."""
    topic = Topic.query.get_or_404(id)
    return {'topic': topic}

Throw 404 if category/topic with given id is not found.
Throw 404 if category/topic with given id is not found.

  
  from ...util.framework import create_blueprint
  from ...util.templating import templated
  
  from ..authorization.registry import permission_registry
  
  from .authorization import BoardPostingPermission, BoardTopicPermission
  from .models import Category, Topic
  
  
  blueprint = create_blueprint('board', __name__)
  
  
  permission_registry.register_enum('board_topic', BoardTopicPermission)
  permission_registry.register_enum('board_posting', BoardPostingPermission)
  
  
  @blueprint.route('/categories')
  @templated
  def category_index():
      """List categories."""
      categories = Category.query.for_current_brand().all()
      return {'categories': categories}
  
  
  @blueprint.route('/categories/<id>')
  @templated
  def category_view(id):
      """List latest topics in the category."""
-     category = Category.query.get(id)
+     category = Category.query.get_or_404(id)
      return {'category': category}
  
  
  @blueprint.route('/topics/<id>')
  @templated
  def topic_view(id):
      """List postings for the topic."""
-     topic = Topic.query.get(id)
+     topic = Topic.query.get_or_404(id)
      return {'topic': topic}
  
Throw 404 if category/topic with given id is not found.
## Code Before:

from ...util.framework import create_blueprint
from ...util.templating import templated

from ..authorization.registry import permission_registry

from .authorization import BoardPostingPermission, BoardTopicPermission
from .models import Category, Topic


blueprint = create_blueprint('board', __name__)


permission_registry.register_enum('board_topic', BoardTopicPermission)
permission_registry.register_enum('board_posting', BoardPostingPermission)


@blueprint.route('/categories')
@templated
def category_index():
    """List categories."""
    categories = Category.query.for_current_brand().all()
    return {'categories': categories}


@blueprint.route('/categories/<id>')
@templated
def category_view(id):
    """List latest topics in the category."""
    category = Category.query.get(id)
    return {'category': category}


@blueprint.route('/topics/<id>')
@templated
def topic_view(id):
    """List postings for the topic."""
    topic = Topic.query.get(id)
    return {'topic': topic}

## Instruction:
Throw 404 if category/topic with given id is not found.
## Code After:

from ...util.framework import create_blueprint
from ...util.templating import templated

from ..authorization.registry import permission_registry

from .authorization import BoardPostingPermission, BoardTopicPermission
from .models import Category, Topic


blueprint = create_blueprint('board', __name__)


permission_registry.register_enum('board_topic', BoardTopicPermission)
permission_registry.register_enum('board_posting', BoardPostingPermission)


@blueprint.route('/categories')
@templated
def category_index():
    """List categories."""
    categories = Category.query.for_current_brand().all()
    return {'categories': categories}


@blueprint.route('/categories/<id>')
@templated
def category_view(id):
    """List latest topics in the category."""
    category = Category.query.get_or_404(id)
    return {'category': category}


@blueprint.route('/topics/<id>')
@templated
def topic_view(id):
    """List postings for the topic."""
    topic = Topic.query.get_or_404(id)
    return {'topic': topic}
