~homeworkprod/byceps

ref: 342e5296ae417372e544ce931b442e98301c17a1 byceps/byceps/blueprints/admin/shop/shipping/views.py -rw-r--r-- 1.3 KiB
342e5296 — Jochen Kupperschmidt Require body blocks in base templates 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""
byceps.blueprints.admin.shop.shipping.views
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2021 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""

from flask import abort

from .....services.brand import service as brand_service
from .....services.shop.shipping import service as shipping_service
from .....services.shop.shop import service as shop_service
from .....util.framework.blueprint import create_blueprint
from .....util.framework.templating import templated
from .....util.views import permission_required

from ..order.authorization import ShopOrderPermission


blueprint = create_blueprint('shop_shipping_admin', __name__)


@blueprint.route('/for_shop/<shop_id>')
@permission_required(ShopOrderPermission.view)
@templated
def view_for_shop(shop_id):
    """List the articles to ship, or likely to ship, for that shop."""
    shop = _get_shop_or_404(shop_id)

    brand = brand_service.get_brand(shop.brand_id)

    articles_to_ship = shipping_service.get_articles_to_ship(shop.id)

    return {
        'shop': shop,
        'brand': brand,
        'articles_to_ship': articles_to_ship,
    }


def _get_shop_or_404(shop_id):
    shop = shop_service.find_shop(shop_id)

    if shop is None:
        abort(404)

    return shop