from pyramid.view import view_config
from ..models.comment import get_comments_for_shop
from . import shop_editor_required


@view_config(route_name="shop_comments", renderer="shop_comments.j2")
@shop_editor_required()
def shop_comments(request):
    shop = request.shop
    filter_type = request.params.get("filter", "all")
    if filter_type not in ("all", "pending", "deleted"):
        filter_type = "all"
    comments = get_comments_for_shop(request.dbsession, shop.id, filter_type)
    return {"shop": shop, "comments": comments, "filter_type": filter_type}
